-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.c
More file actions
80 lines (71 loc) · 2.83 KB
/
list.c
File metadata and controls
80 lines (71 loc) · 2.83 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
78
79
80
#include <proto/dos.h>
#include <proto/utility.h>
#include <proto/exec.h>
#include <dos/dosextens.h>
#include <string.h>
#include "utility.h"
int list(int opt)
{
char cmd[MAX_PATH_BUF];
char link[MAX_PATH_BUF];
char version[MAX_PATH_BUF];
char current_version[MAX_PATH_BUF];
char cmd_dir[MAX_PATH_BUF];
char target[MAX_PATH_BUF];
struct ExamineData *path_data, *cmd_data;
APTR path_context, cmd_context;
BPTR path_lock, cmd_lock;
int32 rc = 0;
path_lock = IDOS->Lock(SETCMD_PATH, ACCESS_READ);
if (!path_lock) {
IDOS->Printf("%sERROR %s: Failed to lock the " SETCMD_PATH " directory\n", fmt(FG_RED), fmt(NORMAL));
IDOS->Printf("Check your installation and make sure the SETCMD: assign is correctly setup.\n");
IDOS->Printf("For more information see the SetCmd manual.\n");
return RETURN_FAIL;
}
path_context = IDOS->ObtainDirContextTags(EX_LockInput, path_lock, TAG_END);
while (path_data = IDOS->ExamineDir(path_context)) {
strcpy (cmd, path_data->Name);
strcpy (link, path_data->Link);
strcpy (current_version, IDOS->FilePart(link));
// If the file is not a link, we just ignore it as it's not a valid command
if (strlen(link) > 0) {
IDOS->Printf("%s [%s%s%s]\n", cmd, fmt(SELECTED), current_version, fmt(NORMAL));
if (opt == OPT_VERBOSE) {
/* Verbose mode - for every link, get a list of the versions under the
* relevant "cmd" directory, and highlight it if it's also the currently
* selected version.
*/
strcpy(cmd_dir, SETCMD_CMDS);
IDOS->AddPart(cmd_dir, cmd, MAX_PATH_BUF);
cmd_lock = IDOS->Lock(cmd_dir, ACCESS_READ);
if (!cmd_lock) {
IDOS->Printf("%sERROR %s: Failed to lock the %s directory\n", fmt(FG_RED), fmt(NORMAL), cmd_dir);
IDOS->Printf("Check your installation and make sure the SETCMD: assign is correctly setup.\n");
IDOS->Printf("For more information see the SetCmd manual.\n");
return RETURN_FAIL;
}
// Now, get a directory listing of the available versions underneath this cmd directory
cmd_context = IDOS->ObtainDirContextTags(EX_LockInput, cmd_lock, TAG_END);
while (cmd_data = IDOS->ExamineDir(cmd_context)) {
strcpy(version, cmd_data->Name);
rc = get_target(cmd, version, target);
if (rc == SETCMD_ERROR) {
IDOS->Printf("%sERROR %s: Could not read link for %s/%s.\n", fmt(FG_RED), fmt(NORMAL), cmd, version);
return RETURN_FAIL;
}
IDOS->Printf(" %s%s%s (%s)\n", fmt(FG_BLUE), version, fmt(NORMAL), target);
}
IDOS->ReleaseDirContext(cmd_context);
if (cmd_lock) {
IDOS->UnLock(cmd_lock);
}
}
}
}
if (path_lock) {
IDOS->UnLock(path_lock);
}
IDOS->ReleaseDirContext(path_context);
return RETURN_OK;
}