home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
smapp100.zip
/
sm10.zip
/
smgfuncr.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-05-14
|
13KB
|
415 lines
/* ------------------------------------------------------------------------
*
* File: smgfuncr.c
* Project: Source Mapper.
* Created: April 4, 1993.
* Description: Source code to include index of functins in map.
*
* 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 struct
{
long fnr; /* Number of functions in project */
funcTYPE *buff; /* Points to buffer of functions info */
}
funcs;
int FuncRIncludeToMap ( FILE *mapf )
/*
Function: Include index of functions to map file.
Date: April, 26. 1993. 11:42. By LEL.
Interface: mapf = Map file to include index of functions.
Returns: E/O.
*/
{
int ok;
if (!prjstat.prjon) /* If no active project */
{
return (ERROR);
}
if (prjstat.filc == 1) /* If only one source in project */
{
/* Make index of one source */
ok = FuncRIncludeToMap1 (mapf);
}
else /* If several sources in project */
{
/* Make index of several sources */
ok = FuncRIncludeToMap2 (mapf);
}
return (ok);
} /* FuncRIncludeToMap (); */
int FuncRBuffConstruct ( void )
/*
Function: Construct buffer of functions in project.
Date: April, 26. 1993. 12:00. By LEL.
Interface:
Returns: E/O.
*/
{
FILE *objf;
finfTYPE finf;
fposTYPE fpos;
funcTYPE *func;
prjfeTYPE fdata;
if (prjstat.filc == 1) /* If only one source in project */
{
/* Get name of normal objectfile */
if (!GetFDataFromPrj (1, &fdata))
RETURN_ERR;
/* Use normal objfile if only 1 source */
if ((objf = FOpen (fdata.objn, "r+b")) == NULL)
{
/* Failed on open file! */
RETERR (16, fdata.objn);
}
}
else
{
/* Open main objectfile */
if ((objf = FOpen (tmpn.manobj, "r+b")) == NULL)
{
/* Failed on open temporary file! */
RETERR (11, tmpn.manobj);
}
}
GetFInfTYPE (objf, &finf); /* Get main info about project sources*/
if (!GetFPosTYPE (objf, &fpos)) /* Get file position indexes */
{
FClose (objf); /* Close main objectfile if error */
RETURN_ERR;
}
FSeek (objf, fpos.funreg, SEEK_SET);/* Start of block of function data */
funcs.fnr = finf.func;
if (funcs.fnr <= 0) /* If this module has no functions */
{
FClose (objf);
return (OK); /* Just do nothing, but return OK */
}
/* Get memory to function buffer */
funcs.buff = (funcTYPE *) Alloc (finf.func * sizeof (funcTYPE));
if (funcs.buff == NULL)
{
FClose (objf);
RETERR (14, NULL); /* Out of memory! */
}
for (func = funcs.buff; /* Point to first element in buffer */
finf.func-- > 0; /* Read all functions into buffer */
func += 1) /* Point to next element */
{
/* Read next function */
if (FRead (func, sizeof (funcTYPE), 1, objf) != 1)
{
Free ((char *) funcs.buff); /* Give allocated memory back to heap */
FClose (objf); /* Close main objectfile if error */
return (ERROR);
}
}
FClose (objf); /* Close main objectfile */
return (OK); /* OK construct */
} /* FuncRBuffConstruct (); */
int FuncRBuffDestruct ( void )
/*
Function: Destruct buffer of functions in project.
Date: April, 26. 1993. 12:00. By LEL.
Interface:
Returns: E/O.
*/
{
Free ((char *) funcs.buff); /* Give allocated memory back to heap */
funcs.fnr = 0L;
funcs.buff = NULL;
return (OK); /* OK destruct */
} /* FuncRBuffDestruct (); */
int FuncRBuffIndxGet ( long indx, funcTYPE *func )
/*
Function: Get function info from buffer, with respect to specified index.
Date: April, 26. 1993. 12:20. LEL.
Interface: indx = Index of which function to get info about (0..).
func = Buffer of where to store the information.
Returns: 1 if index is within legal area, else 0.
*/
{
if (indx >= funcs.fnr)
return (0); /* Index is outside legal area */
memcpy (func,
ADRESS (funcs.buff, indx, sizeof (funcTYPE)),
sizeof (funcTYPE));
return (1); /* Index is within legal area */
} /* FuncRBuffIndxGet (); */
int FuncRBuffLNrGet ( long lnr, funcTYPE *func )
/*
Function: Get function info from buffer, in respect to
specified global line number. Which function do this line
belong to?
Date: April, 26. 1993. 12:30. By LEL.
Interface: lnr = Which function do this global line number belong to?
func = Returns info about owner.
Returns: 1 if the actual function was found, else 0.
*/
{
long fnr;
funcTYPE huge *ptr = funcs.buff;
for (fnr = 0; /* See trough all functions */
fnr < funcs.fnr;
fnr++, ptr++)
{
if (lnr >= ptr->blin && /* Line number within this function? */
lnr <= ptr->blin + ptr->lines)
{
/* Yes, so copy info about function */
memcpy (func, ptr, sizeof (funcTYPE));
return (1); /* Found a function with that line nr */
}
}
return (0); /* No function with that line number */
} /* FuncRBuffLNrGet (); */
long FuncRBuffGetFNr ( void )
/*
Function: Get number of functions currently in buffer.
Date: Mai, 12. 1993. 18:12. By LEL.
Interface:
Returns: Number of functions currently in buffer.
Comment:
*/
{
return (funcs.fnr);
} /* FuncRBuffGetFNr (); */
int FuncRBuffIsFunc ( const char *fname )
/*
Function: Test if function is in buffer.
Programmed by: LEL
Date: Mai, 13. 1993. 04:35.
Interface: fname = Name of function to test if is in buffer.
Returns: 1 if the function is in buffer, else 0.
*/
{
long fnr; /* Count number of function in buffer */
funcTYPE huge *ptr = funcs.buff; /* Init pointer to buffer */
for (fnr = 0; /* See trough all functions */
fnr < funcs.fnr;
fnr++, ptr++)
{
if (strcmp (fname, ptr->name) == 0)
return (1); /* Yes, function is in buffer */
}
return (0); /* No, function is not in buffer */
} /* FuncRBuffIsFunc (); */
int FuncRIncludeToMap1 ( FILE *mapf )
/*
Function: Include index of functions in single source project.
Date: April, 26. 1993. 13:45. By LEL.
Interface: mapf = Map file to include index of functions in single
source in project.
Returns: E/O.
*/
{
long fnr; /* Index to current function */
funcTYPE func; /* Info about current function */
if (funcs.fnr == 0) /* Any functions in project? */
return (OK); /* No, do nothing but return OK */
/* =======================================================================*/
/* Index of functions: */
/* */
/* */
WrtStdLinComStart (mapf, stdwidth, linechr2);
FPrintF (mapf, "%s:\n\n", _StrMSGFUNCREGSTR);
if (errno != 0) /* Any error in last file I/O? */
{
return (ERROR);
}
/* Including index of functions */
Display (D_HEIGH, "%s", _StrMSGINCLFUNCREG);
for (fnr = 0;
fnr < funcs.fnr; /* All functions in project */
fnr += 1)
{
FuncRBuffIndxGet (fnr, &func); /* Get info of this function */
if (fnr % 17 == 0) /* Oppdater brukerinfo for hver 17. */
{
Display (D_LOW, "%s: %d%%", _StrMSGINCLFUNCREG,
(fnr * 100) / funcs.fnr);
}
/* F-nn NameOfFunction () L-xxx */
FPrintF (mapf, "%c-%ld\t%s ()\t%c-%ld",
FUNCTIONCHR,
fnr + 1,
func.name,
LOCLINCHR,
func.blin);
if (o_various.gencom && /* Insert SMG-info in comments? */
fnr+1 == funcs.fnr) /* Is this the last function in list? */
{
WrtComEnd (mapf); /* Mark end of comment */
}
FPrintF (mapf, "\n"); /* New line after each function index */
if (errno != 0) /* Any error in last file I/O? */
{
return (ERROR);
}
}
FPrintF (mapf, "\n\n\n");
/* Including index of functions: 100% */
Display (D_LOW, "%s: 100%%", _StrMSGINCLFUNCREG);
return (OK);
} /* FuncRIncludeToMap1 (); */
int FuncRIncludeToMap2 ( FILE *mapf )
/*
Function: Include index of functions in sources in project.
Date: April, 26. 1993. 13:50. By LEL.
Interface: mapf = Map file to include index of functions in sources
in project.
Returns: E/O.
*/
{
long fnr; /* Index to current function */
long slin; /* Starting line number of source */
funcTYPE func; /* Info about current function */
prjfeTYPE fdata; /* Data about current source */
if (funcs.fnr == 0) /* Any functions in project? */
return (OK); /* No, do nothing but return */
/* =======================================================================*/
/* Index of functions: */
/* */
WrtStdLinComStart (mapf, stdwidth, linechr2);
FPrintF (mapf, "%s:\n\n", _StrMSGFUNCREGSTR);
Display (D_HEIGH, "%s", _StrMSGINCLFUNCREG); /* Including index of functions */
for (fnr = 0; fnr < funcs.fnr; fnr++) /* All functions in project */
{
FuncRBuffIndxGet (fnr, &func); /* Get info of this function */
if (fnr % 17 == 0) /* Oppdater brukerinfo for hver 17. */
Display (D_LOW, "%s: %d%%", _StrMSGINCLFUNCREG, (fnr * 100) / funcs.fnr);
/* To which source do the line belong? */
if (!GetFDataOfGLin (func.blin, &slin, &fdata))
{
/* A rare error due to a bug in the program! */
RETERR (5, NULL); /* Line belongs to no source! */
}
/* F-nnn NameOfFunction () G-xxx (L-nn: filename.c) */
FPrintF (mapf, "%c-%ld\t%s ()\t%c-%ld\t(%c-%ld:\t%s)",
FUNCTIONCHR, fnr + 1,
func.name,
GLOBLINCHR, func.blin,
LOCLINCHR,
func.blin - slin + 1,
GetFName (fdata.name));
if (o_various.gencom && /* Insert SMG-info in comments? */
fnr + 1 == funcs.fnr) /* Is this the last function in list? */
{
WrtComEnd (mapf); /* Mark end of comment */
}
FPrintF (mapf, "\n"); /* New line after each function index */
if (errno != 0) /* Any error in last file I/O? */
return (ERROR);
}
FPrintF (mapf, "\n\n\n");
/* Including index of functions: 100% */
Display (D_LOW, "%s: 100%%", _StrMSGINCLFUNCREG);
return (OK);
} /* FuncRIncludeToMap2 (); */