LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - DynamicPath.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 58.9 % 56 33
Test Date: 2026-02-28 14:20:25 Functions: 60.0 % 10 6
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* do not edit automatically generated by mc from DynamicPath.  */
       2              : /* DynamicPath.mod implements a path for DynamicStrings.
       3              : 
       4              : Copyright (C) 2001-2026 Free Software Foundation, Inc.
       5              : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
       6              : 
       7              : This file is part of GNU Modula-2.
       8              : 
       9              : GNU Modula-2 is free software; you can redistribute it and/or modify
      10              : it under the terms of the GNU General Public License as published by
      11              : the Free Software Foundation; either version 3, or (at your option)
      12              : any later version.
      13              : 
      14              : GNU Modula-2 is distributed in the hope that it will be useful, but
      15              : WITHOUT ANY WARRANTY; without even the implied warranty of
      16              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17              : General Public License for more details.
      18              : 
      19              : Under Section 7 of GPL version 3, you are granted additional
      20              : permissions described in the GCC Runtime Library Exception, version
      21              : 3.1, as published by the Free Software Foundation.
      22              : 
      23              : You should have received a copy of the GNU General Public License and
      24              : a copy of the GCC Runtime Library Exception along with this program;
      25              : see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
      26              : <http://www.gnu.org/licenses/>.  */
      27              : 
      28              : #include "config.h"
      29              : #include "system.h"
      30              : #include <stdbool.h>
      31              : #   if !defined (PROC_D)
      32              : #      define PROC_D
      33              :        typedef void (*PROC_t) (void);
      34              :        typedef struct { PROC_t proc; } PROC;
      35              : #   endif
      36              : 
      37              : #   if !defined (FALSE)
      38              : #      define FALSE (1==0)
      39              : #   endif
      40              : 
      41              : #   include "GStorage.h"
      42              : #if defined(__cplusplus)
      43              : #   undef NULL
      44              : #   define NULL 0
      45              : #endif
      46              : #define _DynamicPath_C
      47              : 
      48              : #include "GDynamicPath.h"
      49              : #   include "GStorage.h"
      50              : #   include "GDynamicStrings.h"
      51              : #   include "GSFIO.h"
      52              : #   include "GFIO.h"
      53              : #   include "GM2Printf.h"
      54              : 
      55              : #   define Directory '/'
      56              : #   define Debugging false
      57              : typedef struct DynamicPath__T1_r DynamicPath__T1;
      58              : 
      59              : typedef DynamicPath__T1 *DynamicPath_PathList__opaque;
      60              : 
      61              : struct DynamicPath__T1_r {
      62              :                            DynamicPath_PathList__opaque tail;
      63              :                            DynamicPath_PathList__opaque next;
      64              :                            DynamicStrings_String entry;
      65              :                          };
      66              : 
      67              : static DynamicPath_PathList__opaque FreeList;
      68              : 
      69              : /*
      70              :    InitPathList - creates a new empty path list.
      71              :                   It takes a copy of the string.
      72              : */
      73              : 
      74              : extern "C" DynamicPath_PathList DynamicPath_InitPathList (DynamicStrings_String str);
      75              : 
      76              : /*
      77              :    KillPathList - places list pl onto the freelist.
      78              :                   Postcondition: pl will be NIL.
      79              : */
      80              : 
      81              : extern "C" void DynamicPath_KillPathList (DynamicPath_PathList *pl);
      82              : 
      83              : /*
      84              :    Cons - appends str to the end of a path list.
      85              :           If pl is NIL a new list is created and returned
      86              :           containing str.
      87              : */
      88              : 
      89              : extern "C" DynamicPath_PathList DynamicPath_Cons (DynamicPath_PathList pl, DynamicStrings_String str);
      90              : 
      91              : /*
      92              :    ConsList - concatenates path list left and right together.
      93              : */
      94              : 
      95              : extern "C" DynamicPath_PathList DynamicPath_ConsList (DynamicPath_PathList left, DynamicPath_PathList right);
      96              : 
      97              : /*
      98              :    Stash - returns pl before setting pl to NIL.
      99              : */
     100              : 
     101              : extern "C" DynamicPath_PathList DynamicPath_Stash (DynamicPath_PathList *pl);
     102              : 
     103              : /*
     104              :    FindFileName - returns NIL if a file cannot be found otherwise
     105              :                   it returns the path including the filename.
     106              : */
     107              : 
     108              : extern "C" DynamicStrings_String DynamicPath_FindFileName (DynamicStrings_String filename, DynamicPath_PathList pl);
     109              : 
     110              : /*
     111              :    DumpPath - debugging dump of the pathlist.
     112              : */
     113              : 
     114              : extern "C" void DynamicPath_DumpPath (DynamicStrings_String name, DynamicPath_PathList pl);
     115              : 
     116              : /*
     117              :    AddDir - if str is not empty and does not end with / then add
     118              :             a directory.
     119              :             Postcondition: str is returned (with a '/' at the end)
     120              :             or is empty.
     121              : */
     122              : 
     123              : static DynamicStrings_String AddDir (DynamicStrings_String str);
     124              : 
     125              : 
     126              : /*
     127              :    AddDir - if str is not empty and does not end with / then add
     128              :             a directory.
     129              :             Postcondition: str is returned (with a '/' at the end)
     130              :             or is empty.
     131              : */
     132              : 
     133      1952508 : static DynamicStrings_String AddDir (DynamicStrings_String str)
     134              : {
     135      1952508 :   if ((DynamicStrings_Length (str)) > 0)
     136              :     {
     137      1952508 :       if ((DynamicStrings_char (str, -1)) != Directory)
     138              :         {
     139      1915608 :           str = DynamicStrings_ConCatChar (str, Directory);
     140              :         }
     141              :     }
     142      1952508 :   return str;
     143              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     144              :   __builtin_unreachable ();
     145              : }
     146              : 
     147              : 
     148              : /*
     149              :    InitPathList - creates a new empty path list.
     150              :                   It takes a copy of the string.
     151              : */
     152              : 
     153       245780 : extern "C" DynamicPath_PathList DynamicPath_InitPathList (DynamicStrings_String str)
     154              : {
     155       245780 :   DynamicPath_PathList__opaque pl;
     156              : 
     157       245780 :   Storage_ALLOCATE ((void **) &pl, sizeof (DynamicPath__T1));
     158       245780 :   pl->tail = pl;
     159       245780 :   pl->next = static_cast<DynamicPath_PathList__opaque> (NULL);
     160       245780 :   pl->entry = DynamicStrings_Dup (str);
     161       245780 :   return static_cast<DynamicPath_PathList> (pl);
     162              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     163              :   __builtin_unreachable ();
     164              : }
     165              : 
     166              : 
     167              : /*
     168              :    KillPathList - places list pl onto the freelist.
     169              :                   Postcondition: pl will be NIL.
     170              : */
     171              : 
     172            0 : extern "C" void DynamicPath_KillPathList (DynamicPath_PathList *pl)
     173              : {
     174            0 :   if ((*pl) != NULL)
     175              :     {
     176            0 :       static_cast<DynamicPath_PathList__opaque> ((*pl))->tail->next = FreeList;
     177            0 :       FreeList = static_cast<DynamicPath_PathList__opaque> ((*pl));
     178            0 :       (*pl) = static_cast<DynamicPath_PathList> (NULL);
     179              :     }
     180            0 : }
     181              : 
     182              : 
     183              : /*
     184              :    Cons - appends str to the end of a path list.
     185              :           If pl is NIL a new list is created and returned
     186              :           containing str.
     187              : */
     188              : 
     189       109847 : extern "C" DynamicPath_PathList DynamicPath_Cons (DynamicPath_PathList pl, DynamicStrings_String str)
     190              : {
     191       109847 :   if (pl == NULL)
     192              :     {
     193            0 :       pl = DynamicPath_InitPathList (str);
     194              :     }
     195              :   else
     196              :     {
     197       109847 :       pl = DynamicPath_ConsList (pl, DynamicPath_InitPathList (str));
     198              :     }
     199       109847 :   return pl;
     200              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     201              :   __builtin_unreachable ();
     202              : }
     203              : 
     204              : 
     205              : /*
     206              :    ConsList - concatenates path list left and right together.
     207              : */
     208              : 
     209       109847 : extern "C" DynamicPath_PathList DynamicPath_ConsList (DynamicPath_PathList left, DynamicPath_PathList right)
     210              : {
     211       109847 :   if (right != NULL)
     212              :     {
     213       109847 :       static_cast<DynamicPath_PathList__opaque> (left)->tail->next = static_cast<DynamicPath_PathList__opaque> (right);
     214       109847 :       static_cast<DynamicPath_PathList__opaque> (left)->tail = static_cast<DynamicPath_PathList__opaque> (right)->tail;
     215              :     }
     216       109847 :   return left;
     217              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     218              :   __builtin_unreachable ();
     219              : }
     220              : 
     221              : 
     222              : /*
     223              :    Stash - returns pl before setting pl to NIL.
     224              : */
     225              : 
     226            0 : extern "C" DynamicPath_PathList DynamicPath_Stash (DynamicPath_PathList *pl)
     227              : {
     228            0 :   DynamicPath_PathList__opaque old;
     229              : 
     230            0 :   old = static_cast<DynamicPath_PathList__opaque> ((*pl));
     231            0 :   (*pl) = static_cast<DynamicPath_PathList> (NULL);
     232            0 :   return static_cast<DynamicPath_PathList> (old);
     233              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     234              :   __builtin_unreachable ();
     235              : }
     236              : 
     237              : 
     238              : /*
     239              :    FindFileName - returns NIL if a file cannot be found otherwise
     240              :                   it returns the path including the filename.
     241              : */
     242              : 
     243      1026326 : extern "C" DynamicStrings_String DynamicPath_FindFileName (DynamicStrings_String filename, DynamicPath_PathList pl)
     244              : {
     245      1026326 :   DynamicStrings_String s;
     246              : 
     247      2748866 :   while (pl != NULL)
     248              :     {
     249      1952508 :       s = DynamicStrings_ConCat (AddDir (DynamicStrings_Dup (static_cast<DynamicPath_PathList__opaque> (pl)->entry)), DynamicStrings_Dup (filename));
     250      1952508 :       if (Debugging)
     251              :         {
     252              :           M2Printf_fprintf1 (FIO_StdErr, (const char *) "testing for %s: ", 16, (const unsigned char *) &s, (sizeof (s)-1));
     253              :         }
     254      1952508 :       if (SFIO_Exists (s))
     255              :         {
     256              :           if (Debugging)
     257              :             {
     258              :               M2Printf_fprintf0 (FIO_StdErr, (const char *) "yes\\n", 5);
     259              :             }
     260              :           return s;
     261              :         }
     262      1722540 :       if (Debugging)
     263              :         {
     264              :           M2Printf_fprintf0 (FIO_StdErr, (const char *) "no\\n", 4);
     265              :         }
     266      1722540 :       s = DynamicStrings_KillString (s);
     267      1722540 :       pl = static_cast<DynamicPath_PathList> (static_cast<DynamicPath_PathList__opaque> (pl)->next);
     268              :     }
     269              :   if (Debugging)
     270              :     {
     271              :       M2Printf_fprintf1 (FIO_StdErr, (const char *) "FindFileName did not find: %s in path\\n", 39, (const unsigned char *) &filename, (sizeof (filename)-1));
     272              :     }
     273              :   return static_cast<DynamicStrings_String> (NULL);
     274              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     275              :   __builtin_unreachable ();
     276              : }
     277              : 
     278              : 
     279              : /*
     280              :    DumpPath - debugging dump of the pathlist.
     281              : */
     282              : 
     283            0 : extern "C" void DynamicPath_DumpPath (DynamicStrings_String name, DynamicPath_PathList pl)
     284              : {
     285            0 :   M2Printf_fprintf1 (FIO_StdErr, (const char *) "%s:", 3, (const unsigned char *) &name, (sizeof (name)-1));
     286            0 :   while (pl != NULL)
     287              :     {
     288            0 :       M2Printf_fprintf0 (FIO_StdErr, (const char *) " {", 2);
     289            0 :       M2Printf_fprintf1 (FIO_StdErr, (const char *) "%s", 2, (const unsigned char *) &static_cast<DynamicPath_PathList__opaque> (pl)->entry, (sizeof (static_cast<DynamicPath_PathList__opaque> (pl)->entry)-1));
     290            0 :       M2Printf_fprintf0 (FIO_StdErr, (const char *) "}", 1);
     291            0 :       pl = static_cast<DynamicPath_PathList> (static_cast<DynamicPath_PathList__opaque> (pl)->next);
     292              :     }
     293            0 :   M2Printf_fprintf0 (FIO_StdErr, (const char *) "\\n", 2);
     294            0 : }
     295              : 
     296        14952 : extern "C" void _M2_DynamicPath_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     297              : {
     298        14952 :   FreeList = static_cast<DynamicPath_PathList__opaque> (NULL);
     299        14952 : }
     300              : 
     301            0 : extern "C" void _M2_DynamicPath_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     302              : {
     303            0 : }
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.