Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/util/windows/libecho.c
34907 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/*
3
* libecho.c
4
*
5
* For each argument on the command line, echo it. Should expand
6
* DOS wildcards correctly.
7
*
8
* Syntax: libecho [-p prefix] list...
9
*/
10
#include <stdio.h>
11
#include <io.h>
12
#include <string.h>
13
14
void echo_files(char *, char *);
15
16
int
17
main(int argc, char *argv[])
18
{
19
int i;
20
char *prefix;
21
22
prefix = "";
23
24
if (argc < 2) {
25
fprintf(stderr, "Usage: libecho [-p prefix] list...\n");
26
return 1;
27
}
28
29
for (i = 1 ; i < argc ; i++)
30
if (!stricmp(argv[i], "-p"))
31
prefix = argv[++i];
32
else
33
echo_files(prefix, argv[i]);
34
35
return 0;
36
}
37
38
void
39
echo_files(char *prefix, char *f)
40
{
41
intptr_t ff;
42
struct _finddata_t fdt;
43
char *slash;
44
char filepath[256];
45
46
/*
47
* We're unix based quite a bit here. Look for normal slashes and
48
* make them reverse slashes.
49
*/
50
while((slash = strrchr(f, '/')) != NULL)
51
*slash = '\\';
52
53
strcpy(filepath, f);
54
55
slash = strrchr(filepath, '\\');
56
57
if (slash) {
58
slash++;
59
*slash = 0;
60
} else {
61
filepath[0] = '\0';
62
}
63
64
ff = _findfirst(f, &fdt);
65
66
if (ff < 0)
67
return;
68
69
printf("%s%s%s\n", prefix, filepath, fdt.name);
70
71
for (;;) {
72
if (_findnext(ff, &fdt) < 0)
73
break;
74
printf("%s%s%s\n", prefix, filepath, fdt.name);
75
}
76
_findclose(ff);
77
}
78
79