Skip to content

Commit

Permalink
Improved blCheckProgName
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Martin authored and Andrew Martin committed Aug 3, 2018
1 parent e610677 commit a08dceb
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/filename.c
Expand Up @@ -78,37 +78,39 @@
*/

/************************************************************************/
/*>char *blCheckProgName()
--------------------------------
/*>BOOL *blCheckProgName(char *progname, char *expected)
-----------------------------------------------------
*//**
\param[in] *filename A PDB filename containing a PDB code
\return The PDB code (lower case)
NULL if memory allocation fails
XXXX if filename blank or NULL or if
unable to find PDB code
\return Does the program name match?
This routine attempts to convert a filename stem to a PDB code.
This routine strips the path and checks a program name.
- 12.03.15 Original By: ACRM
*/
BOOL blCheckProgName(char *progname, char *expected)
{
char *chp;
char buffer[240];

sprintf(buffer, "/%s", expected);

/* Is the last thing after a path spec the expected program name */
if((chp = strstr(progname, buffer))!=NULL)
{
if(*(chp+9) == '\0')
return(TRUE);
}
/* Is the whole thing the expected program name */
if(!strcmp(progname, expected))
return(TRUE);

/* Othewise, find the last / in the progname and return FALSE if it's
not found
*/
if((chp = strrchr(progname, '/'))==NULL)
return(FALSE);

/* Bump the pointer so it is the first character after the / and
compare with the expected name
*/
chp++;
if(!strcmp(chp, expected))
return(TRUE);

/* No match so the names differ */
return(FALSE);
}

0 comments on commit a08dceb

Please sign in to comment.