Author Topic: How to add support for other Workspaces  (Read 12366 times)

Gary

  • Community Member
  • Posts: 43
  • Hero Points: 5
How to add support for other Workspaces
« on: June 23, 2006, 07:50:37 pm »
This Topic is deprecated

According to SlickCMacroBestPractices.pdf modifying system macros is not recommended


Modifying macros that ship with SlickEdit
Don't do it! Take your hands away from the keyboard. Unless you have an OEM support contract with SlickEdit Inc., and sometimes not even then, you should not be modifying system macros...ever. Feel free to use snippets from them all you like in your own macros, but don't modify the ones we ship.
If you modify a system macro, you are guaranteeing that:
   • The next patch or upgrade you do willwipe out your changes
   • Support will not be able to help you



To import Keil uVision workspaces please see http://community.slickedit.com/index.php?topic=2382.0




Since I am working with an IDE which is not yet supported by SlickEdit I have investigated some time to get rudimentary support for these project files and want to share my knowledge with other people who probably want to add support for other IDEs.

This HowTo is about support for Keil uVision2 project files but can be adapted to any other project file with a similar structure. Currently it is possible to open the project file with SlickEdit - the source files are automatically grouped using SlickEdit's "Package View".

At the moment I am sure that some modifications are unnecessary, quick and dirty or erroneous but I will try to improve this HowTo as soon as I have new information.

1. Let's take a look at a Keil project file 'demo.uv2'...

... so the .uv2 project files are simple text files starting with this two ### lines followed by a target definition section, followed by a group definition section, followed by a section containing the project's sources which are .c and and .a51 (8051 Assembly).

Code: [Select]
### uVision2 Project, (C) Keil Software
### Do not modify !

Target (demo), 0x0000 // Tools: 'MCS-51'

Group (C Sources)
Group (A51 Sources)

File 1,7,<.\src\c\foo.c><foo.c> 0x0
File 2,2,<.\src\a51\foo.a51><foo.a51> 0x0
   ...


2. Modifications in the file 'slick.sh'

In this file we have to:

- add a define for the project file extension (.uv2)
- add a define for the vendor name

Code: [Select]
#define KEIL_PROJECT_EXT '.uv2'
#define KEIL_VENDOR_NAME 'keil uvision2'



3. Modifications in the file 'wkspace.e'
Here we have to do the most work...


3.1 Modifications in the 'VendorNameTable' array
Here we have to make the assignment of our project file's extension to the vendor name by adding a line

Code: [Select]
KEIL_PROJECT_EXT                    => KEIL_VENDOR_NAME,


3.2 Modifictions in the 'workspace_open' function

3.2.1 Adapt the 'format_list' string assignment
Insert your project file's extension in here - in my case the string would now look like this:

Code: [Select]
format_list='Workspace Files(*'WORKSPACE_FILE_EXT';*'VISUAL_STUDIO_SOLUTION_EXT';*'VCPP_PROJECT_WORKSPACE_EXT';
                             *'VCPP_EMBEDDED_PROJECT_WORKSPACE_EXT';*'TORNADO_WORKSPACE_EXT';*'JBUILDER_PROJECT_EXT';
                             *'MACROMEDIA_FLASH_PROJECT_EXT'),SlickEdit Workspace Files(*'WORKSPACE_FILE_EXT'),
             SlickEdit Project Files(*'PRJ_FILE_EXT'),
             Visual C++ Workspace Files(*'VCPP_PROJECT_WORKSPACE_EXT'),
             Visual C++ Embedded Workspace Files(*'VCPP_EMBEDDED_PROJECT_WORKSPACE_EXT'),
             Tornado Workspace Files(*'TORNADO_WORKSPACE_EXT'),
             JBuilder Project Files(*'JBUILDER_PROJECT_EXT'),
             Flash Project Files(*'MACROMEDIA_FLASH_PROJECT_EXT'),
             Keil Project Files(*'KEIL_PROJECT_EXT'),
             All Files('ALLFILES_RE')';

3.2.2 Perform the workspace association
There is a code block...

Code: [Select]
      } else if (file_eq('.'get_extension(WorkspaceFilename),XCODE_PROJECT_EXT)) {
         status=_WorkspaceAssociate(WorkspaceFilename);
         if (status) {
            return(status);
         }
      }

after this block add another >else if< construct with your workspace
Code: [Select]
      } else if (file_eq('.'get_extension(WorkspaceFilename),KEIL_PROJECT_EXT)) {
         status=_WorkspaceAssociate(WorkspaceFilename);
         if (status) {
            return(status);
         }
      }



