-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdir.c
144 lines (127 loc) · 3.55 KB
/
dir.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
*
* This file is part of ED.
*
* ED is free software; you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation.
*
* ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with ED
* (see the file COPYING). If not, write to the Free Software Foundation, 675
* Mass Ave, Cambridge, MA 02139, USA.
*/
#include "opsys.h"
#include <stdio.h>
#include "rec.h"
#include "window.h"
#include "ed_dec.h"
/* note, none of these routines should be called by systems that set NO_FTP. */
/* but, we have them to keep the linker happy */
#ifdef NO_FTP
void dir_destroy(window)
Int window;
{
return;
}
rec_ptr dir_find(window,dirname)
Int window;
Char *dirname;
{
return(NULL);
}
void dir_store(window,dirname,buffer)
Int window;
Char *dirname;
rec_ptr buffer;
{
return;
}
#else /* not NO_FTP */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct dir_str *dir_ptr;
typedef struct dir_str
{
dir_ptr next;
Char *dirname;
rec_ptr buffer;
} dir_node;
static dir_ptr base[32] = {
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; /* this limits ED to 32 simultaneous windows */
/******************************************************************************\
|Routine: dir_destroy
|Callby: main wincom
|Purpose: Removes a directory from the list of already-visited directories.
|Arguments:
| window is the window number of the diredit buffer to remove.
\******************************************************************************/
void dir_destroy(window)
Int window;
{
dir_ptr p,l;
Int i;
for(l = base[window];l;)
{
ifree(l->dirname);
p = l->next;
ifree(l);
l = p;
}
for(i = window;i < NWINDOWS;i++) /* squidge all the base pointers */
base[i] = base[i + 1];
base[NWINDOWS - 1] = NULL;
return;
}
/******************************************************************************\
|Routine: dir_find
|Callby: edit
|Purpose: Retrieves an already-visited diredit buffer by name.
|Arguments:
| window is the window number of the diredit tree to search within.
| dirname is the name of the dir to search for.
\******************************************************************************/
rec_ptr dir_find(window,dirname)
Int window;
Char *dirname;
{
dir_ptr l;
for(l = base[window];l;l = l->next)
if(!strcmp(dirname,l->dirname))
return(l->buffer);
return(NULL);
}
/******************************************************************************\
|Routine: dir_store
|Callby: edit insert_win main
|Purpose: Adds a diredit buffer to the list for a window.
|Arguments:
| window is the window number.
| dirname is the name of the directory that is to be stored.
| buffer is the diredit buffer to be stored.
\******************************************************************************/
void dir_store(window,dirname,buffer)
Int window;
Char *dirname;
rec_ptr buffer;
{
dir_ptr new;
if(!dir_find(window,dirname))
{
new = (dir_ptr)imalloc(sizeof(dir_node));
new->next = base[window];
base[window] = new;
new->dirname = (Char *)imalloc(strlen(dirname) + 1);
strcpy(new->dirname,dirname);
new->buffer = buffer;
}
return;
}
#endif