home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
smapp100.zip
/
sm10.zip
/
smgfcal.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-05-14
|
9KB
|
252 lines
/* ------------------------------------------------------------------------
*
* File: smgfcal.c
* Project: Source Mapper.
* Created: October 6, 1992.
* Description: Source code to include list of function calls.
*
* Copyright (C) 2000 Leif-Erik Larsen.
* This file is part of the Source Mapper source package.
* Source Mapper is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, in version 2 as it comes in the
* "COPYING" file of the XWorkplace main distribution.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ------------------------------------------------------------------------ */
#include "smg.h"
static char loclinchr;
static char globlinchr;
int FCalIncludeToMap ( FILE *mapf )
/*
Function: Include list of function calls to map file.
Date: October 6, 1992. By LEL.
Interface: mapf = Map file to include list of function calls.
Returns: E/O.
*/
{
int ret;
FILE *objf; /* Main object file */
fposTYPE fpos; /* Indexes to blocks of data in file */
prjfeTYPE fdata; /* Data about source in project */
if (!prjstat.prjon) /* If no active project */
return (ERROR);
/* Including list of function calls */
Display (D_HEIGH, "%s", _StrMSGINCLFUNCALLST);
/* =======================================================================*/
/* List of function calls: */
WrtStdLinComStart (mapf, stdwidth, linechr2);
FPrintF (mapf, "%s:\n\n", o_funcall.sel ? _StrMSGSELFUNCALLSTSTR : _StrMSGFUNCALLSTSTR);
loclinchr = LOCLINCHR; /* Shortening for local line ==> 'L' */
globlinchr = GLOBLINCHR; /* Shortening for global line ==> 'G' */
if (prjstat.filc == 1) /* If only one source in project */
globlinchr = LOCLINCHR; /* then all lines are local lines */
if (prjstat.filc == 1) /* If only one source in project */
{
if (!GetFDataFromPrj (1, &fdata))/* Get name of normal objectfile */
RETURN_ERR;
objf = FOpen (fdata.objn, "r+b");/* Use normal objfile if only 1 source */
}
else
{
objf = FOpen (tmpn.manobj, "r+b"); /* Open main objectfile */
}
if (objf == NULL) /* Any error when open file? */
return (ERROR);
if (!GetFPosTYPE (objf, &fpos)) /* Get indexes to blocks of data */
{
FClose (objf); /* Close objectfile if error */
RETURN_ERR;
}
if (fpos.funcal == fpos.idlst) /* Any function calls in project? */
{
FClose (objf); /* No, so close objectfile */
return (OK); /* And return without include list */
}
ret = FCalIncludeToMap1 (mapf, objf, &fpos);
FClose (objf); /* Close main objectfile */
return (ret); /* OK generate of function call list */
} /* FCalIncludeToMap (); */
int FCalNameInSelList ( const char *funcn )
/*
Function: Test if specified function name is in list of selective
function calls.
Date: December, 17. 1992. By LEL.
Interface: funcn = Name to test if in selective list.
Returns: YES if name is in list, else return NO.
Comment: Allways return YES if user has optioned not to make a
selective list.
*/
{
int fcnr = 1; /* Count function call number */
char fcname [MAXFUNCN + 1]; /* Buffer to store name of function */
/* Look trough whole selective list to see if name is in selective list */
while (StrPart (fcnr++, MAXFUNCN, fcname, o_funcall.list, "(), \t\n"))
{
if (strcmp (funcn, fcname) == 0)
return (YES);
}
return (NO); /* Name is not in selective list */
} /* FCalNameInSelList (); */
int FCalIncludeToMap1 ( FILE *mapf, FILE *objf, fposTYPE *fpos )
/*
Function: Include list of function calls in single source in project.
Date: April 26, 1993. 17:55. By LEL.
Interface: mapf = Map file to include list of function calls in single
source in project.
objf = Main objectfile.
fpos = Indexes to blocks of data in main objectfile.
Returns: E/O.
*/
{
long fcnr = 0; /* Count different function calls */
long curpos; /* Current file position in objectfile*/
long linenr; /* Line number where a call is done */
char fcname [MAXFUNCN + 1]; /* Name of current function call */
FSeek (objf, fpos->funcal,SEEK_SET);/* Start of function call data */
curpos = FTell (objf); /* Init file position controll */
while (curpos < fpos->idlst) /* Loop trough all function calls */
{
/* Read name of function call */
if (!FGetS0 (fcname, MAXFUNCN + 1, objf))
return (ERROR);
if (o_funcall.sel == O_YES) /* If selective list */
{
if (FCalNameInSelList (fcname) == NO)
{
do /* Do a dummy seek over line numbers */
{
/* Read next line number reference */
if (FRead (&linenr, sizeof (long), 1, objf) != 1)
return (ERROR);
}
while (linenr != 0L); /* 0L if end of line number list */
curpos = FTell (objf); /* Get filpos to test if end of block */
continue; /* Continue without include func.call */
}
}
/* Including list of function calls */
Display (D_LOW, "%s: (%s)", _StrMSGINCLFUNCALLST, fcname);
FPrintF (mapf, "%s ():\n", fcname);
/* Include the references of the call */
if (!FCalIncludeToMap1_ (mapf, objf))
RETURN_ERR;
fcnr += 1; /* Count number of function calls */
curpos = FTell (objf); /* Get filpos to test if end of block */
}
WritFLineLn (mapf, stdwidth, linechr1);
FPrintF (mapf, "%s: %ld\n", _StrMSGTOTFUNCCALS, fcnr);
WrtStdLinComEnd (mapf, stdwidth, linechr2);
FPrintF (mapf, "\n\n\n");
if (errno != 0) /* Any error in last file I/O? */
return (ERROR);
return (OK);
} /* FCalIncludeToMap1 (); */
int FCalIncludeToMap1_ ( FILE *mapf, FILE *objf )
/*
Function: Include function names of callers, and do neccesarry
indents.
Date: April 26, 1993. 18:45. By LEL.
Interface: mapf = Map file to include list of function calls.
objf = Main objectfile of project.
Returns: E/O.
*/
{
int first = 1; /* 0 when loop passed second and more */
long linenr; /* Line number where a call is done */
char oldf [MAXFUNCN + 1]; /* Name of previous func. who called */
funcTYPE func; /* Data of current function who calls */
oldf[0] = '\0'; /* Reset previous name of function */
do /* Loop trough all line numbers */
{
/* Read next line number reference */
if (FRead (&linenr, sizeof (long), 1, objf) != 1)
return (ERROR);
if (linenr == 0) /* 0L if end of line number list */
break; /* So break loop */
/* Find function who own this line */
if (FuncRBuffLNrGet (linenr, &func) == 0)
continue; /* Warning: No function use this line */
/* Is it a new function who calls? */
if (strcmp (oldf, func.name) == 0)
continue; /* Don't include same name twice */
/*---------------------------------------------------------------------*/
/* NameOfCaller () ... L-nnn */
/* Name of function who calls */
FPrintF (mapf, "\t%s ()\t%c-%ld\n", func.name, globlinchr, func.blin);
if (errno != 0) /* Any error in last file I/O? */
return (ERROR);
strcpy (oldf, func.name); /* Remember name of previous function */
first = 0; /* Now, first loop has been passed */
}
while (1); /* Only break loop from inside */
/* Empty line(s) between each block */
FPrintF (mapf, "\n%s", first ? "\n" : "");
return (OK); /* OK include of references */
} /* FCalIncludeToMap1_ (); */