Author Topic: customizing save command  (Read 8754 times)

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 285
Re: customizing save command
« Reply #15 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



hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 285
Re: customizing save command
« Reply #16 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

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #17 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.

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 285
Re: customizing save command
« Reply #18 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

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #19 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

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 285
Re: customizing save command
« Reply #20 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

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #21 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);

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 285
Re: customizing save command
« Reply #22 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

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #23 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.

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 285
Re: customizing save command
« Reply #24 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
« Last Edit: July 18, 2014, 08:53:53 am by hs2 »

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #25 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";


vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #26 on: July 18, 2014, 10:06:02 am »
i am not able to find fileseperator like "/", Do we have anything for "/"

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #27 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.

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 285
Re: customizing save command
« Reply #28 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

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #29 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