home *** CD-ROM | disk | FTP | other *** search
- /*
- * SaveProject - saves all open buffers as a project file
- *
- * Written by Mathias Axelsson (c) 940715
- *
- * All info is saved in a selected file.
- *
- * First comes a line of info (starting with #).
- * Second comes a line with (width, height, x, y position of window).
- * After that comes several lines with:
- * <full filename> <line> <byte position> <tab size>
- *
- */
-
- void SaveProject(void)
- {
- int id = GetBufferID();
- int i = 0, j;
- string tmp, outfile;
- int tal;
- string projectname, dir;
-
- dir = ReadInfo("Project_dir");
- if (!strlen(dir))
- dir = "FrexxEd:projects/";
- else
- if (dir[strlen(dir) - 1] != '/')
- dir = dir + "/";
-
- projectname = PromptFile(dir, "Save project:", "#?.prj");
-
- if (strlen(projectname))
- {
- outfile = "# full_file_name line byte_position tab_size window;\n";
-
- j = ReadInfo("buffers", id);
-
- tal = ReadInfo("window_width", id);
- outfile = joinstr(outfile, itoa(tal), " ");
- tal = ReadInfo("window_height", id);
- outfile = joinstr(outfile, itoa(tal), " ");
- tal = ReadInfo("window_xpos", id);
- outfile = joinstr(outfile, itoa(tal), " ");
- tal = ReadInfo("window_ypos", id);
- outfile = joinstr(outfile, itoa(tal), " ");
- tal = ReadInfo("window", id);
- outfile = joinstr(outfile, itoa(tal), " ;\n");
-
- for (i = 0; i < j; i++)
- {
- if (ReadInfo("type", id) & 1)
- {
- tmp = ReadInfo("full_file_name", id);
- outfile = joinstr(outfile, "\"", tmp, "\"", " ");
- tal = ReadInfo("line", id);
- outfile = joinstr(outfile, itoa(tal), " ");
- tal = ReadInfo("byte_position", id);
- outfile = joinstr(outfile, itoa(tal), " ");
- tal = ReadInfo("tab_size", id);
- outfile = joinstr(outfile, itoa(tal), " ;\n");
- }
- id = NextBuffer(id);
- }
- if (SaveString(projectname, outfile))
- Request("Error writing project file!", "Error message", "OK");
- }
- else
- ReturnStatus(GetReturnMsg(GetErrNo()));
- }
-
- /*
- * LoadProject - Loads a project file and open buffers
- *
- * Written by Mathias Axelsson (c) 940715
- *
- * Loads the seleted project file and sets the window width, height
- * x and y position. Then it opens all the files and sets line, byte
- * position and tab size.
- *
- */
-
- void LoadProject(void)
- {
- int id, i, j, first = 1, x, y, w, h, win;
- string infile, tmp;
-
- string projectname, dir;
-
- dir = ReadInfo("Project_dir");
- if (!strlen(dir))
- dir = "FrexxEd:projects/";
- else
- if (dir[strlen(dir) - 1] != '/')
- dir = dir + "/";
-
- projectname = PromptFile(dir, "Load project:", "#?.prj");
-
- if (strlen(projectname))
- {
- infile = LoadString(projectname);
- if (strlen(infile))
- {
- if (strlen(infile) == 0)
- {
- Request("Error reading project file!", "Error message", "OK");
- return;
- }
-
- if (strncmp(infile, "#", 1))
- {
- Request("This is not a project file!", "Error message", "OK");
- return;
- }
-
- i = strstr(infile, ";");
- if (i < 0)
- return;
-
- infile = substr(infile, i + 2, 10000);
-
- j = strstr(infile, " ");
- tmp = substr(infile, 0, j);
- infile = substr(infile, j + 1, 10000);
- w = atoi(tmp);
-
- j = strstr(infile, " ");
- tmp = substr(infile, 0, j);
- infile = substr(infile, j + 1, 10000);
- h = atoi(tmp);
-
- j = strstr(infile, " ");
- tmp = substr(infile, 0, j);
- infile = substr(infile, j + 1, 10000);
- x = atoi(tmp);
-
- j = strstr(infile, " ");
- tmp = substr(infile, 0, j);
- infile = substr(infile, j + 1, 10000);
- y = atoi(tmp);
-
- j = strstr(infile, " ");
- tmp = substr(infile, 0, j);
- infile = substr(infile, j + 3, 10000);
- win = atoi(tmp);
-
- SetInfo(id, "window_width", w, "window_height", h, "window_xpos", x, "window_ypos", y, "window", win);
-
- for (;;)
- {
- if (strlen(infile) == 0)
- break;
-
- infile = substr(infile, 1, 1000);
- j = strstr(infile, "\"");
- tmp = substr(infile, 0, j);
- infile = substr(infile, j + 2, 10000);
-
- if (first)
- {
- id = GetBufferID();
-
- if (strlen(ReadInfo("file_name", id)) != 0 ||
- ReadInfo("changes", id) != 0)
- {
- id = New();
- if (!id)
- {
- Request("Can't create new buffer", "Error message", "OK");
- return;
- }
- }
-
- first = 0;
- }
- else
- {
- id = New();
- if (!id)
- {
- Request("Can't create new buffer", "Error message", "OK");
- return;
- }
- }
-
- CurrentBuffer(id);
- if (!Load(tmp))
- {
- Request("Error loading file!", "Error message", "OK");
- return;
- }
-
- j = strstr(infile, " ");
- tmp = substr(infile, 0, j);
- infile = substr(infile, j + 1, 10000);
-
- y = atoi(tmp);
-
- j = strstr(infile, " ");
- tmp = substr(infile, 0, j);
- infile = substr(infile, j + 1, 10000);
-
- x = atoi(tmp);
-
- GotoLine(y, x);
-
- j = strstr(infile, " ");
- tmp = substr(infile, 0, j);
- infile = substr(infile, j + 1, 10000);
-
- SetInfo(id, "tab_size", atoi(tmp));
-
- j = strstr(infile, ";");
- infile = substr(infile, j + 2, 10000);
- }
- }
- }
- }
-
- //AssignKey("SaveProject();", "Amiga P s");
- //AssignKey("LoadProject();", "Amiga P l");
-
- //ConstructInfo("Project_dir", "", "", "GS", "", 0, 0, "FrexxEd:projects");
-