-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarp.c
82 lines (70 loc) · 2.31 KB
/
warp.c
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
81
82
#include "headers.h"
void warp(char *c, char *initial_address, char *current_address)
{
char *tokens[100];
int number_of_tokens = 0;
char *token = strtok(c, " ");
while (token != NULL)
{
tokens[number_of_tokens++] = strdup(token);
token = strtok(NULL, " ");
}
char showing_address[256];
if (number_of_tokens == 1)
{
int result3 = chdir(initial_address);
char current_address[1024];
char *result4 = getcwd(current_address, 256);
// strcpy(showing_address,get_showing_address(current_address));
strcpy(showing_address, current_address);
char *occurrence = strstr(showing_address, initial_address);
while (occurrence)
{
int position = occurrence - showing_address;
showing_address[position] = '~';
for (int i = 1; i < strlen(initial_address); i++)
{
showing_address[position + i] = '\0';
}
occurrence = strstr(occurrence + 1, initial_address);
}
printf("%s\n", showing_address);
return;
}
if (number_of_tokens >= 2)
{
for (int i = 1; i < number_of_tokens; i++)
{
// printf("'%s'", tokens[1]);
if (!strcmp(tokens[i], "~") || !strcmp(tokens[i], " "))
{
int result3 = chdir(initial_address);
}
else if (!strcmp(tokens[i], "-"))
{
printf("%s\n", current_address);
continue;
}
else
{
int result3 = chdir(tokens[i]);
}
char current_address[1024];
char *result5 = getcwd(current_address, 256);
strcpy(showing_address, current_address);
char *occurrence = strstr(showing_address, initial_address);
while (occurrence)
{
int position = occurrence - showing_address;
showing_address[position] = '~';
for (int i = 1; i < strlen(initial_address); i++)
{
showing_address[position + i] = '\0';
}
occurrence = strstr(occurrence + 1, initial_address);
}
printf("%s\n", current_address);
}
return;
}
}