home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / smapp100.zip / sm10.zip / smgidlst.c < prev    next >
C/C++ Source or Header  |  2000-05-14  |  10KB  |  281 lines

  1. /* ------------------------------------------------------------------------
  2.  *
  3.  *        File: smgidlst.c
  4.  *     Project: Source Mapper.
  5.  *     Created: October 6, 1992.
  6.  * Description: Source code to include list of items.
  7.  *
  8.  * Copyright (C) 2000 Leif-Erik Larsen.
  9.  * This file is part of the Source Mapper source package.
  10.  * Source Mapper is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published
  12.  * by the Free Software Foundation, in version 2 as it comes in the
  13.  * "COPYING" file of the XWorkplace main distribution.
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * ------------------------------------------------------------------------ */
  20.  
  21.  
  22.  
  23.  
  24. #include "smg.h"
  25.  
  26.  
  27.  
  28.  
  29. static char loclinchr;
  30. static char globlinchr;
  31.  
  32.  
  33.  
  34.  
  35. int IdLstIncludeToMap ( FILE *mapf )
  36. /*
  37.     Function: Include list of items to map file.
  38.         Date: October 6, 1992. By LEL.
  39.    Interface: mapf = Map file to include list of items.
  40.      Returns: E/O.
  41. */
  42. {
  43.    int ok;
  44.    FILE *objf;                         /* Main object file */
  45.    fposTYPE  fpos;                     /* Indexes to blocks of data in file */
  46.    prjfeTYPE fdata;                    /* Data about source in project */
  47.  
  48.    if (!prjstat.prjon)                 /* If no active project */
  49.       return (ERROR);
  50.  
  51.    /* Including list of items */
  52.    Display (D_HEIGH, "%s", _StrMSGINCLIDLST);
  53.  
  54.    /* =======================================================================*/
  55.    /* List of items:                                                         */
  56.  
  57.    WrtStdLinComStart (mapf, stdwidth, linechr2);
  58.    if (o_idlist.sel)
  59.       FPrintF (mapf, "%s:\n\n", _StrMSGSELIDLSTSTR);
  60.    else
  61.       FPrintF (mapf, "%s:\n\n", _StrMSGIDLSTSTR);
  62.  
  63.    if (errno != 0)                     /* Any error in last file I/O?        */
  64.       return (ERROR);
  65.  
  66.    loclinchr = LOCLINCHR;              /* Shortening for local line ==> 'L'  */
  67.    globlinchr = GLOBLINCHR;            /* Shortening for global line ==> 'G' */
  68.    if (prjstat.filc == 1)              /* If only one source in project      */
  69.       globlinchr = LOCLINCHR;          /* then all lines are local lines     */
  70.  
  71.    /* Use normal objfile if only 1 source, or else use the main collected
  72.       object file */
  73.    if (prjstat.filc == 1)              /* If only one source in project      */
  74.    {
  75.       if (!GetFDataFromPrj (1, &fdata))/* Get name of normal objectfile */
  76.          RETURN_ERR;
  77.  
  78.       if ((objf = FOpen (fdata.objn, "r+b")) == NULL)
  79.          RETERR (16, fdata.objn);      /* Failed on open file! */
  80.    }
  81.    else
  82.    {
  83.       if ((objf = FOpen (tmpn.manobj, "r+b")) == NULL)
  84.          RETERR (11, tmpn.manobj);     /* Failed on open main objectfile! */
  85.    }
  86.  
  87.    if (!GetFPosTYPE (objf, &fpos))     /* Get indexes to blocks of data      */
  88.    {
  89.       FClose (objf);                   /* Close objectfile if error          */
  90.       RETURN_ERR;
  91.    }
  92.  
  93.    if (fpos.idlst == fpos.lininf)      /* Any items in project?              */
  94.    {
  95.       FClose (objf);                   /* No, so close objectfile            */
  96.       return (OK);                     /* And return without include list    */
  97.    }
  98.  
  99.    ok = IdLstIncludeToMap1 (mapf, objf, &fpos);
  100.  
  101.    FClose (objf);                      /* Close main objectfile              */
  102.  
  103.    return (ok);
  104. } /* IdLstIncludeToMap (); */
  105.  
  106.  
  107.  
  108.  
  109. int IdLstNameInSelList ( const char *idname )
  110. /*
  111.         Function: Test if specified item name is in list of selective items.
  112.    Programmed by: LEL
  113.             Date: December, 17. 1992.
  114.        Interface: idname = Name to test if in selective list.
  115.          Returns: YES if name is in list, else return NO.
  116.          Comment: Allways return YES if user has optioned not to make a
  117.                   selective list.
  118. */
  119. {
  120.    int  inr = 1;                       /* Count item number                  */
  121.    char iname [MAXFUNCN + 1];          /* Buffer to store name of item       */
  122.  
  123.    /* Look trough whole selective list to see if name is in list */
  124.    while (StrPart (inr++, MAXFUNCN, iname, o_idlist.list, "(), \t\n"))
  125.       if (strcmp (idname, iname) == 0)
  126.          return (YES);                 /* Yes, so return name is in sel. list*/
  127.  
  128.    return (NO);                        /* Name is not in selective list      */
  129. } /* IdLstNameInSelList (); */
  130.  
  131.  
  132.  
  133.  
  134. int IdLstIncludeToMap1 ( FILE *mapf, FILE *objf, fposTYPE *fpos )
  135. /*
  136.     Function: Include list of items in single source in project.
  137.         Date: April, 27. 1993. 02:15. By LEL.
  138.    Interface: mapf = Map file to include list of items in single
  139.                      source in project.
  140.               objf = Main objectfile.
  141.               fpos = Indexes to blocks of data in main objectfile.
  142.      Returns: E/O.
  143. */
  144. {
  145.    long inr = 0;                       /* Count different items */
  146.    long curpos;                        /* Current file position in objectfile*/
  147.    long linenr;                        /* Line number where a item is used */
  148.    char iname [MAXFUNCN + 1];          /* Name of current item */
  149.    int iWasHere = FALSE;
  150.  
  151.    FSeek (objf, fpos->idlst,SEEK_SET); /* Start of item list data */
  152.  
  153.    curpos = FTell (objf);              /* Init file position controll */
  154.    while (curpos < fpos->lininf)       /* Loop trough all items */
  155.    {
  156.       if (!FGetS0 (iname, MAXFUNCN + 1, objf)) /* Read name of item */
  157.          return (ERROR);
  158.  
  159.       if (o_idlist.sel == O_YES)       /* If selective list */
  160.       {
  161.          if (IdLstNameInSelList (iname) == NO)
  162.          {
  163.             do                         /* Do a dummy seek over line numbers */
  164.             {
  165.                /* Read next line number reference */
  166.                if (FRead (&linenr, sizeof (long), 1, objf) != 1)
  167.                   return (ERROR);
  168.             }
  169.             while (linenr != 0L);      /* 0L if end of line number list */
  170.             curpos = FTell (objf);     /* Get filpos to test if end of block */
  171.             continue;                  /* Continue without include func.call */
  172.          }
  173.       }
  174.  
  175.       /* Including list of items */
  176.       Display (D_LOW, "%s: (%s)", _StrMSGINCLIDLST, iname);
  177.  
  178.       FPrintF (mapf, "%s:\n", iname);
  179.  
  180.       if (!iWasHere)
  181.       {
  182.          iWasHere = TRUE;
  183.          if (!DiffBConstruct (tmpn.sortfi, MAXFUNCN + 1))
  184.             RETURN_ERR;
  185.       }
  186.       else
  187.       {
  188.          if (!DiffBClear ())
  189.          {
  190.             DiffBDestruct ();
  191.             RETURN_ERR;
  192.          }
  193.       }
  194.  
  195.       if (!IdLstIncludeToMap1_ (mapf, objf)) /* Include the references of this item */
  196.       {
  197.          DiffBDestruct ();             /* Terminate buffers, etc. in 'diffb' */
  198.          RETURN_ERR;
  199.       }
  200.  
  201.       inr += 1;                        /* Count number of different items    */
  202.       curpos = FTell (objf);           /* Get filpos to test if end of block */
  203.    }
  204.  
  205.    DiffBDestruct ();
  206.  
  207.    WritFLineLn     (mapf, stdwidth, linechr1);
  208.    FPrintF         (mapf, "%s: %ld\n", _StrMSGTOTIDS, inr);
  209.    WrtStdLinComEnd (mapf, stdwidth, linechr2);
  210.    FPrintF         (mapf, "\n\n\n");
  211.  
  212.    if (errno != 0)                     /* Any error in last file I/O?        */
  213.       return (ERROR);
  214.  
  215.    return (OK);
  216. } /* IdLstIncludeToMap1 (); */
  217.  
  218.  
  219.  
  220.  
  221. int IdLstIncludeToMap1_ ( FILE *mapf, FILE *objf )
  222. /*
  223.     Function: Include name of functions which use current item, and do
  224.               neccesarry indents.
  225.         Date: April 27, 1993. 02:20. By LEL.
  226.    Interface: mapf = Map file to include list of items.
  227.               objf = Main objectfile of project.
  228.      Returns: E/O.
  229. */
  230. {
  231.    int first = 1;                      /* 0 when loop passed second and more */
  232.    long linenr;                        /* Line number where a call is done */
  233.    uint16 answ;                        /* Store result of tests */
  234.    funcTYPE func;                      /* Data of current function who use it*/
  235.  
  236.    do                                  /* Loop trough all line numbers */
  237.    {
  238.       /* Read next line number reference */
  239.       if (FRead (&linenr, sizeof (long), 1, objf) != 1)
  240.          return (ERROR);
  241.  
  242.       if (linenr == 0)                 /* 0L if end of line number list      */
  243.          break;                        /* So break loop                      */
  244.  
  245.       /* Find function who own this line (== 0 if we find such a function) */
  246.       if (FuncRBuffLNrGet (linenr, &func) == 0)
  247.       {
  248.          FPrintF (mapf, "\t%c-%ld\n", globlinchr, linenr);
  249.          first = 0;                    /* Now, first loop has been passed */
  250.          continue;                     /* Warning: No function use this line */
  251.       }
  252.  
  253.       if (!DiffBIfId (func.name, &answ)) /* Test if name allready included */
  254.          return (ERROR);
  255.  
  256.       if (answ)                        /* Is name allready included? */
  257.          continue;                     /* No, so don't include a name twice  */
  258.  
  259.       if (!DiffBAddId (func.name))     /* Add function name in list          */
  260.          RETURN_ERR;
  261.  
  262.       /*---------------------------------------------------------------------*/
  263.       /* NameOfUser () L-nnn                                                 */
  264.  
  265.       /* Name of function who use the item */
  266.       FPrintF (mapf, "\t%s ()\t%c-%ld\n", func.name, globlinchr, func.blin);
  267.  
  268.       if (errno != 0)                  /* Any error in last file I/O? */
  269.          return (ERROR);
  270.  
  271.       first = 0;                       /* Now, first loop has been passed */
  272.    }
  273.    while (1);                          /* Only break loop from inside */
  274.  
  275.    /* Empty line(s) between each block */
  276.    FPrintF (mapf, "\n%s", first ? "\n" : "");
  277.  
  278.    return (OK);                        /* OK include of references */
  279. } /* IdLstIncludeToMap1_ (); */
  280.  
  281.