LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - PathName.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 61.3 % 93 57
Test Date: 2024-03-23 14:05:01 Functions: 57.1 % 14 8
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* do not edit automatically generated by mc from PathName.  */
       2                 :             : /* 
       3                 :             :    HandleEscape - translates \a, \b, \e, \f, 
       4                 :             : , \r, \x[hex] \[octal]
       5                 :             :                   into their respective ascii codes.  It also converts
       6                 :             :                   \[any] into a single [any] character.
       7                 :             :   */
       8                 :             : 
       9                 :             : #include "config.h"
      10                 :             : #include "system.h"
      11                 :             : #include <stdbool.h>
      12                 :             : #   if !defined (PROC_D)
      13                 :             : #      define PROC_D
      14                 :             :        typedef void (*PROC_t) (void);
      15                 :             :        typedef struct { PROC_t proc; } PROC;
      16                 :             : #   endif
      17                 :             : 
      18                 :             : #   if !defined (FALSE)
      19                 :             : #      define FALSE (1==0)
      20                 :             : #   endif
      21                 :             : 
      22                 :             : #   include "GStorage.h"
      23                 :             : #if defined(__cplusplus)
      24                 :             : #   undef NULL
      25                 :             : #   define NULL 0
      26                 :             : #endif
      27                 :             : #define _PathName_H
      28                 :             : #define _PathName_C
      29                 :             : 
      30                 :             : #   include "GStorage.h"
      31                 :             : #   include "GDynamicStrings.h"
      32                 :             : #   include "GSFIO.h"
      33                 :             : #   include "GFIO.h"
      34                 :             : #   include "GM2Printf.h"
      35                 :             : #   include "GFormatStrings.h"
      36                 :             : #   include "GDynamicPath.h"
      37                 :             : #   include "GM2RTS.h"
      38                 :             : 
      39                 :             : #   define Debugging false
      40                 :             : typedef struct PathName__T1_r PathName__T1;
      41                 :             : 
      42                 :             : typedef PathName__T1 *PathName_NamedPath;
      43                 :             : 
      44                 :             : struct PathName__T1_r {
      45                 :             :                         DynamicPath_PathList pathList;
      46                 :             :                         DynamicStrings_String name;
      47                 :             :                         PathName_NamedPath tail;
      48                 :             :                         PathName_NamedPath next;
      49                 :             :                       };
      50                 :             : 
      51                 :             : static PathName_NamedPath FreeList;
      52                 :             : static PathName_NamedPath NamedPathHead;
      53                 :             : 
      54                 :             : /*
      55                 :             :    FindNamedPathFile - Post-condition: returns NIL if a file cannot be found otherwise
      56                 :             :                        it returns the path including the filename.
      57                 :             :                        It also returns a new string the name of the path.
      58                 :             :                        Pre-condition: if name = NIL then it searches
      59                 :             :                                           user path first, followed by any
      60                 :             :                                           named path.
      61                 :             :                                       elsif name = ''
      62                 :             :                                       then
      63                 :             :                                          search user path
      64                 :             :                                       else
      65                 :             :                                          search named path
      66                 :             :                                       fi
      67                 :             : */
      68                 :             : 
      69                 :             : extern "C" DynamicStrings_String PathName_FindNamedPathFile (DynamicStrings_String filename, DynamicStrings_String *name);
      70                 :             : 
      71                 :             : /*
      72                 :             :    AddInclude - adds include path to the named path.  If named path
      73                 :             :                 is the same as the previous call then the include path
      74                 :             :                 is appended to the named path PathList otherwise a new
      75                 :             :                 named path is created and placed at the end of the
      76                 :             :                 named path list.
      77                 :             : */
      78                 :             : 
      79                 :             : extern "C" void PathName_AddInclude (DynamicStrings_String named, DynamicStrings_String directory);
      80                 :             : 
      81                 :             : /*
      82                 :             :    InitNamedPath - creates a new path name with an associated pathlist.
      83                 :             : */
      84                 :             : 
      85                 :             : extern "C" PathName_NamedPath PathName_InitNamedPath (DynamicStrings_String name, DynamicPath_PathList pl);
      86                 :             : 
      87                 :             : /*
      88                 :             :    KillNamedPath - places list np onto the freelist.
      89                 :             :                    Postcondition: np will be NIL.
      90                 :             : */
      91                 :             : 
      92                 :             : extern "C" void PathName_KillNamedPath (PathName_NamedPath *np);
      93                 :             : 
      94                 :             : /*
      95                 :             :    Cons - appends pl to the end of a named path.
      96                 :             :           If np is NIL a new list is created and returned
      97                 :             :           containing named and pl.
      98                 :             : */
      99                 :             : 
     100                 :             : extern "C" PathName_NamedPath PathName_Cons (PathName_NamedPath np, DynamicStrings_String named, DynamicPath_PathList pl);
     101                 :             : 
     102                 :             : /*
     103                 :             :    ConsList - concatenates named path left and right together.
     104                 :             : */
     105                 :             : 
     106                 :             : extern "C" PathName_NamedPath PathName_ConsList (PathName_NamedPath left, PathName_NamedPath right);
     107                 :             : 
     108                 :             : /*
     109                 :             :    Stash - returns np before setting np to NIL.
     110                 :             : */
     111                 :             : 
     112                 :             : extern "C" PathName_NamedPath PathName_Stash (PathName_NamedPath *np);
     113                 :             : 
     114                 :             : /*
     115                 :             :    SetNamedPath - assigns the named path to the default path.
     116                 :             : */
     117                 :             : 
     118                 :             : extern "C" void PathName_SetNamedPath (PathName_NamedPath named);
     119                 :             : 
     120                 :             : /*
     121                 :             :    GetNamedPath - returns the default named path.
     122                 :             : */
     123                 :             : 
     124                 :             : extern "C" PathName_NamedPath PathName_GetNamedPath (void);
     125                 :             : 
     126                 :             : /*
     127                 :             :    DumpPathName - display the dictionary of names and all path entries.
     128                 :             : */
     129                 :             : 
     130                 :             : extern "C" void PathName_DumpPathName (const char *name_, unsigned int _name_high);
     131                 :             : 
     132                 :             : /*
     133                 :             :    AddSystem -
     134                 :             : */
     135                 :             : 
     136                 :             : static void AddSystem (DynamicStrings_String named, DynamicStrings_String directory);
     137                 :             : 
     138                 :             : /*
     139                 :             :    AddUser -
     140                 :             : */
     141                 :             : 
     142                 :             : static void AddUser (DynamicStrings_String named, DynamicStrings_String directory);
     143                 :             : 
     144                 :             : 
     145                 :             : /*
     146                 :             :    AddSystem -
     147                 :             : */
     148                 :             : 
     149                 :      191412 : static void AddSystem (DynamicStrings_String named, DynamicStrings_String directory)
     150                 :             : {
     151                 :      191412 :   if (NamedPathHead == NULL)
     152                 :             :     {
     153                 :             :       /* Empty dictionary add single entry.  */
     154                 :       16845 :       PathName_SetNamedPath (PathName_InitNamedPath (named, DynamicPath_InitPathList (directory)));
     155                 :             :     }
     156                 :      174567 :   else if (DynamicStrings_Equal (NamedPathHead->tail->name, named))
     157                 :             :     {
     158                 :             :       /* avoid dangling else.  */
     159                 :       55906 :       NamedPathHead->tail->pathList = DynamicPath_Cons (NamedPathHead->tail->pathList, directory);
     160                 :             :     }
     161                 :             :   else
     162                 :             :     {
     163                 :             :       /* avoid dangling else.  */
     164                 :      118661 :       PathName_SetNamedPath (PathName_ConsList (NamedPathHead, PathName_InitNamedPath (named, DynamicPath_InitPathList (directory))));
     165                 :             :     }
     166                 :      191412 : }
     167                 :             : 
     168                 :             : 
     169                 :             : /*
     170                 :             :    AddUser -
     171                 :             : */
     172                 :             : 
     173                 :       75954 : static void AddUser (DynamicStrings_String named, DynamicStrings_String directory)
     174                 :             : {
     175                 :       75954 :   if (NamedPathHead == NULL)
     176                 :             :     {
     177                 :             :       /* Empty dictionary add single entry.  */
     178                 :          22 :       PathName_SetNamedPath (PathName_InitNamedPath (named, DynamicPath_InitPathList (directory)));
     179                 :             :     }
     180                 :       75932 :   else if (DynamicStrings_EqualArray (NamedPathHead->name, (const char *) "", 0))
     181                 :             :     {
     182                 :             :       /* avoid dangling else.  */
     183                 :             :       /* Found user node.  */
     184                 :       60150 :       NamedPathHead->pathList = DynamicPath_Cons (NamedPathHead->pathList, directory);
     185                 :             :     }
     186                 :             :   else
     187                 :             :     {
     188                 :             :       /* avoid dangling else.  */
     189                 :             :       /* No user node yet, so we will create one.  */
     190                 :       15782 :       NamedPathHead = PathName_ConsList (PathName_InitNamedPath (named, DynamicPath_InitPathList (directory)), NamedPathHead);
     191                 :       15782 :       PathName_SetNamedPath (NamedPathHead);
     192                 :             :     }
     193                 :       75954 : }
     194                 :             : 
     195                 :             : 
     196                 :             : /*
     197                 :             :    FindNamedPathFile - Post-condition: returns NIL if a file cannot be found otherwise
     198                 :             :                        it returns the path including the filename.
     199                 :             :                        It also returns a new string the name of the path.
     200                 :             :                        Pre-condition: if name = NIL then it searches
     201                 :             :                                           user path first, followed by any
     202                 :             :                                           named path.
     203                 :             :                                       elsif name = ''
     204                 :             :                                       then
     205                 :             :                                          search user path
     206                 :             :                                       else
     207                 :             :                                          search named path
     208                 :             :                                       fi
     209                 :             : */
     210                 :             : 
     211                 :      182332 : extern "C" DynamicStrings_String PathName_FindNamedPathFile (DynamicStrings_String filename, DynamicStrings_String *name)
     212                 :             : {
     213                 :      182332 :   DynamicStrings_String foundFile;
     214                 :      182332 :   PathName_NamedPath np;
     215                 :             : 
     216                 :      182332 :   np = NamedPathHead;
     217                 :      689395 :   while (np != NULL)
     218                 :             :     {
     219                 :      678889 :       if (((*name) == NULL) || (DynamicStrings_Equal (np->name, (*name))))
     220                 :             :         {
     221                 :      678889 :           foundFile = DynamicPath_FindFileName (filename, np->pathList);
     222                 :      678889 :           if (foundFile != NULL)
     223                 :             :             {
     224                 :      171826 :               (*name) = DynamicStrings_Dup (np->name);
     225                 :      171826 :               return foundFile;
     226                 :             :             }
     227                 :             :         }
     228                 :      507063 :       np = np->next;
     229                 :             :     }
     230                 :       10506 :   (*name) = static_cast<DynamicStrings_String> (NULL);
     231                 :       10506 :   return static_cast<DynamicStrings_String> (NULL);
     232                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     233                 :             :   __builtin_unreachable ();
     234                 :             : }
     235                 :             : 
     236                 :             : 
     237                 :             : /*
     238                 :             :    AddInclude - adds include path to the named path.  If named path
     239                 :             :                 is the same as the previous call then the include path
     240                 :             :                 is appended to the named path PathList otherwise a new
     241                 :             :                 named path is created and placed at the end of the
     242                 :             :                 named path list.
     243                 :             : */
     244                 :             : 
     245                 :      267366 : extern "C" void PathName_AddInclude (DynamicStrings_String named, DynamicStrings_String directory)
     246                 :             : {
     247                 :      267366 :   if (Debugging)
     248                 :             :     {
     249                 :             :       M2Printf_fprintf2 (FIO_StdErr, (const char *) "named = %s, directory =%s\\n", 27, (const unsigned char *) &named, (sizeof (named)-1), (const unsigned char *) &directory, (sizeof (directory)-1));
     250                 :             :     }
     251                 :      267366 :   if ((named == NULL) || (DynamicStrings_EqualArray (named, (const char *) "", 0)))
     252                 :             :     {
     253                 :             :       /* avoid dangling else.  */
     254                 :       75954 :       AddUser (named, directory);
     255                 :       75954 :       if (Debugging)
     256                 :             :         {
     257                 :             :           PathName_DumpPathName ((const char *) "User pathname", 13);
     258                 :             :         }
     259                 :             :     }
     260                 :             :   else
     261                 :             :     {
     262                 :      191412 :       AddSystem (named, directory);
     263                 :      191412 :       if (Debugging)
     264                 :             :         {
     265                 :             :           PathName_DumpPathName ((const char *) "System pathname", 15);
     266                 :             :         }
     267                 :             :     }
     268                 :      267366 : }
     269                 :             : 
     270                 :             : 
     271                 :             : /*
     272                 :             :    InitNamedPath - creates a new path name with an associated pathlist.
     273                 :             : */
     274                 :             : 
     275                 :      151310 : extern "C" PathName_NamedPath PathName_InitNamedPath (DynamicStrings_String name, DynamicPath_PathList pl)
     276                 :             : {
     277                 :      151310 :   PathName_NamedPath np;
     278                 :             : 
     279                 :      151310 :   Storage_ALLOCATE ((void **) &np, sizeof (PathName__T1));
     280                 :      151310 :   if (np == NULL)
     281                 :             :     {
     282                 :           0 :       M2RTS_HALT (-1);
     283                 :             :       __builtin_unreachable ();
     284                 :             :     }
     285                 :             :   else
     286                 :             :     {
     287                 :      151310 :       np->pathList = pl;
     288                 :      151310 :       np->name = DynamicStrings_Dup (name);
     289                 :      151310 :       np->next = NULL;
     290                 :      151310 :       np->tail = np;
     291                 :             :     }
     292                 :      151310 :   return np;
     293                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     294                 :             :   __builtin_unreachable ();
     295                 :             : }
     296                 :             : 
     297                 :             : 
     298                 :             : /*
     299                 :             :    KillNamedPath - places list np onto the freelist.
     300                 :             :                    Postcondition: np will be NIL.
     301                 :             : */
     302                 :             : 
     303                 :           0 : extern "C" void PathName_KillNamedPath (PathName_NamedPath *np)
     304                 :             : {
     305                 :           0 :   if ((*np) != NULL)
     306                 :             :     {
     307                 :           0 :       (*np)->tail->next = FreeList;
     308                 :           0 :       FreeList = (*np);
     309                 :           0 :       (*np) = NULL;
     310                 :             :     }
     311                 :           0 : }
     312                 :             : 
     313                 :             : 
     314                 :             : /*
     315                 :             :    Cons - appends pl to the end of a named path.
     316                 :             :           If np is NIL a new list is created and returned
     317                 :             :           containing named and pl.
     318                 :             : */
     319                 :             : 
     320                 :           0 : extern "C" PathName_NamedPath PathName_Cons (PathName_NamedPath np, DynamicStrings_String named, DynamicPath_PathList pl)
     321                 :             : {
     322                 :           0 :   if (np == NULL)
     323                 :             :     {
     324                 :           0 :       np = PathName_InitNamedPath (named, pl);
     325                 :             :     }
     326                 :             :   else
     327                 :             :     {
     328                 :           0 :       np = PathName_ConsList (np, PathName_InitNamedPath (named, pl));
     329                 :             :     }
     330                 :           0 :   return np;
     331                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     332                 :             :   __builtin_unreachable ();
     333                 :             : }
     334                 :             : 
     335                 :             : 
     336                 :             : /*
     337                 :             :    ConsList - concatenates named path left and right together.
     338                 :             : */
     339                 :             : 
     340                 :      134443 : extern "C" PathName_NamedPath PathName_ConsList (PathName_NamedPath left, PathName_NamedPath right)
     341                 :             : {
     342                 :      134443 :   if (right != NULL)
     343                 :             :     {
     344                 :      134443 :       left->tail->next = right;
     345                 :      134443 :       left->tail = right->tail;
     346                 :             :     }
     347                 :      134443 :   return left;
     348                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     349                 :             :   __builtin_unreachable ();
     350                 :             : }
     351                 :             : 
     352                 :             : 
     353                 :             : /*
     354                 :             :    Stash - returns np before setting np to NIL.
     355                 :             : */
     356                 :             : 
     357                 :           0 : extern "C" PathName_NamedPath PathName_Stash (PathName_NamedPath *np)
     358                 :             : {
     359                 :           0 :   PathName_NamedPath old;
     360                 :             : 
     361                 :           0 :   old = (*np);
     362                 :           0 :   (*np) = NULL;
     363                 :           0 :   return old;
     364                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     365                 :             :   __builtin_unreachable ();
     366                 :             : }
     367                 :             : 
     368                 :             : 
     369                 :             : /*
     370                 :             :    SetNamedPath - assigns the named path to the default path.
     371                 :             : */
     372                 :             : 
     373                 :      151310 : extern "C" void PathName_SetNamedPath (PathName_NamedPath named)
     374                 :             : {
     375                 :      151310 :   NamedPathHead = named;
     376                 :      151310 : }
     377                 :             : 
     378                 :             : 
     379                 :             : /*
     380                 :             :    GetNamedPath - returns the default named path.
     381                 :             : */
     382                 :             : 
     383                 :           0 : extern "C" PathName_NamedPath PathName_GetNamedPath (void)
     384                 :             : {
     385                 :           0 :   return NamedPathHead;
     386                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     387                 :             :   __builtin_unreachable ();
     388                 :             : }
     389                 :             : 
     390                 :             : 
     391                 :             : /*
     392                 :             :    DumpPathName - display the dictionary of names and all path entries.
     393                 :             : */
     394                 :             : 
     395                 :           0 : extern "C" void PathName_DumpPathName (const char *name_, unsigned int _name_high)
     396                 :             : {
     397                 :           0 :   PathName_NamedPath np;
     398                 :           0 :   DynamicStrings_String leader;
     399                 :           0 :   char name[_name_high+1];
     400                 :             : 
     401                 :             :   /* make a local copy of each unbounded array.  */
     402                 :           0 :   memcpy (name, name_, _name_high+1);
     403                 :             : 
     404                 :           0 :   M2Printf_fprintf0 (FIO_StdErr, (const char *) name, _name_high);
     405                 :           0 :   M2Printf_fprintf0 (FIO_StdErr, (const char *) " = {\\n", 6);
     406                 :           0 :   np = NamedPathHead;
     407                 :           0 :   while (np != NULL)
     408                 :             :     {
     409                 :           0 :       leader = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "  %s", 4)), (const unsigned char *) &np->name, (sizeof (np->name)-1));
     410                 :           0 :       DynamicPath_DumpPath (leader, np->pathList);
     411                 :           0 :       leader = DynamicStrings_KillString (leader);
     412                 :           0 :       np = np->next;
     413                 :             :     }
     414                 :           0 :   M2Printf_fprintf0 (FIO_StdErr, (const char *) "}\\n", 3);
     415                 :           0 : }
     416                 :             : 
     417                 :       16867 : extern "C" void _M2_PathName_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
     418                 :             : {
     419                 :       16867 :   NamedPathHead = NULL;
     420                 :       16867 :   FreeList = NULL;
     421                 :       16867 : }
     422                 :             : 
     423                 :           0 : extern "C" void _M2_PathName_fini (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
     424                 :             : {
     425                 :           0 : }
        

Generated by: LCOV version 2.0-1

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.