-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
executable file
·77 lines (63 loc) · 1.71 KB
/
utils.c
File metadata and controls
executable file
·77 lines (63 loc) · 1.71 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* utils.c: utility functions for html2texi */ /* JMJ */
/* See the file COPYING for copying conditions */
#include <config.h>
#include <string.h>
#include <stdio.h>
#include <utils.h>
/* quotation_marks:
return an appropriate type of quotation marks based on
depth: if 1 then double, if >1 then single quotes
type: if 0 then return open, if 1 then return close quotes
The caller should insure that depth and type have the proper values.
*/
char *
quotation_marks(int depth, int type)
{
if (depth >=2) return (!type)?"`":"'";
else return (!type)?"``":"''";
}
/* convert_extension:
change the extension of old_name to
new_extension if old_name ends with any extension in
old_extension. otherwise, append new_extension to old_name.
old_name: the name to be changed
old_extension: extension to be replaced
new_extension: the new extension
*/
char *
convert_extension(const char *old_name,const char *old_extension,const char *new_extension)
{
char *new_name;
if (strend(old_name,old_extension)) {
new_name=strndup(old_name,strlen(old_name)-strlen(old_extension));
new_name=strcat(new_name,new_extension);
}
else {
new_name=strdup(old_name);
new_name=strcat(new_name,new_extension);
}
return new_name;
}
/* base_name:
return a copy of the basename of s, as if s were a filename.
would be more portable if the '/' werent hardcoded.
*/
char *
base_name(const char *s)
{
char *ptr;
return (ptr=strrchr(s,'/'))?strdup(++ptr):strdup(s);
}
/* strend:
return non-zero if a string s ends with a substring t, 0 otherwise.
*/
int strend(const char *s, const char *t)
{
return !strcmp(s+strlen(s)-strlen(t),t);
}
/*
Local Variables:
mode: c
compile-command: "make"
End:
*/