summaryrefslogtreecommitdiff
path: root/command_line/CmdLine/Src/Project/CLFiles.c
blob: a13deaf71a1a01b2735bd12a4773115c44235f35 (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "cmdline.h"

File *File_New() {
    File *file;
    file = xmalloc(NULL, sizeof(File));
    if (!file) {
        return NULL;
    } else {
        memset(file, 0, sizeof(File));
        return file;
    }
}

void File_Free(File *file) {
    if (file) {
        if (file->textdata) {
            DisposeHandle(file->textdata);
            file->textdata = NULL;
        }
        if (file->objectdata) {
            DisposeHandle(file->objectdata);
            file->objectdata = NULL;
        }
        if (file->browsedata) {
            DisposeHandle(file->browsedata);
            file->browsedata = NULL;
        }
        xfree(file);
    }
}

Boolean Files_Initialize(Files *this) {
#line 47
    OPTION_ASSERT(this != NULL);
    return 1;
}

Boolean Files_Terminate(Files *this) {
    File *file;
    File *next;

#line 56
    OPTION_ASSERT(this != NULL);

    for (file = this->fileList; file; file = next) {
        next = file->next;
        File_Free(file);
    }

    return 1;
}

Boolean Files_AddFile(Files *this, File *file) {
    return Files_InsertFile(this, file, this->fileCount);
}

Boolean Files_InsertFile(Files *this, File *file, SInt32 position) {
    File **scan;

#line 80
    OPTION_ASSERT(this != NULL);
    OPTION_ASSERT(file != NULL);

    if (position < 0)
        position = 0;
    else if (position > this->fileCount)
        position = this->fileCount;

    scan = &this->fileList;
    while (position > 0) {
        scan = &(*scan)->next;
        position--;
    }

    file->filenum = this->fileCount++;
    file->next = *scan;
    *scan = file;
    return 1;
}

File *Files_GetFile(Files *this, SInt32 filenum) {
    File *file;

#line 104
    OPTION_ASSERT(this != NULL);
    OPTION_ASSERT(filenum >= 0);

    file = this->fileList;
    while (file && file->filenum != filenum)
        file = file->next;
    return file;
}

File *Files_FindFile(Files *this, OSSpec *spec) {
    File *file;

    file = this->fileList;
    while (file && !OS_EqualSpec(&file->srcfss, spec))
        file = file->next;
    return file;
}

int Files_Count(Files *this) {
#line 127
    OPTION_ASSERT(this != NULL);

    return this->fileCount;
}

Boolean VFiles_Initialize(VFile **list) {
    *list = NULL;
    return 1;
}

void VFiles_Terminate(VFile **list) {
    VFile *next;

    while (*list) {
        next = (*list)->next;
        DisposeHandle((*list)->data);
        xfree(*list);
        list = &next;
    }

    *list = NULL;
}

VFile *VFile_New(const char *name, Handle data) {
    VFile *vf;

    vf = xmalloc(NULL, sizeof(VFile));
    if (!vf)
        return NULL;

    strncpy(vf->displayName, name, sizeof(vf->displayName));
    vf->displayName[sizeof(vf->displayName) - 1] = 0;

    vf->data = NewHandle(0);
    if (!vf->data || HandAndHand(data, vf->data)) {
        xfree(vf);
        return NULL;
    }

    FixTextHandle(vf->data);
    vf->next = NULL;
    return vf;
}

Boolean VFiles_Add(VFile **list, VFile *entry) {
    VFile **scan = list;
    while (*scan)
        scan = &(*scan)->next;
    *scan = entry;
    return 1;
}

VFile *VFiles_Find(VFile *list, const char *name) {
    VFile *scan = list;
    while (scan) {
        if (!strcmp(scan->displayName, name))
            break;
        scan = scan->next;
    }
    return scan;
}