summaryrefslogtreecommitdiff
path: root/command_line/CmdLine/Src/Project
diff options
context:
space:
mode:
Diffstat (limited to 'command_line/CmdLine/Src/Project')
-rw-r--r--command_line/CmdLine/Src/Project/CLAccessPaths.c525
-rw-r--r--command_line/CmdLine/Src/Project/CLFiles.c165
-rw-r--r--command_line/CmdLine/Src/Project/CLOverlays.c296
-rw-r--r--command_line/CmdLine/Src/Project/CLProj.c16
-rw-r--r--command_line/CmdLine/Src/Project/CLSegs.c123
5 files changed, 1125 insertions, 0 deletions
diff --git a/command_line/CmdLine/Src/Project/CLAccessPaths.c b/command_line/CmdLine/Src/Project/CLAccessPaths.c
index e69de29..1ffcd1d 100644
--- a/command_line/CmdLine/Src/Project/CLAccessPaths.c
+++ b/command_line/CmdLine/Src/Project/CLAccessPaths.c
@@ -0,0 +1,525 @@
+#include "cmdline.h"
+
+// TODO check where this should be!
+Paths FrameworkPaths;
+Frameworks FrameworkInfo;
+
+Path *Path_Init(const OSPathSpec *dir, Path *path) {
+ path->spec = xmalloc(NULL, sizeof(OSPathSpec));
+ *path->spec = *dir;
+ path->recursive = NULL;
+ path->dirlist = NULL;
+ path->flags = 0;
+ return path;
+}
+
+Path *Path_New(const OSPathSpec *dir) {
+ Path *path;
+ path = xmalloc(NULL, sizeof(Path));
+ return Path_Init(dir, path);
+}
+
+void Path_Free(Path *path) {
+ if (path) {
+ if (path->spec)
+ xfree(path->spec);
+ if (path->recursive) {
+ Paths_Terminate(path->recursive);
+ xfree(path->recursive);
+ }
+ xfree(path);
+ }
+}
+
+Boolean Paths_Initialize(Paths *paths) {
+#line 52
+ OPTION_ASSERT(paths != NULL);
+
+ memset(paths, 0, sizeof(Paths));
+ paths->pathsArray = NULL;
+ return 1;
+}
+
+Boolean Paths_Terminate(Paths *paths) {
+ UInt16 index;
+
+#line 63
+ OPTION_ASSERT(paths != NULL);
+
+ if (paths->pathsArray) {
+ for (index = 0; index < paths->pathsCount; index++)
+ Path_Free(paths->pathsArray[index]);
+ xfree(paths->pathsArray);
+ }
+
+ paths->pathsArray = NULL;
+ return 1;
+}
+
+static Boolean Paths_GrowPaths(Paths *paths, UInt16 *index) {
+ Path **newArray;
+
+#line 84
+ OPTION_ASSERT(paths != NULL);
+
+ if (paths->pathsCount >= paths->arraySize) {
+ paths->arraySize += 20;
+ newArray = xrealloc("access paths", paths->pathsArray, sizeof(Path *) * paths->arraySize);
+ paths->pathsArray = newArray;
+ }
+
+ *index = paths->pathsCount++;
+ return 1;
+}
+
+Boolean Paths_AddPath(Paths *paths, Path *path) {
+ UInt16 ni;
+
+ if (Paths_GrowPaths(paths, &ni)) {
+ paths->pathsArray[ni] = path;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+Boolean Paths_InsertPath(Paths *paths, UInt16 index, Path *path) {
+ UInt16 ni;
+
+ if (Paths_GrowPaths(paths, &ni)) {
+ if (index > ni) {
+ index = (ni != 0) ? (ni - 1) : 0;
+ }
+ memmove(&paths->pathsArray[index + 1], &paths->pathsArray[index], sizeof(Path *) * (paths->pathsCount - index));
+ paths->pathsArray[index] = path;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+Boolean Paths_RemovePath(Paths *paths, UInt16 index) {
+ if (index >= paths->pathsCount)
+ return 0;
+
+ memmove(&paths->pathsArray[index], &paths->pathsArray[index + 1], sizeof(Path *) * (paths->pathsCount - index - 1));
+ paths->pathsCount--;
+ return 1;
+}
+
+Boolean Paths_DeletePath(Paths *paths, UInt16 index) {
+ if (index >= paths->pathsCount)
+ return 0;
+
+ Path_Free(paths->pathsArray[index]);
+ return Paths_RemovePath(paths, index);
+}
+
+Path *Paths_GetPath(Paths *paths, UInt16 pathnum) {
+#line 151
+ OPTION_ASSERT(paths != NULL);
+
+ if (pathnum < paths->pathsCount)
+ return paths->pathsArray[pathnum];
+ else
+ return NULL;
+}
+
+UInt16 Paths_Count(const Paths *paths) {
+#line 161
+ OPTION_ASSERT(paths != NULL);
+
+ return paths->pathsCount;
+}
+
+Boolean Paths_FindPath(const Paths *paths, const Path *path) {
+ UInt16 idx;
+
+#line 169
+ OPTION_ASSERT(paths != NULL);
+
+ for (idx = 0; idx < paths->pathsCount; idx++) {
+ if (paths->pathsArray[idx] == path)
+ return 1;
+ }
+
+ return 0;
+}
+
+Path *Paths_FindPathSpec(const Paths *paths, const OSPathSpec *dir) {
+ UInt16 idx;
+ Path *path;
+
+#line 182
+ OPTION_ASSERT(paths != NULL);
+
+ for (idx = 0; idx < paths->pathsCount; idx++) {
+ path = paths->pathsArray[idx];
+ if (OS_EqualPathSpec(path->spec, dir))
+ return path;
+ }
+
+ return NULL;
+}
+
+static Boolean GatherRecurse(Paths *list, Path *path) {
+ int err;
+ OSOpenedDir rf;
+ OSSpec ent;
+ int count;
+ char filename[64];
+ Boolean isfile;
+ char *nptr;
+ char *eptr;
+ UInt16 added;
+ Path *nw;
+
+ count = 0;
+ if (CheckForUserBreak())
+ return 1;
+
+ err = OS_OpenDir(path->spec, &rf);
+ while (!err) {
+ err = OS_ReadDir(&rf, &ent, filename, &isfile);
+ if (!err) {
+ if (!isfile) {
+ nw = Path_New(&ent.path);
+ nptr = OS_GetFileNamePtr(filename);
+ eptr = nptr + strlen(nptr) - 1;
+ if (eptr[0] == OS_PATHSEP)
+ eptr--;
+ if (eptr > nptr && *nptr == '(' && *eptr == ')')
+ continue;
+
+ if (!Paths_AddPath(list, nw))
+ break;
+ added = Paths_Count(list) - 1;
+ if (!GatherRecurse(list, nw))
+ Paths_DeletePath(list, added);
+ } else {
+ if (!(++count % 50) && CheckForUserBreak())
+ return 0;
+ }
+ }
+ }
+ OS_CloseDir(&rf);
+ return count > 0;
+}
+
+Boolean Paths_GatherRecurse(Path *path) {
+ path->recursive = xcalloc(NULL, sizeof(Paths));
+ GatherRecurse(path->recursive, path);
+ return Paths_Count(path->recursive) != 0;
+}
+
+int Paths_CountRecurse(Paths *paths) {
+ UInt16 idx;
+ int mine;
+ Path *path;
+
+ mine = Paths_Count(paths);
+ for (idx = 0; idx < mine; idx++) {
+ path = Paths_GetPath(paths, idx);
+#line 336
+ OPTION_ASSERT(path);
+
+ if (path->recursive)
+ mine += Paths_CountRecurse(path->recursive);
+ }
+
+ return mine;
+}
+
+static void CopyRecurseFSS(FSSpec **list, Paths *paths, UInt16 *count) {
+ UInt16 idx;
+ OSSpec spec;
+ Path *path;
+
+ for (idx = 0; idx < Paths_Count(paths); idx++) {
+ path = Paths_GetPath(paths, idx);
+#line 353
+ OPTION_ASSERT(path && *count > 0);
+ OS_MakeSpecWithPath(path->spec, NULL, 0, &spec);
+#line 355
+ OPTION_ASSERT(OS_OSSpec_To_FSSpec(&spec, *list));
+ (*list)++;
+ (*count)--;
+ if (path->recursive)
+ CopyRecurseFSS(list, path->recursive, count);
+ }
+}
+
+void Paths_CopyRecurseFSS(FSSpec *list, Paths *paths, UInt16 count) {
+ CopyRecurseFSS(&list, paths, &count);
+#line 367
+ OPTION_ASSERT(count == 0);
+}
+
+static Boolean Frameworks_Initialize(Frameworks *fws) {
+#line 405
+ OPTION_ASSERT(fws != NULL);
+
+ memset(fws, 0, sizeof(Frameworks));
+ fws->fwsArray = NULL;
+ return 1;
+}
+
+static Boolean Frameworks_Grow(Frameworks *fws, UInt16 *index) {
+ Paths_FWInfo **newArray;
+
+#line 418
+ OPTION_ASSERT(fws != NULL);
+
+ if (fws->fwsCount >= fws->arraySize) {
+ fws->arraySize += 20;
+ newArray = xrealloc("access frameworks", fws->fwsArray, sizeof(Paths_FWInfo *) * fws->arraySize);
+ fws->fwsArray = newArray;
+ }
+
+ *index = fws->fwsCount++;
+ return 1;
+}
+
+static Boolean Frameworks_Add(Frameworks *fws, Paths_FWInfo *info) {
+ UInt16 ni;
+
+ if (Frameworks_Grow(fws, &ni)) {
+ fws->fwsArray[ni] = info;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+static Paths_FWInfo *Framework_Init(OSSpec *dir, const char *name, const char *version, Paths_FWInfo *info, Path *p, Boolean hidden) {
+ info->fileSpec = *dir;
+ if (version && version[0])
+ strncpy(info->version.s, version, sizeof(info->version.s));
+ else
+ info->version.s[0] = 0;
+ strncpy(info->name.s, name, sizeof(info->name.s));
+ info->path = p;
+ info->hidden = hidden;
+ return info;
+}
+
+static Paths_FWInfo *Framework_New(OSSpec *dir, const char *name, const char *version, Path *p, Boolean hidden) {
+ Paths_FWInfo *info;
+ info = xmalloc(NULL, sizeof(Paths_FWInfo));
+ return Framework_Init(dir, name, version, info, p, hidden);
+}
+
+static Boolean CheckForFileInFrameworkDir(char *out, const char *framework_path, OSPathSpec *osps, const char *fname) {
+ int err;
+ OSSpec oss;
+
+ sprintf(out, "%s/%s", framework_path, fname);
+ err = OS_MakeSpecWithPath(osps, out, 0, &oss);
+ if (err == 0 && OS_IsFile(&oss))
+ return 1;
+
+ sprintf(out, "%s/Headers/%s", framework_path, fname);
+ err = OS_MakeSpecWithPath(osps, out, 0, &oss);
+ if (err == 0 && OS_IsFile(&oss))
+ return 1;
+
+ sprintf(out, "%s/Resources/%s", framework_path, fname);
+ err = OS_MakeSpecWithPath(osps, out, 0, &oss);
+ if (err == 0 && OS_IsFile(&oss))
+ return 1;
+
+ sprintf(out, "%s/Resources/%s", framework_path, fname);
+ err = OS_MakeSpecWithPath(osps, out, 0, &oss);
+ if (err == 0 && OS_IsFile(&oss))
+ return 1;
+
+ return 0;
+}
+
+static Boolean CheckForFileInFramework(char *out, int i, const char *fname) {
+ Paths_FWInfo *info;
+ char framework_path[256];
+
+ info = Frameworks_GetInfo(i);
+ if (strlen(info->version.s))
+ sprintf(framework_path, "%s.framework/Versions/%s", info->name.s, info->version.s);
+ else
+ sprintf(framework_path, "%s.framework", info->name.s);
+
+ if (CheckForFileInFrameworkDir(out, framework_path, info->path->spec, fname))
+ return 1;
+ else
+ return 0;
+}
+
+Boolean MakeFrameworkPath(char *out, const char *filename, Path *globalpath) {
+ Paths_FWInfo *info;
+ int err;
+ char *end;
+ char *fname;
+ char framework_name[256];
+ char framework_path[256];
+ const char *s;
+ char *d;
+ int i;
+ int n;
+
+ n = Frameworks_GetCount();
+ end = strchr(filename, OS_PATHSEP);
+ if (!end) {
+ for (i = 0; i < n; i++) {
+ info = Frameworks_GetInfo(i);
+ if (!info->hidden && CheckForFileInFramework(out, i, filename))
+ return 1;
+ }
+ return 0;
+ }
+
+ fname = end + 1;
+ s = filename;
+ d = framework_name;
+ while (s < end)
+ *(d++) = *(s++);
+ *d = 0;
+
+ for (i = 0; i < n; i++) {
+ if (!strcmp(Frameworks_GetInfo(i)->name.s, framework_name)) {
+ return CheckForFileInFramework(out, i, fname) != 0;
+ }
+ }
+
+ if (globalpath) {
+ OSSpec oss;
+ sprintf(framework_path, "../Frameworks/%s.framework", framework_name);
+ err = OS_MakeSpecWithPath(globalpath->spec, framework_path, 0, &oss);
+ if (!err && OS_IsDir(&oss)) {
+ if (CheckForFileInFrameworkDir(out, framework_path, globalpath->spec, fname))
+ return 1;
+ }
+ }
+
+ n = Paths_Count(&FrameworkPaths);
+ sprintf(framework_path, "%s.framework", framework_name);
+ for (i = 0; i < n; i++) {
+ OSSpec oss;
+ Path *p;
+ p = Paths_GetPath(&FrameworkPaths, i);
+ err = OS_MakeSpecWithPath(p->spec, framework_path, 0, &oss);
+ if (!err && OS_IsDir(&oss)) {
+ if (CheckForFileInFrameworkDir(out, framework_path, p->spec, fname)) {
+ Frameworks_AddFramework(framework_name, NULL, 1);
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+void Frameworks_AddPath(const OSPathSpec *oss) {
+ Paths_AddPath(&FrameworkPaths, Path_New(oss));
+}
+
+int Frameworks_AddFramework(const char *name, const char *version, Boolean hidden) {
+ char fullname[256];
+ int i;
+ Path *p;
+ int n_paths;
+ OSSpec oss;
+ int err;
+
+ sprintf(fullname, "%s.framework", name);
+ n_paths = Paths_Count(&FrameworkPaths);
+ for (i = 0; i < n_paths; i++) {
+ p = Paths_GetPath(&FrameworkPaths, i);
+ err = OS_MakeSpecWithPath(p->spec, fullname, 0, &oss);
+ if (!err && OS_IsDir(&oss)) {
+ if (Frameworks_Add(&FrameworkInfo, Framework_New(&oss, name, version, p, hidden))) {
+ if (version && strlen(version)) {
+ sprintf(fullname, "Versions/%s/Frameworks", version);
+ err = OS_MakeSpecWithPath(&oss.path, fullname, 0, &oss);
+ } else {
+ err = OS_MakeSpecWithPath(&oss.path, "Frameworks", 0, &oss);
+ }
+ if (!err && OS_IsDir(&oss))
+ Frameworks_AddPath(&oss.path);
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+void Framework_GetEnvInfo() {
+ char path[256];
+ char *env;
+ char *ptr;
+ OSSpec spec;
+ char name[64];
+ char version[16];
+ int err;
+ Boolean is_file;
+
+#line 672
+ OPTION_ASSERT(Paths_Initialize(&FrameworkPaths) == 1);
+ OPTION_ASSERT(Frameworks_Initialize(&FrameworkInfo) == 1);
+
+ env = getenv("MWFrameworkPaths");
+ if (env) {
+ while (*env) {
+ ptr = path;
+ while (*env && *env != ':' && (ptr + 1) < &path[sizeof(path)])
+ *(ptr++) = *(env++);
+ *ptr = 0;
+ while (*env && *env == ':')
+ env++;
+
+ if (path[0]) {
+ if (strlen(path) >= sizeof(path)) {
+ CLReportError(64, sizeof(path), path);
+ } else {
+ err = OS_MakeSpec(path, &spec, &is_file);
+ if (!is_file && !err) {
+ Frameworks_AddPath(&spec.path);
+ } else {
+ CLReportError(23, path);
+ }
+ }
+ }
+ }
+ }
+
+ env = getenv("MWFrameworkVersions");
+ if (env) {
+ while (*env) {
+ ptr = name;
+ while (*env && *env != ':' && (ptr + 1) < &name[sizeof(name)])
+ *(ptr++) = *(env++);
+ *ptr = 0;
+ while (*env && *env == ':')
+ env++;
+
+ ptr = version;
+ while (*env && *env != ',' && (ptr + 1) < &version[sizeof(version)])
+ *(ptr++) = *(env++);
+ *ptr = 0;
+ while (*env && *env == ',')
+ env++;
+
+ if (name[0])
+ Frameworks_AddFramework(name, version, 0);
+ }
+ }
+}
+
+int Frameworks_GetCount() {
+ return FrameworkInfo.fwsCount;
+}
+
+Paths_FWInfo *Frameworks_GetInfo(int which) {
+#line 762
+ OPTION_ASSERT(FrameworkInfo.fwsArray);
+ OPTION_ASSERT(FrameworkInfo.fwsCount > which);
+ return FrameworkInfo.fwsArray[which];
+}
diff --git a/command_line/CmdLine/Src/Project/CLFiles.c b/command_line/CmdLine/Src/Project/CLFiles.c
index e69de29..a13deaf 100644
--- a/command_line/CmdLine/Src/Project/CLFiles.c
+++ b/command_line/CmdLine/Src/Project/CLFiles.c
@@ -0,0 +1,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;
+}
diff --git a/command_line/CmdLine/Src/Project/CLOverlays.c b/command_line/CmdLine/Src/Project/CLOverlays.c
index e69de29..3437366 100644
--- a/command_line/CmdLine/Src/Project/CLOverlays.c
+++ b/command_line/CmdLine/Src/Project/CLOverlays.c
@@ -0,0 +1,296 @@
+#include "cmdline.h"
+
+Boolean Overlays_Initialize(Overlays *this) {
+ OvlGroup *grp;
+ Overlay *ovl;
+ OvlAddr addr;
+ SInt32 idx;
+
+#line 24
+ OPTION_ASSERT(this);
+
+ this->groups = NULL;
+ this->lastgrp = NULL;
+ this->grpcnt = 0;
+ addr.hi = 0;
+ addr.lo = 0;
+
+ grp = OvlGroup_New("main_application", addr);
+ if (!grp)
+ return 0;
+
+ ovl = Overlay_New("MAIN");
+ if (!ovl)
+ return 0;
+
+ OvlGroup_AddOverlay(grp, ovl, &idx);
+#line 42
+ OPTION_ASSERT(idx==0);
+
+ Overlays_AddOvlGroup(this, grp, &idx);
+#line 45
+ OPTION_ASSERT(idx==0);
+
+ return 1;
+}
+
+Boolean Overlays_Terminate(Overlays *this) {
+ OvlGroup *grp;
+ OvlGroup *nxtgrp;
+
+#line 54
+ OPTION_ASSERT(this);
+
+ for (grp = this->groups; grp; grp = nxtgrp) {
+ nxtgrp = grp->next;
+ OvlGroup_Delete(grp);
+ xfree(grp);
+ }
+
+ this->groups = NULL;
+ return 1;
+}
+
+Boolean Overlays_AddOvlGroup(Overlays *this, OvlGroup *grp, SInt32 *grpnum) {
+#line 70
+ OPTION_ASSERT(this);
+ OPTION_ASSERT(grp);
+
+ if (this->groups == NULL)
+ this->groups = grp;
+ else
+ this->lastgrp->next = grp;
+ this->lastgrp = grp;
+
+ if (grpnum)
+ *grpnum = this->grpcnt;
+ this->grpcnt++;
+
+ return 1;
+}
+
+OvlGroup *Overlays_GetOvlGroup(Overlays *this, SInt32 grpnum) {
+ OvlGroup *grp;
+ SInt32 cnt = 0;
+
+#line 93
+ OPTION_ASSERT(this);
+
+ grp = this->groups;
+ while (grp && cnt < grpnum) {
+ grp = grp->next;
+ cnt++;
+ }
+
+ if (cnt == grpnum)
+ return grp;
+ else
+ return NULL;
+}
+
+SInt32 Overlays_CountGroups(Overlays *this) {
+ OvlGroup *scan;
+ int num = 0;
+
+#line 112
+ OPTION_ASSERT(this);
+
+ scan = this->groups;
+ while (scan) {
+ scan = scan->next;
+ num++;
+ }
+
+ return num;
+}
+
+Boolean Overlays_AddFileToOverlay(Overlays *this, SInt32 grpnum, SInt32 ovlnum, SInt32 filenum) {
+ Overlay *oly;
+
+#line 130
+ OPTION_ASSERT(this);
+
+ oly = Overlays_GetOverlayInGroup(this, grpnum, ovlnum);
+ if (oly)
+ return Overlay_AddFile(oly, filenum, NULL);
+ else
+ return 0;
+}
+
+Overlay *Overlays_GetOverlayInGroup(Overlays *this, SInt32 grpnum, SInt32 ovlnum) {
+ OvlGroup *grp;
+
+#line 144
+ OPTION_ASSERT(this);
+
+ grp = Overlays_GetOvlGroup(this, grpnum);
+ if (grp)
+ return OvlGroup_GetOverlay(grp, ovlnum);
+ else
+ return NULL;
+}
+
+SInt32 Overlays_GetFileInOverlay(Overlays *this, SInt32 grpnum, SInt32 ovlnum, SInt32 filnum) {
+ Overlay *oly;
+
+#line 160
+ OPTION_ASSERT(this);
+
+ oly = Overlays_GetOverlayInGroup(this, grpnum, ovlnum);
+ if (oly)
+ return Overlay_GetFile(oly, filnum);
+ else
+ return -1;
+}
+
+OvlGroup *OvlGroup_New(const char *name, OvlAddr addr) {
+ OvlGroup *grp;
+
+#line 175
+ OPTION_ASSERT(name);
+
+ grp = xmalloc(NULL, sizeof(OvlGroup));
+ if (grp) {
+ strncpy(grp->name, name, sizeof(grp->name));
+ grp->name[sizeof(grp->name) - 1] = 0;
+ grp->addr = addr;
+ grp->lastoly = NULL;
+ grp->olys = NULL;
+ grp->olycnt = 0;
+ grp->next = NULL;
+ } else {
+#line 188
+ DO_INTERNAL_ERROR("Could not allocate %s", "overlay group");
+ }
+ return grp;
+}
+
+void OvlGroup_Delete(OvlGroup *grp) {
+ Overlay *scan;
+ Overlay *next;
+
+#line 197
+ OPTION_ASSERT(grp);
+
+ for (scan = grp->olys; scan; scan = next) {
+ next = scan->next;
+ Overlay_Delete(scan);
+ xfree(scan);
+ }
+
+ grp->olys = NULL;
+}
+
+Boolean OvlGroup_AddOverlay(OvlGroup *this, Overlay *oly, SInt32 *olynum) {
+#line 211
+ OPTION_ASSERT(this);
+ OPTION_ASSERT(oly);
+
+ if (!this->lastoly)
+ this->olys = oly;
+ else
+ this->lastoly->next = oly;
+ this->lastoly = oly;
+
+ if (olynum)
+ *olynum = this->olycnt;
+ this->olycnt++;
+
+ return 1;
+}
+
+Overlay *OvlGroup_GetOverlay(OvlGroup *this, SInt32 olynum) {
+ Overlay *oly;
+ SInt32 cnt = 0;
+
+#line 234
+ OPTION_ASSERT(this);
+
+ oly = this->olys;
+ while (oly && cnt < olynum) {
+ oly = oly->next;
+ cnt++;
+ }
+
+ if (cnt == olynum)
+ return oly;
+ else
+ return NULL;
+}
+
+SInt32 OvlGroup_CountOverlays(OvlGroup *this) {
+ Overlay *scan;
+ int num = 0;
+
+#line 254
+ OPTION_ASSERT(this);
+
+ scan = this->olys;
+ while (scan) {
+ scan = scan->next;
+ num++;
+ }
+
+ return num;
+}
+
+Overlay *Overlay_New(const char *name) {
+ Overlay *oly;
+
+ oly = xmalloc(NULL, sizeof(Overlay));
+ if (oly) {
+ strncpy(oly->name, name, sizeof(oly->name));
+ oly->name[sizeof(oly->name) - 1] = 0;
+ oly->list = NULL;
+ oly->max = 0;
+ oly->cnt = 0;
+ oly->next = NULL;
+ } else {
+#line 281
+ DO_INTERNAL_ERROR("Could not allocate %s", "overlay");
+ }
+ return oly;
+}
+
+void Overlay_Delete(Overlay *oly) {
+#line 288
+ OPTION_ASSERT(oly);
+
+ if (oly->list)
+ xfree(oly->list);
+ oly->list = NULL;
+}
+
+Boolean Overlay_AddFile(Overlay *oly, SInt32 filenum, SInt32 *filnum) {
+#line 296
+ OPTION_ASSERT(oly);
+
+ if (oly->cnt >= oly->max) {
+ oly->max += 16;
+ oly->list = xrealloc("overlay file list", oly->list, sizeof(SInt32) * oly->max);
+ }
+ oly->list[oly->cnt] = filenum;
+
+ if (filnum)
+ *filnum = oly->cnt;
+ oly->cnt++;
+
+ return 1;
+}
+
+SInt32 Overlay_GetFile(Overlay *oly, SInt32 filnum) {
+#line 314
+ OPTION_ASSERT(oly);
+
+ if (filnum < oly->cnt)
+ return oly->list[filnum];
+ else
+ return -1;
+}
+
+SInt32 Overlay_CountFiles(Overlay *oly) {
+#line 323
+ OPTION_ASSERT(oly);
+
+ return oly->cnt;
+}
diff --git a/command_line/CmdLine/Src/Project/CLProj.c b/command_line/CmdLine/Src/Project/CLProj.c
index e69de29..83b2ce1 100644
--- a/command_line/CmdLine/Src/Project/CLProj.c
+++ b/command_line/CmdLine/Src/Project/CLProj.c
@@ -0,0 +1,16 @@
+#include "cmdline.h"
+
+Boolean Proj_Initialize(Project *this) {
+ this->targets = NULL;
+ OS_GetCWD(&this->projectDirectory.path);
+ OS_MakeNameSpec("", &this->projectDirectory.name);
+ return 1;
+}
+
+Boolean Proj_Terminate(Project *this) {
+#line 25
+ OPTION_ASSERT(this != NULL);
+
+ Targets_Term(this->targets);
+ return 1;
+}
diff --git a/command_line/CmdLine/Src/Project/CLSegs.c b/command_line/CmdLine/Src/Project/CLSegs.c
index e69de29..a0e006c 100644
--- a/command_line/CmdLine/Src/Project/CLSegs.c
+++ b/command_line/CmdLine/Src/Project/CLSegs.c
@@ -0,0 +1,123 @@
+#include "cmdline.h"
+
+Segment *Segment_New(const char *name, UInt16 attrs) {
+ Segment *seg = xmalloc(NULL, sizeof(Segment));
+ strncpy(seg->name, name, sizeof(seg->name));
+ seg->name[sizeof(seg->name) - 1] = 0;
+ seg->attrs = attrs;
+ return seg;
+}
+
+void Segment_Free(Segment *seg) {
+ if (seg)
+ xfree(seg);
+}
+
+Boolean Segments_Initialize(Segments *segs) {
+ Segment *jump;
+ Segment *main;
+ UInt16 idx;
+
+#line 36
+ OPTION_ASSERT(segs != NULL);
+
+ memset(segs, 0, sizeof(Segments));
+ segs->segsArray = NULL;
+
+ jump = Segment_New("Jump Table", 0x28);
+ Segments_AddSegment(segs, jump, &idx);
+#line 44
+ OPTION_ASSERT(idx==0);
+
+ main = Segment_New("Main", 0xFFFF);
+ Segments_AddSegment(segs, main, &idx);
+#line 49
+ OPTION_ASSERT(idx==1);
+
+ return 1;
+}
+
+Boolean Segments_Terminate(Segments *segs) {
+ UInt16 index;
+
+#line 57
+ OPTION_ASSERT(segs != NULL);
+
+ if (segs->segsArray) {
+ for (index = 0; index < segs->segsCount; index++)
+ Segment_Free(segs->segsArray[index]);
+ xfree(segs->segsArray);
+ }
+ segs->segsArray = NULL;
+
+ return 1;
+}
+
+static Boolean Segments_GrowSegments(Segments *segs, UInt16 *index) {
+ Segment **newArray;
+
+#line 78
+ OPTION_ASSERT(segs != NULL);
+
+ if (segs->segsCount >= segs->arraySize) {
+ segs->arraySize += 20;
+ newArray = xrealloc("segments", segs->segsArray, sizeof(Segment *) * segs->arraySize);
+ segs->segsArray = newArray;
+ }
+
+ *index = segs->segsCount++;
+ return 1;
+}
+
+Boolean Segments_AddSegment(Segments *segs, Segment *seg, UInt16 *index) {
+ UInt16 ni;
+
+ if (Segments_GrowSegments(segs, &ni)) {
+ segs->segsArray[ni] = seg;
+ *index = ni;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+Boolean Segments_InsertSegment(Segments *segs, UInt16 index, Segment *seg) {
+ UInt16 ni;
+
+ if (Segments_GrowSegments(segs, &ni)) {
+ if (index > ni)
+ index = ni - 1;
+ memmove(&segs->segsArray[index + 1], &segs->segsArray[index], sizeof(Segment *) * (segs->segsCount - index));
+ segs->segsArray[index] = seg;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+Boolean Segments_DeleteSegment(Segments *segs, UInt16 index) {
+ if (index >= segs->segsCount)
+ return 0;
+
+ Segment_Free(segs->segsArray[index]);
+ memmove(&segs->segsArray[index], &segs->segsArray[index + 1], sizeof(Segment *) * (segs->segsCount - index));
+ segs->segsCount--;
+ return 1;
+}
+
+Segment *Segments_GetSegment(Segments *segs, UInt16 segnum) {
+#line 137
+ OPTION_ASSERT(segs != NULL);
+
+ if (segnum < segs->segsCount)
+ return segs->segsArray[segnum];
+ else
+ return NULL;
+}
+
+UInt16 Segments_Count(const Segments *segs) {
+#line 147
+ OPTION_ASSERT(segs != NULL);
+
+ return segs->segsCount;
+}