home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
smapp100.zip
/
sm10.zip
/
smgidlst.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-05-14
|
10KB
|
281 lines
/* ------------------------------------------------------------------------
*
* File: smgidlst.c
* Project: Source Mapper.
* Created: October 6, 1992.
* Description: Source code to include list of items.
*
* 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 IdLstIncludeToMap ( FILE *mapf )
/*
Function: Include list of items to map file.
Date: October 6, 1992. By LEL.
Interface: mapf = Map file to include list of items.
Returns: E/O.
*/
{
int ok;
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 items */
Display (D_HEIGH, "%s", _StrMSGINCLIDLST);
/* =======================================================================*/
/* List of items: */
WrtStdLinComStart (mapf, stdwidth, linechr2);
if (o_idlist.sel)
FPrintF (mapf, "%s:\n\n", _StrMSGSELIDLSTSTR);
else
FPrintF (mapf, "%s:\n\n", _StrMSGIDLSTSTR);
if (errno != 0) /* Any error in last file I/O? */
return (ERROR);
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 */
/* Use normal objfile if only 1 source, or else use the main collected
object file */
if (prjstat.filc == 1) /* If only one source in project */
{
if (!GetFDataFromPrj (1, &fdata))/* Get name of normal objectfile */
RETURN_ERR;
if ((objf = FOpen (fdata.objn, "r+b")) == NULL)
RETERR (16, fdata.objn); /* Failed on open file! */
}
else
{
if ((objf = FOpen (tmpn.manobj, "r+b")) == NULL)
RETERR (11, tmpn.manobj); /* Failed on open main objectfile! */
}
if (!GetFPosTYPE (objf, &fpos)) /* Get indexes to blocks of data */
{
FClose (objf); /* Close objectfile if error */
RETURN_ERR;
}
if (fpos.idlst == fpos.lininf) /* Any items in project? */
{
FClose (objf); /* No, so close objectfile */
return (OK); /* And return without include list */
}
ok = IdLstIncludeToMap1 (mapf, objf, &fpos);
FClose (objf); /* Close main objectfile */
return (ok);
} /* IdLstIncludeToMap (); */
int IdLstNameInSelList ( const char *idname )
/*
Function: Test if specified item name is in list of selective items.
Programmed by: LEL
Date: December, 17. 1992.
Interface: idname = 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 inr = 1; /* Count item number */
char iname [MAXFUNCN + 1]; /* Buffer to store name of item */
/* Look trough whole selective list to see if name is in list */
while (StrPart (inr++, MAXFUNCN, iname, o_idlist.list, "(), \t\n"))
if (strcmp (idname, iname) == 0)
return (YES); /* Yes, so return name is in sel. list*/
return (NO); /* Name is not in selective list */
} /* IdLstNameInSelList (); */
int IdLstIncludeToMap1 ( FILE *mapf, FILE *objf, fposTYPE *fpos )
/*
Function: Include list of items in single source in project.
Date: April, 27. 1993. 02:15. By LEL.
Interface: mapf = Map file to include list of items in single
source in project.
objf = Main objectfile.
fpos = Indexes to blocks of data in main objectfile.
Returns: E/O.
*/
{
long inr = 0; /* Count different items */
long curpos; /* Current file position in objectfile*/
long linenr; /* Line number where a item is used */
char iname [MAXFUNCN + 1]; /* Name of current item */
int iWasHere = FALSE;
FSeek (objf, fpos->idlst,SEEK_SET); /* Start of item list data */
curpos = FTell (objf); /* Init file position controll */
while (curpos < fpos->lininf) /* Loop trough all items */
{
if (!FGetS0 (iname, MAXFUNCN + 1, objf)) /* Read name of item */
return (ERROR);
if (o_idlist.sel == O_YES) /* If selective list */
{
if (IdLstNameInSelList (iname) == 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 items */
Display (D_LOW, "%s: (%s)", _StrMSGINCLIDLST, iname);
FPrintF (mapf, "%s:\n", iname);
if (!iWasHere)
{
iWasHere = TRUE;
if (!DiffBConstruct (tmpn.sortfi, MAXFUNCN + 1))
RETURN_ERR;
}
else
{
if (!DiffBClear ())
{
DiffBDestruct ();
RETURN_ERR;
}
}
if (!IdLstIncludeToMap1_ (mapf, objf)) /* Include the references of this item */
{
DiffBDestruct (); /* Terminate buffers, etc. in 'diffb' */
RETURN_ERR;
}
inr += 1; /* Count number of different items */
curpos = FTell (objf); /* Get filpos to test if end of block */
}
DiffBDestruct ();
WritFLineLn (mapf, stdwidth, linechr1);
FPrintF (mapf, "%s: %ld\n", _StrMSGTOTIDS, inr);
WrtStdLinComEnd (mapf, stdwidth, linechr2);
FPrintF (mapf, "\n\n\n");
if (errno != 0) /* Any error in last file I/O? */
return (ERROR);
return (OK);
} /* IdLstIncludeToMap1 (); */
int IdLstIncludeToMap1_ ( FILE *mapf, FILE *objf )
/*
Function: Include name of functions which use current item, and do
neccesarry indents.
Date: April 27, 1993. 02:20. By LEL.
Interface: mapf = Map file to include list of items.
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 */
uint16 answ; /* Store result of tests */
funcTYPE func; /* Data of current function who use it*/
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 (== 0 if we find such a function) */
if (FuncRBuffLNrGet (linenr, &func) == 0)
{
FPrintF (mapf, "\t%c-%ld\n", globlinchr, linenr);
first = 0; /* Now, first loop has been passed */
continue; /* Warning: No function use this line */
}
if (!DiffBIfId (func.name, &answ)) /* Test if name allready included */
return (ERROR);
if (answ) /* Is name allready included? */
continue; /* No, so don't include a name twice */
if (!DiffBAddId (func.name)) /* Add function name in list */
RETURN_ERR;
/*---------------------------------------------------------------------*/
/* NameOfUser () L-nnn */
/* Name of function who use the item */
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);
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 */
} /* IdLstIncludeToMap1_ (); */