home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / DVD!FX17.LHA / FrexxEd / fpl / LoadSaveProject.FPL < prev    next >
Encoding:
Text File  |  1995-02-22  |  5.0 KB  |  189 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;
  22.  
  23.   projectname=PromptFile("FrexxEd:Projects/", "Save project:", "#?.prj");
  24.  
  25.   if (strlen(projectname)) {
  26.     outfile = "# full_file_name line byte_position tab_size window;\n";
  27.       
  28.     j = ReadInfo("buffers", id);
  29.  
  30.     tal = ReadInfo("window_width", id);
  31.     outfile = joinstr(outfile, itoa(tal), " ");
  32.     tal = ReadInfo("window_height", id);
  33.     outfile = joinstr(outfile, itoa(tal), " ");
  34.     tal = ReadInfo("window_xpos", id);
  35.     outfile = joinstr(outfile, itoa(tal), " ");
  36.     tal = ReadInfo("window_ypos", id);
  37.     outfile = joinstr(outfile, itoa(tal), " ");
  38.     tal = ReadInfo("window", id);
  39.     outfile = joinstr(outfile, itoa(tal), " ;\n");
  40.  
  41.     for (i=0; i<j; i++) {
  42.       if (ReadInfo("type", id)&1) {
  43.         tmp = ReadInfo("full_file_name", id);
  44.         outfile = joinstr(outfile, "\"", tmp, "\"", " ");
  45.         tal = ReadInfo("line", id);
  46.         outfile = joinstr(outfile, itoa(tal), " ");
  47.         tal = ReadInfo("byte_position", id);
  48.         outfile = joinstr(outfile, itoa(tal), " ");
  49.         tal = ReadInfo("tab_size", id);
  50.         outfile = joinstr(outfile, itoa(tal), " ;\n");
  51.       }
  52.       id = NextBuffer(id);
  53.     }
  54.     if (SaveString(projectname, outfile))
  55.       Request("Error writing project file!", "Error message", "OK");
  56.   } else
  57.     ReturnStatus(GetReturnMsg(GetErrNo()));
  58. }
  59.  
  60.  
  61. /*
  62.  * LoadProject - Loads a project file and open buffers
  63.  *
  64.  * Written by Mathias Axelsson (c) 940715
  65.  *
  66.  * Loads the seleted project file and sets the window width, height
  67.  * x and y position. Then it opens all the files and sets line, byte
  68.  * position and tab size.
  69.  *
  70.  */
  71.  
  72. void LoadProject(void)
  73. {
  74.   int        id, i, j, first=1, x, y, w, h, win;
  75.   string    infile, tmp;
  76.       
  77.   string    projectname;
  78.  
  79.   projectname=PromptFile("FrexxEd:Projects/", "Load project:", "#?.prj");
  80.  
  81.   if (strlen(projectname)) {
  82.     infile = LoadString(projectname);
  83.     if (strlen(infile)) {
  84.       if (strlen(infile) == 0) {
  85.         Request("Error reading project file!", "Error message", "OK");
  86.         return;
  87.       }
  88.           
  89.       if (strncmp(infile, "#", 1)) {
  90.         Request("This is not a project file!", "Error message", "OK");
  91.         return;
  92.       }
  93.           
  94.       i = strstr(infile, ";");
  95.       if (i < 0)
  96.         return;
  97.           
  98.       infile = substr(infile, i+2, 10000);
  99.           
  100.       j = strstr(infile, " ");
  101.       tmp = substr(infile, 0, j);
  102.       infile = substr(infile, j+1, 10000);
  103.       w = atoi(tmp);
  104.       
  105.       j = strstr(infile, " ");
  106.       tmp = substr(infile, 0, j);
  107.       infile = substr(infile, j+1, 10000);
  108.       h = atoi(tmp);
  109.       
  110.       j = strstr(infile, " ");
  111.       tmp = substr(infile, 0, j);
  112.       infile = substr(infile, j+1, 10000);
  113.       x = atoi(tmp);
  114.       
  115.       j = strstr(infile, " ");
  116.       tmp = substr(infile, 0, j);
  117.       infile = substr(infile, j+1, 10000);
  118.       y = atoi(tmp);
  119.  
  120.       j = strstr(infile, " ");
  121.       tmp = substr(infile, 0, j);
  122.       infile = substr(infile, j+3, 10000);
  123.       win = atoi(tmp);
  124.       
  125.       SetInfo(id, "window_width", w, "window_height", h, "window_xpos", x, "window_ypos", y, "window", win);
  126.       
  127.       for (;;) {
  128.         if (strlen(infile) == 0)
  129.             break;
  130.         
  131.         infile = substr(infile, 1, 1000);
  132.         j = strstr(infile, "\"");
  133.         tmp = substr(infile, 0, j);
  134.         infile = substr(infile, j+2, 10000);
  135.         
  136.         if (first) {
  137.           id = GetBufferID();
  138.             
  139.           if (strlen(ReadInfo("file_name", id)) != 0 ||
  140.                  ReadInfo("changes", id) != 0) {
  141.             id = New();
  142.             if (!id)  {
  143.               Request("Can't create new buffer", "Error message", "OK");
  144.               return;
  145.             }
  146.           }
  147.             
  148.           first = 0;
  149.         } else {
  150.           id = New();
  151.           if (!id) {
  152.             Request("Can't create new buffer", "Error message", "OK");
  153.             return;
  154.           }
  155.         }
  156.         
  157.         CurrentBuffer(id);
  158.         if (!Load(tmp)) {
  159.           Request("Error loading file!", "Error message", "OK");
  160.           return;
  161.         }
  162.         
  163.         j = strstr(infile, " ");
  164.         tmp = substr(infile, 0, j);
  165.         infile = substr(infile, j+1, 10000);
  166.         
  167.         y = atoi(tmp);
  168.         
  169.         j = strstr(infile, " ");
  170.         tmp = substr(infile, 0, j);
  171.         infile = substr(infile, j+1, 10000);
  172.         
  173.         x = atoi(tmp);
  174.         
  175.         GotoLine(y, x);
  176.         
  177.         j = strstr(infile, " ");
  178.         tmp = substr(infile, 0, j);
  179.         infile = substr(infile, j+1, 10000);
  180.         
  181.         SetInfo(id, "tab_size", atoi(tmp));
  182.         
  183.         j = strstr(infile, ";");
  184.         infile = substr(infile, j+2, 10000);
  185.       }
  186.     }
  187.   }
  188. }
  189.