SlickEdit Community

SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: vineetvijay12 on July 16, 2014, 09:14:56 AM

Title: customizing save command
Post by: vineetvijay12 on July 16, 2014, 09:14:56 AM
I have a requirement customizing save command so i can copy file to shared location once i save the file using save button in slickedit..
Quick help will be highly appreciated.

Thanks
Vineet

Title: Re: customizing save command
Post by: Graeme on July 16, 2014, 10:16:47 AM
Copy the code below to a file of your own called mysave.e or something  - in your slick configuration folder.  I added the following lines to the official save_file function.

   int result = copy_file(filename, 'H:\slick-backups\' :+ strip_filename(filename,'P'));
   if (result != 0) {
      _message_box("slick backup main copy failed " :+ (_str)(result));
   }

Modify the location you want the file to be copied to.  If you want to replicate the directory structure on the server according to where the file comes from then you need to do a bit more work (using make_path).  Let me know if you need that.  To load the code, open the mysave.e file in slick and use the load module command on the macro menu.

Code: [Select]
#include "slick.sh"

#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)
#import "tagform.e"

/**
 * Writes current buffer to filename.  This function is a hook function
 * that the user may replace.  Options allowed by <b>_save_file</b>
 * built-in may be specified.
 * @param filename parameter should not contain options.
 *
 * @appliesTo Edit_Window
 *
 * @categories File_Functions
 *
 */
_str save_file(_str filename,_str options)
{
#if 0
   int renumber_flags=numbering_options();
   if (renumber_flags&VSRENUMBER_AUTO) {
      if (renumber_flags&VSRENUMBER_COBOL) {
         renumber_lines(1,6,'0',false,true);
      }
      if (renumber_flags&VSRENUMBER_STD) {
         renumber_lines(73,80,'0',false,true);
      }
   }
#endif
   typeless status=_save_file(options " "maybe_quote_filename(filename));
   if (!status && file_eq(strip(filename,'B','"'),p_buf_name)) {
      //_cbsave_filewatch();
#if 1
      call_list('_cbsave_');
      //10:51am 7/3/1997
      //Dan modified for auto-tagging
      if (def_autotag_flags2&AUTOTAG_ON_SAVE) {
         //messageNwait(nls('got here'));
         TagFileOnSave();
      }
#endif
   }

   int result = copy_file(filename, 'H:\slick-backups\' :+ strip_filename(filename,'P'));

   if (result != 0) {
      _message_box("slick backup main copy failed " :+ (_str)(result));
   }

   return(status);

}

Title: Re: customizing save command
Post by: vineetvijay12 on July 16, 2014, 10:39:42 AM
yes that works with static path.
i want to get source path and create a destination path.
can you help me on this?
Title: Re: customizing save command
Post by: Graeme on July 16, 2014, 11:58:54 AM


sure.  If you have autosave enabled you'll find it uses this function, so your autosave files will get copied to the server too.

Code: [Select]
   _str pa = 'H:\slick-backup\' :+ strip_filename(filename,'DN');
   if (!path_exists(pa)) {
      int result = make_path(pa);
      if (result) {
         _message_box("slick backup make path failed : " :+ result :+ pa);
         return status;
      }
   }

   int result2 = copy_file(filename, pa :+ strip_filename(filename,'P'));

   if (result2 != 0) {
      _message_box("slick backup main copy failed " :+ (_str)(result2));
   }
Title: Re: customizing save command
Post by: vineetvijay12 on July 16, 2014, 12:14:54 PM
autosave is not enabeled, how to enable that.
even i want to make path dynamically as below, can you please help?
m:\vvijay_test_protocols_test_lbx_wtl\vv-test\makedoc, the SAVE function of SlikEdit will trigger a program to copy the file directly to \\home\vvijay\stage_area\vvijay_test_protocols_test_lbx_wtl\vv-test\makedoc
Title: Re: customizing save command
Post by: Graeme on July 16, 2014, 12:26:10 PM
Do you mean you didn't understand what to do with the extra code I posted?
I don't use Linux so I can't test your paths.
Regarding autosave, in tools -> options, type autosave in the search text box at the top left.

Code: [Select]
#include "slick.sh"

#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)
#import "tagform.e"

/**
 * Writes current buffer to filename.  This function is a hook function
 * that the user may replace.  Options allowed by <b>_save_file</b>
 * built-in may be specified.
 * @param filename parameter should not contain options.
 *
 * @appliesTo Edit_Window
 *
 * @categories File_Functions
 *
 */
_str save_file(_str filename,_str options)
{
#if 0
   int renumber_flags=numbering_options();
   if (renumber_flags&VSRENUMBER_AUTO) {
      if (renumber_flags&VSRENUMBER_COBOL) {
         renumber_lines(1,6,'0',false,true);
      }
      if (renumber_flags&VSRENUMBER_STD) {
         renumber_lines(73,80,'0',false,true);
      }
   }
#endif
   typeless status=_save_file(options " "maybe_quote_filename(filename));
   if (!status && file_eq(strip(filename,'B','"'),p_buf_name)) {
      //_cbsave_filewatch();
#if 1
      call_list('_cbsave_');
      //10:51am 7/3/1997
      //Dan modified for auto-tagging
      if (def_autotag_flags2&AUTOTAG_ON_SAVE) {
         //messageNwait(nls('got here'));
         TagFileOnSave();
      }
#endif
   }

 _str pa = '\\home\vvijay\stage_area\' :+ strip_filename(filename,'DN');
   if (!path_exists(pa)) {
      int result = make_path(pa);
      if (result) {
         _message_box("slick backup make path failed : " :+ result :+ pa);
         return status;
      }
   }

   int result2 = copy_file(filename, pa :+ strip_filename(filename,'P'));

   if (result2 != 0) {
      _message_box("slick backup main copy failed " :+ (_str)(result2));
   }

   return(status);

}

Title: Re: customizing save command
Post by: vineetvijay12 on July 16, 2014, 02:29:01 PM
almost near to get it.
I am also doing the changes for windows path
can you please help me getting path like this.

m:\vvijay_test_protocols_test_lbx_wtl \vv-test\makedoc to copy to \\home\vvijay\stage_area\vvijay_test_protocols_test_lbx_wtl\vv-test\makedoc

i want to get value vvijay from some windows variable $USER or get the value "vvijay" from vvijay_test_protocols_test_lbx_wtl assigened to a variable $USER and appned in in \home\$USER\stage_area\vvijay_test_protocols_test_lbx_wtl\vv-test\makedoc
Title: Re: customizing save command
Post by: hs2 on July 16, 2014, 10:40:07 PM
Try e.g. 'get_env("User")' to query this env.var. Probably the easiest way for now. Alt. 'parse' the given original file name to extract the ,user' relying on your fixed naming rule. IHMO it seems a bit less robust than querying the user env.var.
Good luck, HS2
Title: Re: customizing save command
Post by: hs2 on July 16, 2014, 11:45:21 PM
I'd propose to use SE callback mechanism for '_cbsave_' and to avoid patching product macro sources.
Add this e.g. to your 'vusrmacs.e' (see this (http://community.slickedit.com/index.php/topic,10050.msg42591.html#msg42591) post for some further details regarding 'vusrmacs.e'):
Code: [Select]
void _cbsave_vvijay(...)
{
   src := strip_filename(p_buf_name, 'DN');
   dst := get_env("HOME") :+ "\\stage_area" :+ src;
   // say("dst path:" dst );
   if ( !path_exists(dst) )
   {
      int err = make_path(dst);
      if (err)
      {
         _message_box("make_path '" dst "' failed - rc =" err);
         return;
      }
   }

   dst :+= strip_filename(p_buf_name, 'DP');
   // say("dst file:" dst );
   err := copy_file(p_buf_name, dst);
   if ( err )
   {
      _message_box("copy_file '" dst "' failed - rc = " err);
   }
}

I guess you're using a Unix probably Linux system. So the 'HOME' env.var should be fine, right ?
(Hint: It's a good idea to tell SE version incl. hotfix pack and OS platform when asking for assistance/support.)

However, it's an example (thanks Graeme) and as a starter.
You should add a filter for backing up the files you really want to...

Good luck, HS2
Title: Re: customizing save command
Post by: Graeme on July 17, 2014, 12:25:06 AM
I'd propose to use SE callback mechanism for '_cbsave_' and to avoid patching product macro sources.

Actually the save_file function is sanctioned as a "hook function" that can be replaced by a user
Code: [Select]
/**
 * Writes current buffer to filename.  This function is a hook function
 * that the user may replace.  Options allowed by <b>_save_file</b>
 * built-in may be specified.

but of course, the _cbsave callback is fine too.

Title: Re: customizing save command
Post by: vineetvijay12 on July 17, 2014, 08:43:38 AM
I am able to copy file but getting attached error during make_path code, can you please check.
 below is my code.
_str save_file(_str filename,_str options)
{
#if 0
   int renumber_flags=numbering_options();
   if (renumber_flags&VSRENUMBER_AUTO) {
      if (renumber_flags&VSRENUMBER_COBOL) {
         renumber_lines(1,6,'0',false,true);
      }
      if (renumber_flags&VSRENUMBER_STD) {
         renumber_lines(73,80,'0',false,true);
      }
   }
#endif
   typeless status=_save_file(options " "filename);
   if (!status && file_eq(strip(filename,'B','"'),p_buf_name)) {
   //_cbsave_filewatch();
   #if 1
      call_list('_cbsave_');
      //10:51am 7/3/1997
      //Dan modified for auto-tagging
      if (def_autotag_flags2&AUTOTAG_ON_SAVE) {
         //messageNwait(nls('got here'));
         TagFileOnSave();
      }
     #endif
   }

   src := strip_filename(p_buf_name, 'DN');
   dst := \\home-1 :+ get_env("USERNAME") :+ "\stage_area" :+ src;
    //say("dst path:" dst );
   if ( !path_exists(dst) )
   {
      int err = make_path(dst);
      if (err)
      {
         _message_box("make_path '" dst "' failed - rc =" err);
         return;
      }
   }

   dst :+= strip_filename(p_buf_name, 'DP');
   // say("dst file:" dst );
   err := copy_file(p_buf_name, dst);
   if ( err )
   {
      _message_box("copy_file '" dst "' failed - rc = " err);
   }

   }
   return(status);

}
Title: Re: customizing save command
Post by: hs2 on July 17, 2014, 08:56:25 AM
1. Which OS platform / SE version ?
2. What's the intention of this ? This doesn't seem right.
Code: [Select]
\\home-1
Try
Code: [Select]
'\\home\' :+ get_env("USERNAME")
HS2

Title: Re: customizing save command
Post by: vineetvijay12 on July 17, 2014, 09:02:42 AM
SE 2007 and 2010.
OS is windows 7
Title: Re: customizing save command
Post by: hs2 on July 17, 2014, 09:18:59 AM
Yes - I've also seen the attachment file path right now ;)
Again beware that if you're modifying an installed ie. product macro it might get overwritten e.g. when installing an SE upgrade or hotfix pack containing a fixed version of 'saveload.e'. You should either follow the advise Graeme posted before
Quote
Copy the code below to a file of your own called mysave.e or something  - in your slick configuration folder
or this this (http://community.slickedit.com/index.php/topic,10050.msg42591.html#msg42591) posting to use the default 'vusrmacs.e' user macro module.

HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 17, 2014, 09:34:55 AM
i chnaged my saveload.e to what came with installation and added new file but same error
#pragma option(strict,on)
#include 'slick.sh'

void _cbsave_vvijay(...)
{
   src := strip_filename(p_buf_name, 'DN');
   dst := '\\home-1\' :+ get_env("USERNAME") :+ "\stage_area" :+ src;
   // say("dst path:" dst );
   if ( !path_exists(dst) )
   {
      int err = make_path(dst);
      if (err)
      {
         _message_box("make_path '" dst "' failed - rc =" err);
         return;
      }
   }

   dst :+= strip_filename(p_buf_name, 'DP');
   // say("dst file:" dst );
   err := copy_file(p_buf_name, dst);
   if ( err )
   {
      _message_box("copy_file '" dst "' failed - rc = " err);
   }
}
Title: Re: customizing save command
Post by: hs2 on July 17, 2014, 10:18:22 AM
Either use (Slick-C specific) single quotes
Quote
'\\stage_area'
or escape the backslash char when using double quotes similar to other languages:
Code: [Select]
dst := '\\home-1\' :+ get_env("USERNAME") :+ "\\stage_area" :+ src;
Watch the error message in status bar when loading/compiling a macro.
When loading your originial macro SE tells you 'Illegal char' and puts the cursor at the (1st) error.
BTW: You can also uncomment the 'say' calls to get debut output in an extra window.
HS2


Title: Re: customizing save command
Post by: hs2 on July 17, 2014, 10:38:26 AM
To be complete: In case of a macro load error the last successfully loaded macro code is still in charge.
Means your last version with was invoked displaying the known error message box.
HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 17, 2014, 10:52:35 AM
now i am able to copy the file but it is going to two locations
1. \\home-1\' :+ get_env("USERNAME")
2. '\\home-1\' :+ get_env("USERNAME") :+ "\\stage_area" :+ src;

why it is getting copied to two locations.
Title: Re: customizing save command
Post by: hs2 on July 17, 2014, 10:58:11 AM
Are you really sure ? Maybe the 1st copy is an orphaned file (file timestamp ?) coming from a previously incorrect macro ? There is only 1 'copy_file' call so there can't be 2 copies I think.
Delete your backup folder and re-try save to verify.
HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 17, 2014, 11:38:03 AM
Thanks for prompting me, I uninstalled and installed slickedit , now it looks good.
I need a message_box to pop up during copy_file even though no error.

how to do that?

Thanks
Title: Re: customizing save command
Post by: hs2 on July 17, 2014, 05:11:27 PM
Quote
uninstalled and installed slickedit
I guess his cleaned up your 1st approach the modified (but incorrect) and loaded (!) save_file function.
That was the reason why you got 2 copies ;)
Re-installing SE loaded the original save_file function. Hence the user overwritable 'hook' functions are not the very best approach.

A message box is a modal dialog but I guess you wanna do sth. fancy and display kind of 'Backing up ...' window while copying to your server share..
So this is not possible by design, but you could display a status message in the status bar using 'message' function.
Get function help: put cursor at the function in your macro source file (e.g. 'message' ) and hit <F1> usually bound to the 'help' command or use 'Help>Index: message'

HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 17, 2014, 06:09:49 PM
i need only simple message_box like below with source and destination path mentioned.
_message_box("copy_file '" dst "' failed - rc = " err);
Title: Re: customizing save command
Post by: hs2 on July 17, 2014, 06:18:14 PM
Quote
i need only simple message_box like below with source and destination path mentioned.
No way - as mentioned it's a modal dialog.
Use
Code: [Select]
   message("backing up '" src "' to '" dst "' ... ");
   copy_file ....
   message("done");
and watch the status bar.

That's all what you can do now.

HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 18, 2014, 06:45:23 AM
okies,
i need to get a value from my source path which is not set in env.

i need to parse last word after _ from "vvijay_test_protocols_test_lbx_wtl "
 path is
m:\vvijay_test_protocols_test_lbx_wtl \vv-test\makedoc

how to parse it.
Title: Re: customizing save command
Post by: hs2 on July 18, 2014, 08:44:44 AM
This example extracting usr (1st part of path root) and kind of tag (last part of path root) should do:
Code: [Select]
   src := "m:\\vvijay_test_protocols_test_lbx_wtl\\vv-test\\makedoc";
   _str usr = "", tag = "";

   _str pparts[];
   split(src, FILESEP, pparts);  // split path, get root
   if (pparts._length() > 2)
   {
      _str uparts[];
      split(pparts[1], '_', uparts);   // split root, get usr (1st) and tag (last)
      if (uparts._length() > 2)
      {
         usr = uparts[0];
         tag = uparts[uparts._length() -1];
      }
   }

   if ( (usr._length() == 0) || (tag._length() == 0) )
   {
      _message_box("error: unexpected src path naming");
      return;
   }

   // ok - proceed ...
   // say( "usr: '" usr "' - tag '" tag "'");


Note that this is just 1 way of implementation. There are much more possibilities to get the same result.
Sometimes it's just a matter of taste and style ;)

Good luck, HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 18, 2014, 09:03:11 AM
i replaced src hard code path like below and getting error message.
"error: unexpected src path naming"

 src := strip_filename(p_buf_name, 'DE');
   //src := "m:\\vvijay_test_protocols_test_lbx_wtl\\vv-test\\makedoc";

Title: Re: customizing save command
Post by: vineetvijay12 on July 18, 2014, 10:06:02 AM
i am not able to find fileseperator like "/", Do we have anything for "/"
Title: Re: customizing save command
Post by: vineetvijay12 on July 18, 2014, 11:13:24 AM
i think my current file path was having space and ( , now i am able to parse the path which does not have space and special chanracter, can we escape special character by any way.
Title: Re: customizing save command
Post by: hs2 on July 18, 2014, 07:20:13 PM
Quote
i replaced src hard code path
sure ;)
Quote
i am not able to find fileseperator like "/"
there are platform dependent defines in 'slick.sh'
Code: [Select]
   #define FILESEP "\\"              /* Primary filename,directory separator */
   #define FILESEP2  "/"              /* Secondary filename,directory separator */
I've used FILESEP in the example.
Quote
i think my current file path was having space and (
Well, this always makes life harder, but it's not a big deal.

I've quickly tested this weird path hopefully similar to your use case and it works as expected ???
Code: [Select]
    src := strip_filename("m:\\vvijay_test_protocols_test_lbx_wtl\\ wvv-test ( 1 ) \\makedoc", "DE");
I've also quick-tested the _cbsave_ code with this example path
Code: [Select]
src := "A:\\a b ( 1 )\\bla.txt"Also no problem there.

So what's the problem exactly ?

You should make use of debug output with 'say()' and also message() resp. messageNwait() to track down the problem.
Also the docs (Help) are quite helpful concerning macro programming.

HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 22, 2014, 07:57:16 AM
Thanks hs2,
I got the problem.
 i need to add one more check to not to execute latter part of "_cbsave_vvijay" code if src does not contain "labx" so other path can also use slickedit.
viewtype=uparts[uparts._length() -2];

if (viewtype == "labx")
   {
if ( (usr._length() == 0) || (site._length() == 0) )
{
.
.
.
}

is this right approach?

Thanks for helping out
Title: Re: customizing save command
Post by: hs2 on July 22, 2014, 08:38:24 AM
I guess 'does (not) contain "labx"' is the filter for (not) making backups.
Seems ok as far as I can see. And your own tests will easily tell you if it's working as expected ;)
Good luck, HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 28, 2014, 07:53:12 AM
i caught up in a condition where some of the users mapped vvijay_test_protocols_test_lbx_wtl as some drive lets say k
so when i open a file in slickedit i get K:\wvv-test\makedoc not getting vvijay_test_protocols_test_lbx_wtl , is there a way i can get full path including network drive in such case.

if no way directly on lsickedit, can i run some commands to get windows registery key values.
Title: Re: customizing save command
Post by: hs2 on July 28, 2014, 09:41:31 AM
I guess they subst'd the mounted share. So you could either invoke 'subst' as shell command, redirect and parse it's output to retrieve and store (static variable) the mapping automagically or add a (static) variable and let the user enter the mapping manually.
Concerning the 1st approach you should do it (silently) on demand ie. on failure and not during each save.
The 2nd way is much simpler, of course. You could prompt the user to enter the mapping on failure.
HS2
Title: Re: customizing save command
Post by: hs2 on July 28, 2014, 09:49:29 AM
And yes - SE supports registry queries on Windows.
There are some (I think undocumented) SE functions '_ntRegQueryValue', '_ntRegFindValue', etc.
Try to lookup '_ntReg' in the SE macro sources ('<SE install dir>/macros') to find out howto use them.
Good luck, HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 28, 2014, 10:08:22 AM
i want to fetch drive letter of source path, i am using below expression to get path except drive letter
src := strip_filename(p_buf_name, 'DN');
 what expression should i use to get drive letter alone
Title: Re: customizing save command
Post by: hs2 on July 28, 2014, 10:18:04 AM
substr( p_buf_name, 1, 2 ); to get e.g. 'K:'. see the docs for 'substr' details.
HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 28, 2014, 11:36:28 AM
if i pass  static value to _ntRegQueryValue, it is working fine but it is not if i  pass some dynamic value.

Working:
src1 := _ntRegQueryValue(HKEY_CURRENT_USER, "Network\\F", "", "RemotePath");

Not working:
drivepath := "Network\\" :+ Drive;
 src1 := _ntRegQueryValue(HKEY_CURRENT_USER, "drivepath", "", "RemotePath");
Title: Re: customizing save command
Post by: hs2 on July 28, 2014, 12:18:54 PM
Don't quote your variable drivepath: "drivepath" -> drivepath
HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 28, 2014, 01:58:07 PM
i got atatched error when tried this

 if (Drive != "M")
         {
         drivepath := "Network\\" :+ Drive;
          src1 := _ntRegQueryValue(HKEY_CURRENT_USER, drivepath, "", "RemotePath")

     _str pparts1[];
     split(src1, FILESEP, pparts1);  // split path, get root
   
     if (pparts1._length() > 2)
   {
      _str uparts[];
      split(pparts1[3], '_', uparts);   // split root, get usr (1st), viewtype (2nd last) and site (last)
      if (uparts._length() > 2)
      {
         usr = uparts[0];
         site = uparts[uparts._length() -1];
         viewtype = uparts[uparts._length() -2];

      }
     }
       }
Title: Re: customizing save command
Post by: hs2 on July 28, 2014, 06:30:56 PM
@vineetvijay12: Sorry, but your report lacks the minimum level of detail needed to do anything.
Which function call / source line failed ? What's the input ?
You should post code with proper formatting. There is this cool '#' button to CODE-tag a selection (see the example below - note the very useful Select link)
Your code is incomplete and contains a syntax error.
SE tells you on loading your macro code that there is no ';' at the end of line
Code: [Select]
_ntRegQueryValue(HKEY_CURRENT_USER, drivepath, "", "RemotePath")
So maybe again you're trapped by running the previous / last successfully compiled macro causing the error b/c you ignored the compile error ?

What did you try yourself solving your own problem and what's your question where you're stuck ?
I assume you don't expect that someone else solves all your problems ;)

Good luck,
HS2
Title: Re: customizing save command
Post by: vineetvijay12 on July 28, 2014, 07:06:25 PM
Even i thought that it might be due to old macro as i am trying out something countinously.

I already tried with fresh installation.
here i am trying to acheive that if Drive is not m then get the second parameter vvijay_... from registry key.
somehow i missed semicolon while pasting the code.
so if i pass  static value to _ntRegQueryValue it is working fine but it is not if i  pass some dynamic value.

Working:
src1 := _ntRegQueryValue(HKEY_CURRENT_USER, "Network\\F", "", "RemotePath");

Not working:
drivepath := "Network\\" :+ Drive;
 src1 := _ntRegQueryValue(HKEY_CURRENT_USER, drivepath, "", "RemotePath");

here is code snip

Code: [Select]
#pragma option(strict,on)
#include 'slick.sh'

void _cbsave_vvijay  (...)
{
   src := strip_filename(p_buf_name, 'DN');
   Drive := substr(p_buf_name, 1, 1 );
   _str usr = "", site = "", viewtype = "";

      if (Drive != "M")
         {
         drivepath := "Network\\" :+ Drive;
    src1 := _ntRegQueryValue(HKEY_CURRENT_USER, drivepath, "", "RemotePath");

     _str pparts1[];
     split(src1, FILESEP, pparts1);  // split path, get root
     _message_box("pparts1 is '" pparts1[3] "'");

     if (pparts1._length() > 2)
   {
      _str uparts[];
      split(pparts1[3], '_', uparts);   // split root, get usr (1st), viewtype (2nd last) and site (last)
      if (uparts._length() > 2)
      {
         usr = uparts[0];
         site = uparts[uparts._length() -1];
         viewtype = uparts[uparts._length() -2];

      }
     }
       }

      else
      {
   _str pparts[];
   split(src, FILESEP, pparts);  // split path, get root
   if (pparts._length() > 2)
   {
      _str uparts[];
      split(pparts[1], '_', uparts);   // split root, get usr (1st), viewtype (2nd last) and site (last)
      if (uparts._length() > 2)
      {
         usr = uparts[0];
         site = uparts[uparts._length() -1];
         viewtype = uparts[uparts._length() -2];
      }
   }
      }

   if (viewtype == "labx")
   {
         message("view is a labx view, will copy file to stage area under your home directory");
       if ( (site :!= "blr") || (site :!= "wtl") )
       //if ( (usr._length() == 0) || (site._length() == 0) )
   {
      _message_box("error: unexpected src path naming");
      return;
    }

   
   dst := '\\' :+ site :+ "home-1\\" :+ "home\\" :+ get_env("USERNAME") :+ "\\stage_area" :+ src;

   if ( !path_exists(dst) )
   {
      int err = make_path(dst);
      if (err)
      {
         _message_box("make_path '" dst "' failed - rc =" err);
         return;
      }
   }

   dst :+= strip_filename(p_buf_name, 'DP');
   //message("backing up '" src "' to '" dst "' ... ");
   err := copy_file(p_buf_name, dst);
   if ( err )
   {
      _message_box("copy_file '" dst "' failed - rc = " err);
   } 
   
   } 
}
Title: Re: customizing save command
Post by: hs2 on July 28, 2014, 08:40:17 PM
So drivepath is also set to something like 'Network\\F' ?
Did you verify the contents of 'drivepath' using e.g.
Code: [Select]
say( "drivepath '" drivepath "' -> src1 '" src1 "'");
Be more careful with arrays ;)
This is safe (with _length > 3 you can access element 3):
Code: [Select]
      if ( pparts1._length() > 3 )
      {
         _message_box("pparts1 is '" pparts1[3] "'");

         _str uparts[];
         split(pparts1[3], '_', uparts);   // split root, get usr (1st), viewtype (2nd last) and site (last)
...

I can't see any problem using variable 'drivepath' set to sth. like 'Network\\F' and a literal string 'Network\\F' at the moment ...

I even tried this tiny but basically similar example accessing a registry key and it works as expected:
Code: [Select]
      drivepath := "SOFTWARE\\Microsoft\\VisualStudio\\" :+ "12.0";
      src1 := _ntRegQueryValue(HKEY_LOCAL_MACHINE, drivepath,"","InstallDir");
      say( "drivepath '" drivepath "' -> src1 '" src1 "'");

HS2
Title: Re: customizing save command
Post by: hs2 on July 28, 2014, 10:25:43 PM
Another hint especially in your case:
Since your code is involved in saving files it's a critical path also affecting compile/saving your macro file.
So better move the code out of the '_cbsave_' callback to a normal macro command like this:
Code: [Select]
_command void vijay_cb_save() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
...
}
With this you can easily develop and test the code until it's working properly without any trouble when saving files.
You can simply invoke it on SE command line after loading it (enter: vijay-cb-save) and/or bind it to a shortcut for faster testing.
When done just add/uncomment the call to it in your '_cb_save' callback and comment it before modifying the code again until it's finished.
In addition you could use:
Code: [Select]
if ( _get_extension( p_buf_name ) == 'e' ) return;to bail out as early as possible if you're compile/saving SE macro files which you don't want to backup and to skip your macro code when working with macro files.
This should help to avoid SE re-installs just to recover from a broken 'file save' macro code path.

HS2