3.3. Add a workspace_open_... function
The next step is to add a custom workspace_open_... function - I have added it after the 'workspace_open_xcode' function which I have used as template.

Code: [Select]
_command int workspace_open_keiluv2(_str workspaceFilename = "") name_info(FILE_ARG'*,')
{
   _macro_delete_line();

   // pass the call
   return workspace_open_other(workspaceFilename, "Open Keil Project",
                               "Keil Project Files(*"KEIL_PROJECT_EXT"),All Files("ALLFILES_RE")");

}


3.4. Modifications in the '_getAssociatedProjectConfigs' function

3.4.1. Set the makefiletype
There is a code block

Code: [Select]
      }else if (file_eq(ext,XCODE_PROJECT_EXT)) {
         makefiletype = XCODE_VENDOR_NAME;

append a block for your project type

Code: [Select]
      } else if (file_eq(ext,KEIL_PROJECT_EXT)) {
        makefiletype = KEIL_VENDOR_NAME;

3.4.2. Get project configuration
This functionality does not work yet but I already have the changes in here...

After the block

Code: [Select]
   } else if (makefiletype==XCODE_VENDOR_NAME) {
      return _xcode_get_configs(associateMakefile,configList);
add
Code: [Select]
   } else if (makefiletype==KEIL_VENDOR_NAME) {
      return _keil_get_configs(associateMakefile,configList);

3.5 Modifications in the 'GetCompilerPackage' function
This functionality is also not supported yet but I have done some preparations in here...

after block
Code: [Select]
   case XCODE_VENDOR_NAME:
      return "Apple Xcode";
add
Code: [Select]
   case KEIL_VENDOR_NAME:
      return "Keil uVision";

3.6. Modifications in the '_WorkspaceAssociate' function

3.6.1. Set WorkspaceType...
After

Code: [Select]
   } else if (_IsXcodeProjectFilename(VendorWorkspaceName)) {
      WorkspaceType=VendorNameTable:[XCODE_PROJECT_EXT];
add
Code: [Select]
   } else if (_IsKeilProjectFilename(VendorWorkspaceName)) {
      WorkspaceType=VendorNameTable:[KEIL_PROJECT_EXT];

3.6.2. Set Compiler...
After
Code: [Select]
      }else if (WorkspaceType == XCODE_VENDOR_NAME) {
         Compiler=GetCompilerPackage(WorkspaceType);
add
Code: [Select]
      }else if (WorkspaceType == KEIL_VENDOR_NAME) {
         Compiler=GetCompilerPackage(WorkspaceType);

3.6.3. Extend the If clause

Code: [Select]
      if (_IsVisualStudioProjectFilename(CurFilename) ||
          file_eq('.'get_extension(CurFilename),VCPP_PROJECT_FILE_EXT) ||
          file_eq('.'get_extension(CurFilename),VCPP_EMBEDDED_PROJECT_FILE_EXT) ||
          file_eq('.'get_extension(CurFilename),TORNADO_PROJECT_EXT) ||
          file_eq('.'get_extension(CurFilename),JBUILDER_PROJECT_EXT) ||
          file_eq('.'get_extension(CurFilename),XCODE_PROJECT_EXT)||
          file_eq('.'get_extension(CurFilename),MACROMEDIA_FLASH_PROJECT_EXT)) {

by an entry for your project file

Code: [Select]
         file_eq('.'get_extension(CurFilename),KEIL_PROJECT_EXT)

3.6.4. Apply the XCODE hack for our project file
After

Code: [Select]
         if (file_eq('.'get_extension(CurFilename),XCODE_PROJECT_EXT)) {
            _xcode_get_configs(absolute(ProjectNames[i],WorkspacePath),configList);
add an else tree
Code: [Select]
         } else if (file_eq('.'get_extension(CurFilename),KEIL_PROJECT_EXT)) {
            _keil_get_configs(absolute(ProjectNames[i],WorkspacePath),configList);
       

3.7. Modifications in the 'GetFilenamesFromVendorWorkspaceFile' function

After

Code: [Select]
   case XCODE_VENDOR_NAME:
      ret_value=_xcode_get_target_names(VendorWorkspaceFilename,ProjectNames,VendorProjectNames);
      break;

add a case for our workspace

Code: [Select]
   case KEIL_VENDOR_NAME:
      ret_value=_keil_get_target_names(VendorWorkspaceFilename,ProjectNames,VendorProjectNames);
      break;

3.8. COMPILE THE FILE !

4. Modifications in the file 'projutil.e'

4.1. Add a function
Code: [Select]
boolean _IsKeilProjectFilename(_str filename)
{
   return(file_eq('.'get_extension(filename),KEIL_PROJECT_EXT));
}

4.2. COMPILE THE FILE !

5. Changes in the file 'project.e'

5.1. Associate MakefileType

After the code block

Code: [Select]
        if (AssociatedMakefileType==XCODE_VENDOR_NAME) {
           // Xcode workspaces don't have project files, so some trickery is necessary
           // to prevent having modify a whole lot of code
           _ProjectSet_AssociatedFile(project_handle,strip_filename(_xmlcfg_get_filename(project_handle),'P'));
        }
add
Code: [Select]
        if (AssociatedMakefileType==KEIL_VENDOR_NAME) {
           // KEIL workspaces don't have project files, so some trickery is necessary
           // to prevent having modify a whole lot of code
           //
           _ProjectSet_AssociatedFile(project_handle,strip_filename(_xmlcfg_get_filename(project_handle),'P'));
        }

5.2. COMPILE THE FILE !

6. Changes to the 'makefile.e' file

6.1. Add an entry to IniFileInfo
I assume VSearch is used to find the location in the project to speed up the search for source file entries.
SourceLine is a regular expression which identifies a source file entry - the path and the source file has to be
regex tagged as group 0.

Code: [Select]
    KEIL_VENDOR_NAME=>{
       "VSearch"=>'### uVision2 Project, (C) Keil Software',
       "VBefore"=>2,
       "VFileExt"=>'uv2',
       "SourceLine"=>'^File:b:n,:n,<{:p}><:p>:b0x:h:b*$',
       "SourceList"=>'',
       "SourceListBegin"=>'',
       "SourceListEnd"=>'',
       "DepListBegin"=>'',
       "DepListEnd"=>'',
       "VariableStart"=>'',
       "VariableEnd"=>'',
       "ContinuationChar"=>'',
    },

6.2. Changes to the 'GetFileListFromMakefile' function
This file extracts the source files from the custom project file and adds it to the SlickEdit workspace. Anyway
I assume the changes I have made here are quick and dirty and have not much to do with the original indention of this funciton.

So here we go - the code just corrects the MakefileName which was not set correctly at another position.

So after the code block
Code: [Select]
   } else if(Type==XCODE_VENDOR_NAME) {
      // Gets files from a Xcode file
      if (listboxFormat) {
         get_window_id(orig_view_id);
         activate_window(FileListViewId);
         int last_line=p_line;
         activate_window(orig_view_id);
         _xcode_get_file_list(MakefileName,FileListViewId,ConvertToAbsolute);
         activate_window(FileListViewId);
         p_line=last_line;_end_line();
         search('^','R@',' ');
         activate_window(orig_view_id);
      } else {
         _xcode_get_file_list(MakefileName,FileListViewId,ConvertToAbsolute);
      }
      return(0);
   }
add an else if clause
Code: [Select]
else if(Type==KEIL_VENDOR_NAME) {
      MakefileName = strip_filename(MakefileName,'PE') KEIL_PROJECT_EXT;
   }

6.3. COMPILE THE FILE !

7. Create a custom file for our project file support 'keiluv2.e'

Code: [Select]

///////////////////////////////////////////////////////////////////////////////

#pragma option(strict,on)

#include "slick.sh"
#include "cbrowser.sh"


/**
 * holds the whole project file
 */
static typeless keil_idHash;
/**
 * pointer to keil_idHash:['objects']
 */
static typeless *keil_objects=0;
/**
 * the name of the file that is loaded in keil_idHash and
 * keil_objects
 */
/**
 * the name of the file that is loaded in keil_idHash and keil_objects
 */
static _str keil_project_file='';
/**
 * the base directory for files with relative paths
 */
static _str keil_project_path='';


/**
 * Extract Keil target names - currently just one (the first)
 * target is handled.
 *
 * @param VendorWorkspaceFilename
 * @param ProjectNames
 * @param VendorProjectNames
 *
 * @return int
 */
int _keil_get_target_names(_str VendorWorkspaceFilename, _str (&ProjectNames)[],_str (&VendorProjectNames)[])
{
   _str projectfile;
   _str dummy;

   keil_split_target_name(VendorWorkspaceFilename,projectfile,dummy);

   //try to loacate the 'Target' entry - tag target name as $0
   if (search('Target:b\({([0-9A-Za-z._ ()]#)}\)','R') != 0) {
      return 1;
   }

   _str targets = get_text(match_length('0'),match_length('S0'));

   _str vpjName = targets;
   _str vpjFullName = targets;

   _str target_name=targets;

   if (target_name:!='') {

      vpjName=VSEProjectFilename(target_name);
      ProjectNames[ProjectNames._length()]=vpjName;

      // since the targets/projects don't exist in their own files,
      // point them all at the vpj
      vpjFullName=strip_filename(VendorWorkspaceFilename,'N'):+vpjName;

      // to make sure that everything goes smoothly, create a dummy file if
      // it hasn't been created yet
      if (file_exists(vpjFullName)) {
         VendorProjectNames[VendorProjectNames._length()]=vpjFullName;
      } else {

         // wild crazy stuff here
         // temporiarly set the Vendor Project file to the keil project file
         // while the vpj file is being created, the associated file will be
         // changed to be the vpj, but for now, a real file must be used
         VendorProjectNames[0]=strip_filename(VendorWorkspaceFilename,'PE') ".uv2";
      }
   }

   vpjName=VendorProjectNames[0];
   ProjectNames[0]=strip_filename(VendorProjectNames[0], 'PE') ".vpj";


   return 0;
}

int _keil_get_configs(_str VendorWorkspaceFilename, ProjectConfig (&configList)[])
{
   _str projectfile;
   _str target_name;

   if (keil_split_target_name(VendorWorkspaceFilename,projectfile,target_name)) {
      return -1;
   }

   int status=keil_maybe_open_project(projectfile);

   if (status) {
      return status;
   }

   if (file_exists(VendorWorkspaceFilename)) {
      _ProjectSet_WorkingDir(_ProjectHandle(VendorWorkspaceFilename),keil_project_path);
   }

   return 0;
}

/**
 *
 * @param VendorWorkspaceFilename
 * @param projectfile
 * @param target
 *
 * @return boolean
 */
static boolean keil_split_target_name(_str VendorWorkspaceFilename, _str & projectfile, _str & target)
{
   projectfile=strip_filename(VendorWorkspaceFilename,'P');
   target=strip_filename(VendorWorkspaceFilename,'PE');
   target=maybe_quote_filename(target);

   return true; //$$GN: I'm not sure what the result shall be but returning true seems to be fine for now
}


/**
 * Opens an keil project file if it is not already open and sets
 * the following global variables:
 * <ol>
 *    <li>keil_idHash</li>
 *    <li>keil_objects</li>
 *    <li>keil_project_file</li>
 *    <li>keil_project_path</li>
 * </ol>
 *
 * @param filename the name of the file to open.  This should be the
 * project.pbxproj and not the .keil directory
 *
 * @return zero on success
 */
static int keil_maybe_open_project(_str filename)
{
   if (file_eq(filename,keil_project_file)) {
      return 0;
   }

   keil_close_project();

   keil_project_file=filename;

   // first get rid of the actual project file name
   keil_project_path=strip_filename(keil_project_file,'N');

   // now get rid of the '.keil' file/directory name
   if (last_char(keil_project_path):==FILESEP) {
      keil_project_path=substr(keil_project_path,1,length(keil_project_path)-1);
   }
   keil_project_path=strip_filename(keil_project_path,'N');

   int temp_view_id;
   int orig_view_id;


   int status=_open_temp_view(filename,temp_view_id,orig_view_id);

   if (status) {
      keil_project_file='';
      return 1;
   }

   top();
   up();

   activate_window(orig_view_id);
   _delete_temp_view(temp_view_id);

   return 0;
}

static void keil_close_project()
{
   keil_idHash._makeempty();
   keil_objects=0;
   keil_project_file='';
   keil_project_path='';
}

7.1. COMPILE THE FILE !

8. Create a raw template for a SlickEdit project file in 'prjtemplates.vpt'
Code: [Select]
<Template
Name="Keil uVision"
ShowOnMenu="0">
<Config Name="Release"
DebugCallbackName="gdb"
Type="gnuc">
<Includes>
<Include Dir="%(INCLUDE)"/>
</Includes>
<Menu>
<Target
Name="Build"
MenuCaption="&amp;Build"
CaptureOutputWith="ProcessBuffer"
SaveOption="SaveCurrent"
RunFromDir="%rw">
<Exec CmdLine='j:\uv3\uv3 "%f"'/>
</Target>
<Target
Name="Compile"
MenuCaption="&amp;Compile"
CaptureOutputWith="ProcessBuffer"
SaveOption="SaveCurrent"
RunFromDir="%rw">
<Exec CmdLine='cx51 "%f"'/>
</Target>
</Menu>
</Config>
        <Files AutoFolders="PackageView">
        </Files>
</Template>

9. Add the new feature to the [Project] menu

9.1. Go to [Macro][Menus...] and open '_mdi_menu'

9.2. Select the {&Project}{Open O&ther Workspace} and press the [Insert] button

9.2.1. Set the menu Caption 'Keil uVision2 Project...'

9.2.2. Set Command 'workspace_open_keiluv2'



Huch - finished! Now I am looking forward to get some feedback and probably also improvements  ;)



Gary
« Last Edit: November 27, 2007, 10:52:26 am by Gary »

zf8848

  • New Community Member
  • Posts: 1
  • Hero Points: 0
Re: How to add support for other Workspaces
« Reply #1 on: October 14, 2006, 02:32:17 pm »
Thanks,but had error!
===============
 Stack trace written to file: D:\DOCUME~1\DEVELO~1\LOCALS~1\Temp\vsstack
 Invalid XMLCFG node index
 0x101450f0 -xmlcfg-copy(4,0,3,-1,2)   p_window_id: 5   p_object: OI_FORM   p_name:
projconv.ex 26027 _ProjectCreateFromTemplate(E:\zf.arm\test\RTL_LPC2142\RTL2142.vpj,Keil uVision,,1,
   5:   0
   p_window_id: 5
   p_object: OI_FORM
   p_name:
project.ex 1480 workspace_new_project2(E:\zf.arm\test\RTL_LPC2142\RTL2142.vpj,Keil uVision,RTL2142,
   4:   E:\zf.arm\test\RTL_LPC2142\RTL2142.Uv2
   5:   0
   6:   1
   7:   E:\zf.arm\test\RTL_LPC2142\RTL2142.uv2
   8:   keil uvision2
   9:   1
   10:   <empty>
   11:   0
   12:   0
   p_window_id: 5
   p_object: OI_FORM
   p_name:
wkspace.ex 26013 _WorkspaceAssociate(E:\zf.arm\test\RTL_LPC2142\RTL2142.Uv2,0)
   p_window_id: 5
   p_object: OI_FORM
   p_name:
wkspace.ex 4197 workspace_open(E:\zf.arm\test\RTL_LPC2142\RTL2142.Uv2,,,1,1)
   p_window_id: 5
   p_object: OI_FORM
   p_name:
wkspace.ex 5203 static(E:\zf.arm\test\RTL_LPC2142\RTL2142.Uv2,Open Keil Project,
   3:   Keil Project Files(*.uv2),All Files(*.*)
   p_window_id: 5
   p_object: OI_FORM
   p_name:
wkspace.ex 5265 workspace_open_keiluv2()   p_window_id: 5   p_object: OI_FORM   p_name:

Gary

  • Community Member
  • Posts: 43
  • Hero Points: 5
Re: How to add support for other Workspaces
« Reply #2 on: October 18, 2006, 07:54:29 pm »
Thanks,but had error!
===============

hi,

just tried my description on a plain installation - for me it worked. are you sure you have made the changes in prjtemplates.vpt correctly? probably i forgot to mention the file already exists (directly in the slickedit directory) and has to be modified


attached you find the affected files for v11.0.2.

hope that helps - if not i will try to find the issue...

gary

Gary

  • Community Member
  • Posts: 43
  • Hero Points: 5
Re: How to add support for other Workspaces
« Reply #3 on: November 16, 2006, 02:42:59 pm »
@slickedit team: as my approach is quite quick and dirty at the moment i would like to improve a few things - probably somebody can give me some useful hints so that i don't have to do reverse engineering.

The first thing I want to improve is:

    I1) In the <Projects> window am using auto folders - here I would prefer to import the Groups (folders) from the .uv2 file and use custom folders instead (a sample project including .uv2 file is attached) but where is the right position to hook the functionality to extract folder names and assign the contents into?


Thanks,
Gary
   
« Last Edit: November 16, 2006, 05:53:38 pm by Gary »

Gary

  • Community Member
  • Posts: 43
  • Hero Points: 5
Re: How to add support for other Workspaces
« Reply #4 on: November 27, 2007, 10:49:15 am »
According to SlickCMacroBestPractices.pdf modifying system macros is not recommended

Modifying macros that ship with SlickEdit
Don't do it! Take your hands away from the keyboard. Unless you have an OEM support contract with SlickEdit Inc., and sometimes not even then, you should not be modifying system macros...ever. Feel free to use snippets from them all you like in your own macros, but don't modify the ones we ship.
If you modify a system macro, you are guaranteeing that:
   • The next patch or upgrade you do willwipe out your changes
   • Support will not be able to help you


To import Keil uVision workspaces please see http://community.slickedit.com/index.php?topic=2382.0

liyong2000

  • New Community Member
  • Posts: 1
  • Hero Points: 0
Re: How to add support for other Workspaces
« Reply #5 on: December 01, 2009, 01:22:29 am »
Sorry, but  How to compile the modify micro ?