File: flist.cc

package info (click to toggle)
qftp 0.97-1.1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 204 kB
  • ctags: 168
  • sloc: cpp: 1,336; makefile: 61
file content (109 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download
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
/*
 *  qftp
 *  Copyright (C) 1997,1998 Peter Strand
 *  Distributed under the GNU Pulic Licence
 */

#include <string.h>
#include <stdlib.h>

#include "flist.h"

FileInf &FileInf::operator=(FileInf &fi)
{
	if (fi.name)
		name = strdup(fi.name);
	else
		name = NULL;
	if (fi.date)
		date = strdup(fi.date);
	else
		date = NULL;
	perm = fi.perm;
	size = fi.size;
	type = fi.type;
	next = NULL;
}

		
FileList::FileList()
{
	first = last = cur = NULL;
}


FileList &FileList::operator=(FileList &fl)
{
	first = fl.first;
	last = fl.last;
	cur = fl.cur;
}

void FileList::Flush()
{
	if (first) {
		FileInf *tmp = first;
		FileInf *t;
		while (tmp) {
			t = tmp->next;
			if (tmp->name)
				free(tmp->name);
			if (tmp->date)
				free(tmp->date);
			delete tmp;
			tmp = t;
		}
	}
}

void FileList::AddFile(FileInf &file)
{
	FileInf *tmp;
	tmp = new FileInf;
	*tmp = file;
	if (first) {
		last->next = tmp;
		last = tmp;
	} else {
		first = tmp;
		last = tmp;
		cur = tmp;
	}
}

int FileList::GetFile(FileInf &file)
{
	if (!cur)
		return 0;
	file = *cur;
	//	file.name = strdup(cur->name);
	//	file.date = strdup(cur->date);
	
	cur = cur->next;
	return 1;
}

int FileList::GetFileAt(FileInf &file, int n)
{
	FileInf *t = first;
	while (t && --n) {
		t = t->next;
		if (!t)
			break;
	}
	if (!t || n)
		return 0;
	file = *t;
	return 1;
}

void FileList::Reset()
{
	cur = first;
}