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