compiler/ide: Various tweaks to buffer sizes for holding command arguments (Buffer...
[sdk] / ide / src / project / Workspace.ec
index a534a5f..49d08aa 100644 (file)
@@ -2,7 +2,7 @@ import "ide"
 
 //bool eString_PathInsideOf(char * path, char * of);
 
-static void ParseListValue(List<String> list, char * equal)
+/*static void ParseListValue(List<String> list, char * equal)
 {
    char * start, * comma;
    char * string;
@@ -21,7 +21,7 @@ static void ParseListValue(List<String> list, char * equal)
       start = comma;
    }
    delete string;
-}
+}*/
 
 enum OpenedFileState { unknown, opened, closed };
 
@@ -74,6 +74,10 @@ class OpenedFileInfo
          } 
       }
    }
+   ~OpenedFileInfo()
+   {
+      delete path;
+   }
 };
 
 class Workspace
@@ -244,7 +248,23 @@ public:
             }
          }
          
+         file.Printf("\n   Execution Data\n");
+         if(commandLineArgs && commandLineArgs[0])
+         {
+            file.Printf("\n      Command Line Arguments = ");
+            file.Puts(commandLineArgs);
+            file.Printf("\n");
+         }
+
+         if(environmentVars.count)
+         {
+            file.Printf("\n      Environment Variables\n\n");
+            for(v : environmentVars)
+               file.Printf("       ~ %s = %s\n", v.name, v.string);
+         }
+
          file.Printf("\n   Debugger Data\n");
+         // This really belonged in Execution Data...
          if(debugDir && debugDir[0])
             file.Printf("\n      Debug Working Directory = %s\n", debugDir);
          if(sourceDirs.count)
@@ -585,6 +605,19 @@ public:
                   project = p;
                   break;
                }
+               // Handle symbol loader modules:
+               {
+                  char moduleName[MAX_FILENAME];
+                  char * sl;
+                  GetLastDirectory(bp.absoluteFilePath, moduleName);
+                  // Tweak for automatically resolving symbol loader modules
+                  sl = strstr(moduleName, ".main.ec");
+                  if(sl && (*sl = 0, !strcmpi(moduleName, p.name)))
+                  {
+                     project = p;
+                     break;
+                  }
+               }
             }
             if(!project)
             {
@@ -638,6 +671,7 @@ public:
 
    ~Workspace()
    {
+      Save();
       timer.Stop();
 
       sourceDirs.Free();
@@ -701,6 +735,18 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                      bp.condition = wh;
                   }
                }
+               else if(!strcmpi(section, "Execution Data") && !strcmpi(subSection, "Environment Variables"))
+               {
+                  String value = strchr(equal, '=');
+                  if(value)
+                  {
+                     *value = 0;
+                     value++;
+                     TrimRSpaces(equal, equal);
+                     TrimLSpaces(value, value);
+                     workspace.environmentVars.Add({ equal, value });
+                  }
+               }
             }
             else if(buffer[0] == '*')
             {
@@ -857,7 +903,10 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                   PathCatSlash(projectFilePath, equal);
                   newProject = LoadProject(projectFilePath);
                   if(newProject)
+                  {
                      workspace.projects.Add(newProject);
+                     newProject.StartMonitoring();
+                  }
                   else if(workspace.projects.count == 0)
                   {
                      delete workspace;
@@ -889,6 +938,8 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                strcpy(subSection, buffer);
             else if(!strcmpi(buffer, "Watches"))
                strcpy(subSection, buffer);
+            else if(!strcmpi(buffer, "Environment Variables"))
+               strcpy(subSection, buffer);
             else if(!strcmpi(buffer, "Opened Files"))
                strcpy(section, buffer);
             else if(!strcmpi(buffer, ""))      // | These two lines were commented out
@@ -922,6 +973,13 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                      TrimLSpaces(equal, equal);
                      if(!strcmpi(buffer, "Command Line Arguments"))
                         workspace.commandLineArgs = equal;
+
+                     if(!strcmpi(buffer, "Environment Variables"))
+                     {
+                        delete workspace.environmentVars;
+                        workspace.environmentVars = { };
+                     }
+
                   }
                   else if(!strcmpi(section, "Debugger Data"))
                   {
@@ -1055,12 +1113,13 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
             }
             if(project)
             {
+               project.StartMonitoring();
                workspace.projects.Add(project);
                workspace.name = CopyString(project.name);
             }
             else
             {
-               MessageBox { type = ok, master = ide, contents = "Workspace load file failed", text = "Workspace Load File Error" }.Modal();
+               MessageBox { type = ok, master = ide, contents = $"Workspace load file failed", text = $"Workspace Load File Error" }.Modal();
                delete workspace;
                return null;
             }
@@ -1070,11 +1129,11 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
          {
             int c = 0;
             char s[2] = "";
-            char files[MAX_LOCATION * 16] = "\n";
+            String files = new char[MAX_LOCATION * 16];
             char title[512];
-            char msg[MAX_LOCATION * 16 + 2048];
-
+            String msg = new char[MAX_LOCATION * 16 + 2048];
             NamedItem item;
+            strcpy(files,"\n");
 
             item = openedFilesNotFound.first;
             if(item.next)
@@ -1092,10 +1151,13 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                strcat(files, item.name);
             }
 
-            sprintf(title, "File%s not found", s);
-            sprintf(msg, "The following file%s could not be re-opened.%s", s, files);
+            sprintf(title, $"File%s not found", s);
+            sprintf(msg, $"The following file%s could not be re-opened.%s", s, files);
             
             MessageBox { type = ok, master = ide, contents = msg, text = title }.Modal();
+
+            delete files;
+            delete msg;
          }
          openedFilesNotFound.Free(OldLink::Free);
       }
@@ -1115,6 +1177,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
 
       if(newProject)
       {
+         newProject.StartMonitoring();
          workspace = Workspace { workspaceFile = filePath };
 
          workspace.projects.Add(newProject);