home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / FREDV19A.LHA / FrexxEd / fpl / LoadSaveProject.FPL < prev    next >
Encoding:
Text File  |  1995-08-25  |  4.9 KB  |  223 lines

  1. /*
  2.  * SaveProject - saves all open buffers as a project file
  3.  *
  4.  * Written by Mathias Axelsson (c) 940715
  5.  *
  6.  * All info is saved in a selected file.
  7.  *
  8.  * First comes a line of info (starting with #).
  9.  * Second comes a line with (width, height, x, y position of window).
  10.  * After that comes several lines with:
  11.  * <full filename> <line> <byte position> <tab size>
  12.  *
  13.  */
  14.  
  15. void SaveProject(void)
  16. {
  17.     int id = GetBufferID();
  18.     int i = 0, j;
  19.     string tmp, outfile;
  20.     int tal;
  21.     string projectname, dir;
  22.  
  23.     dir = ReadInfo("Project_dir");
  24.     if (!strlen(dir))
  25.         dir = "FrexxEd:projects/";
  26.     else
  27.         if (dir[strlen(dir) - 1] != '/')
  28.             dir = dir + "/";
  29.  
  30.     projectname = PromptFile(dir, "Save project:", "#?.prj");
  31.  
  32.     if (strlen(projectname))
  33.     {
  34.         outfile = "# full_file_name line byte_position tab_size window;\n";
  35.  
  36.         j = ReadInfo("buffers", id);
  37.  
  38.         tal = ReadInfo("window_width", id);
  39.         outfile = joinstr(outfile, itoa(tal), " ");
  40.         tal = ReadInfo("window_height", id);
  41.         outfile = joinstr(outfile, itoa(tal), " ");
  42.         tal = ReadInfo("window_xpos", id);
  43.         outfile = joinstr(outfile, itoa(tal), " ");
  44.         tal = ReadInfo("window_ypos", id);
  45.         outfile = joinstr(outfile, itoa(tal), " ");
  46.         tal = ReadInfo("window", id);
  47.         outfile = joinstr(outfile, itoa(tal), " ;\n");
  48.  
  49.         for (i = 0; i < j; i++)
  50.         {
  51.             if (ReadInfo("type", id) & 1)
  52.             {
  53.                 tmp = ReadInfo("full_file_name", id);
  54.                 outfile = joinstr(outfile, "\"", tmp, "\"", " ");
  55.                 tal = ReadInfo("line", id);
  56.                 outfile = joinstr(outfile, itoa(tal), " ");
  57.                 tal = ReadInfo("byte_position", id);
  58.                 outfile = joinstr(outfile, itoa(tal), " ");
  59.                 tal = ReadInfo("tab_size", id);
  60.                 outfile = joinstr(outfile, itoa(tal), " ;\n");
  61.             }
  62.             id = NextBuffer(id);
  63.         }
  64.         if (SaveString(projectname, outfile))
  65.             Request("Error writing project file!", "Error message", "OK");
  66.     }
  67.     else
  68.         ReturnStatus(GetReturnMsg(GetErrNo()));
  69. }
  70.  
  71. /*
  72.  * LoadProject - Loads a project file and open buffers
  73.  *
  74.  * Written by Mathias Axelsson (c) 940715
  75.  *
  76.  * Loads the seleted project file and sets the window width, height
  77.  * x and y position. Then it opens all the files and sets line, byte
  78.  * position and tab size.
  79.  *
  80.  */
  81.  
  82. void LoadProject(void)
  83. {
  84.     int id, i, j, first = 1, x, y, w, h, win;
  85.     string infile, tmp;
  86.  
  87.     string projectname, dir;
  88.  
  89.     dir = ReadInfo("Project_dir");
  90.     if (!strlen(dir))
  91.         dir = "FrexxEd:projects/";
  92.     else
  93.         if (dir[strlen(dir) - 1] != '/')
  94.             dir = dir + "/";
  95.  
  96.     projectname = PromptFile(dir, "Load project:", "#?.prj");
  97.  
  98.     if (strlen(projectname))
  99.     {
  100.         infile = LoadString(projectname);
  101.         if (strlen(infile))
  102.         {
  103.             if (strlen(infile) == 0)
  104.             {
  105.                 Request("Error reading project file!", "Error message", "OK");
  106.                 return;
  107.             }
  108.  
  109.             if (strncmp(infile, "#", 1))
  110.             {
  111.                 Request("This is not a project file!", "Error message", "OK");
  112.                 return;
  113.             }
  114.  
  115.             i = strstr(infile, ";");
  116.             if (i < 0)
  117.                 return;
  118.  
  119.             infile = substr(infile, i + 2, 10000);
  120.  
  121.             j = strstr(infile, " ");
  122.             tmp = substr(infile, 0, j);
  123.             infile = substr(infile, j + 1, 10000);
  124.             w = atoi(tmp);
  125.  
  126.             j = strstr(infile, " ");
  127.             tmp = substr(infile, 0, j);
  128.             infile = substr(infile, j + 1, 10000);
  129.             h = atoi(tmp);
  130.  
  131.             j = strstr(infile, " ");
  132.             tmp = substr(infile, 0, j);
  133.             infile = substr(infile, j + 1, 10000);
  134.             x = atoi(tmp);
  135.  
  136.             j = strstr(infile, " ");
  137.             tmp = substr(infile, 0, j);
  138.             infile = substr(infile, j + 1, 10000);
  139.             y = atoi(tmp);
  140.  
  141.             j = strstr(infile, " ");
  142.             tmp = substr(infile, 0, j);
  143.             infile = substr(infile, j + 3, 10000);
  144.             win = atoi(tmp);
  145.  
  146.             SetInfo(id, "window_width", w, "window_height", h, "window_xpos", x, "window_ypos", y, "window", win);
  147.  
  148.             for (;;)
  149.             {
  150.                 if (strlen(infile) == 0)
  151.                     break;
  152.  
  153.                 infile = substr(infile, 1, 1000);
  154.                 j = strstr(infile, "\"");
  155.                 tmp = substr(infile, 0, j);
  156.                 infile = substr(infile, j + 2, 10000);
  157.  
  158.                 if (first)
  159.                 {
  160.                     id = GetBufferID();
  161.  
  162.                     if (strlen(ReadInfo("file_name", id)) != 0 ||
  163.                          ReadInfo("changes", id) != 0)
  164.                     {
  165.                         id = New();
  166.                         if (!id)
  167.                         {
  168.                             Request("Can't create new buffer", "Error message", "OK");
  169.                             return;
  170.                         }
  171.                     }
  172.  
  173.                     first = 0;
  174.                 }
  175.                 else
  176.                 {
  177.                     id = New();
  178.                     if (!id)
  179.                     {
  180.                         Request("Can't create new buffer", "Error message", "OK");
  181.                         return;
  182.                     }
  183.                 }
  184.  
  185.                 CurrentBuffer(id);
  186.                 if (!Load(tmp))
  187.                 {
  188.                     Request("Error loading file!", "Error message", "OK");
  189.                     return;
  190.                 }
  191.  
  192.                 j = strstr(infile, " ");
  193.                 tmp = substr(infile, 0, j);
  194.                 infile = substr(infile, j + 1, 10000);
  195.  
  196.                 y = atoi(tmp);
  197.  
  198.                 j = strstr(infile, " ");
  199.                 tmp = substr(infile, 0, j);
  200.                 infile = substr(infile, j + 1, 10000);
  201.  
  202.                 x = atoi(tmp);
  203.  
  204.                 GotoLine(y, x);
  205.  
  206.                 j = strstr(infile, " ");
  207.                 tmp = substr(infile, 0, j);
  208.                 infile = substr(infile, j + 1, 10000);
  209.  
  210.                 SetInfo(id, "tab_size", atoi(tmp));
  211.  
  212.                 j = strstr(infile, ";");
  213.                 infile = substr(infile, j + 2, 10000);
  214.             }
  215.         }
  216.     }
  217. }
  218.  
  219. //AssignKey("SaveProject();", "Amiga P s");
  220. //AssignKey("LoadProject();", "Amiga P l");
  221.  
  222. //ConstructInfo("Project_dir", "", "", "GS", "", 0, 0, "FrexxEd:projects");
  223.