File: programn.c

package info (click to toggle)
icmake 6.22-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,148 kB
  • ctags: 1,042
  • sloc: ansic: 9,241; makefile: 1,134; sh: 235; asm: 126
file content (60 lines) | stat: -rw-r--r-- 1,448 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*                       P R O G R A M N . C
    ported to non-MSDOS systems pwp 93 07 15

    % 1 name
\functoc {program\_name}
    % 2 declaration
{char * \fname (\params\ )}
    % 3 arguments
{{char *}{argv0}{The full pathname of the program, as given by, e.g.,
                 \Var{argv[0]}}
}
    % 4 return value
{A pointer to only the basename of the program.}
    % 5 functions used
{}
    % 6 see also
{}
    % 7 source file
{programn.c}
    % 8 description
{The function modifies the full pathname of the program by removing the
extension (e.g., {\sc .exe}), and returns a pointer to the first character of
the basename of the function.

    Note well that the extension is removed from the original string, and that
    the returned pointer points sowhere inside the original string.

    The function {\em assumes\,} a path in which at least one DIRSEP
    precedes the first character of the program name.
    The program name may or may notr have an extension.
    This is not checked.
}
*/
#ifndef MSDOS

#include <stdio.h>
#include <string.h>
#include "icrssdef.h"

char *program_name(char *argv)
{
    register char
        *d;

    if ( (d = strrchr (argv, DIRSEP)) )
        return (d + 1);
    return (argv);
}

#else

#include <string.h>

char *program_name(char *argv)
{
    *strrchr(argv, '.') = 0;                /* clear the extension */
    return (1 + strrchr(argv, '\\'));       /* return the program name */
}

#endif