0

I'm using Notepad++ for write my SA:MP server system, but i have a issue trying to organize my folders: I want to put my compiled files (.amx - like a resulting .exe for non-Pawn devs) in a separated folder called bin, with the same subfolder structure than the sources folder (src).

For clarify, the desired folder structure is this:

Root folder
├── src
│   ├── filterscripts
│   │   ├── file1.pwn
│   │   └── file2.pwn
│   └── gamemodes
│       └── gm_main.pwn
├── bin
│   ├── filterscripts
│   │   ├── file1.amx
│   │   └── file2.amx
│   └── gamemodes
│       └── gm_main.amx

What i want is when i compile a .pwn file, the resulting .amx should go to the equivalent original subfolder but in bin.

My current execute script is this:

NPP_SAVE
cd $(CURRENT_DIRECTORY)
"C:\Pawn\bin\samp\pawncc.exe" "$(FILE_NAME)" -; -(

Is possible to do this only using NppExec?

Vico
  • 171
  • 1
  • 13
  • 1. You dont not need to cd to `$(CURRENT_DIRECTORY)`. You are already there. 2. What is CURRENT_DIRECTORY? Is it src? I suppose it is src\filterscripts and you need to somehow get that part out from CURRENT_DIRECTORY, so that you can use `..\..\bin\MAGIC` whith `MAGIC beeing derived from CURRENT_DIRECTORY. Right? – Lars Fischer Jan 21 '17 at 12:57
  • CURRENT_DIRECTORY i think is the directory the current opened file is located. By default the pointed directory at NppExec startup is the folder where notepad++.exe is in. – Vico Jan 21 '17 at 13:01
  • And about the second question: exacly. I just need to translate `src\filterscripts` or `src\gamemodes` into `bin\filterscripts` or `bin\gamemodes`. – Vico Jan 21 '17 at 13:02
  • let me think about it a few minutes. – Lars Fischer Jan 21 '17 at 13:04
  • Please note that the tag [tag:cmd] refers to the Windows command prompt, so please correct that... – aschipfl Jan 23 '17 at 13:34
  • Corrected. Thanks for the hint @aschipfl – Vico Jan 24 '17 at 04:48

1 Answers1

0

You can use this NppExec script, to derive the needed paths and feed them into some arguments of your compiler:

NPP_SAVE
echo Sourcefile         : $(FULL_CURRENT_PATH)

// ---------------------------------------------------------------------------------
// -- use string function to get ROOT and SRC path and then BIN path:

//  set <var> ~ strrfind <s> <t> - returns the LAST position of <t> in <s>
set Pos_Root ~ strrfind $(FULL_CURRENT_PATH) \src\
//  set <var> ~ <math expression> - calculates the math expression
set Pos_Src ~ $(Pos_Root) + 4
// echo $(Pos_Src), $(Pos_Root)

//   returns the substring
set Dir_Root ~ substr 0 $(Pos_Root) $(FULL_CURRENT_PATH)
set Dir_Src ~ substr 0 $(Pos_Src) $(FULL_CURRENT_PATH)
echo Src-Directory      : $(Dir_Src)
echo Project-Directory  : $(Dir_Root)

set Dir_Bin = $(Dir_Root)\bin
echo Bin-Directory      : $(Dir_bin)

// -- Now use the previously determined substring to get the BIN path and then
// -- derive the Target path with src replace by bin 

// get the target dir:
// set <var> ~ strreplace <s> <t0> <t1> - replaces all <t0> with <t1>
set TARGET_PATH ~ strreplace $(CURRENT_DIRECTORY) $(Dir_Src) $(Dir_Bin)
echo Target-Directory   : $(TARGET_PATH)

// ----------------------------------

// use compile with $(FULL_CURRENT_PATH) and $(TARGET_PATH)
"C:\Pawn\bin\samp\pawncc.exe" $(FULL_CURRENT_PATH) whatever-output-option $(TARGET_PATH)

Notes

  • the NppExec documentation explains all the different set possibilities, check them out
  • alternatives to dynamically derive the paths would be a static definition of the paths:
    • place the "PATH settings" as static paths to ROOT, BIN, SRC, etc inside the NppExec script
    • define the paths as environment variables that you access from the NppExec script
    • a complete different approach would be to store several $(FULL_CURRENT_PATH) and do some change directories between :
      1. a cd.. to jump from src subdir to src
      2. to ROOT,
      3. to bin
      4. then do the string replacement
Lars Fischer
  • 9,135
  • 3
  • 26
  • 35
  • I've got an error: `root_folder\bin\gamemodes.p(0) : fatal error 100: cannot read from file: "root_folder\bin\gamemodes.p"` – Vico Jan 22 '17 at 16:42
  • Seems like the function ate the last two letter of the extension (should be .pwn) – Vico Jan 22 '17 at 16:42
  • @Vico Then you have to find out what is going on. Echo all the vars and find out the line that throws the error. The only line that would imho really read somthing is the last line with the compiler command. And that line uses `$(FULL_CURRENT_PATH)`. So I have no idea what line is giving you that error. – Lars Fischer Jan 22 '17 at 16:46
  • Just some thoughts: `root_folder\bin\gamemodes` : Did you create the subfolder in `bin`? Are they read- and writeable? What happens when you issue the same compile command nppexec uses, verbatim in a cmd window? – Lars Fischer Jan 22 '17 at 16:54
  • Yes, the subfolders are created and read-write permissions given. Another thing. In this line: `set TARGET_PATH ~ strreplace $(CURRENT_DIRECTORY) $(Dir_Src) $(Dir_Bin)` I see you actually inverted the dir parameters. Flipping them gave the correct input folder (src, not bin) for pawncc, but still the final two letters of the extension isnt caught. – Vico Jan 24 '17 at 04:54
  • Now i get `D:\Projetos\GitHub\vicoverse\o_feudo\src\gamemodes.p(0) : fatal error 100: cannot read from file: "D:\Projetos\GitHub\vicoverse\o_feudo\src\gamemodes.p"` – Vico Jan 24 '17 at 04:54
  • @Vico What happens if you just use this `"C:\Pawn\bin\samp\pawncc.exe" $(FULL_CURRENT_PATH) ` ? Because that is what is really given to the compiler. All the other lines are some magic to have variables in place to extend that command with some options to guide the compile into creating the output file in the `$(TARGET_PATH)`, using source in the filepath in `$(FULL_CURRENT_PATH)`. As far as I understood the `$(TARGET_PATH)` should use bin and not src. – Lars Fischer Jan 24 '17 at 18:14
  • Nothing happens – Vico Jan 27 '17 at 14:00
  • @Vico Nothing happens if you use only `"C:\Pawn\bin\samp\pawncc.exe" $(FULL_CURRENT_PATH) ` when the current file in notepad++ is such a pawn source file ???? Then something is broken. Please check if `pawncc` is correctly installed. Please check that the path `C:\Pawn\bin\samp\pawncc.exe` is correct. Please check what happens when you issue the command `C:\Pawn\bin\samp\pawncc.exe ` on the command line. Sorry, but I am out of ideas. – Lars Fischer Jan 27 '17 at 18:24
  • Actually something broke in the first time i've tried the command; now i've got a message from the compiler, BUT no amx file is generated. BUT using "C:\Pawn\bin\samp\pawncc.exe" gm_main.pwn in a cmd window already CDed to the script folder outputs the file as expected – Vico Jan 28 '17 at 02:03
  • If you still want to help me, there is the original tutorial on SAMP Forums: http://forum.sa-mp.com/showthread.php?t=174046 – Vico Jan 28 '17 at 02:12
  • @Vico If that compiler is well behaved it should support an option to put the output file in another directory. Read the docs of the panwcc. *Find that option*. Try it on the commandline first. Then put that option in the nppexec script after the pawncc.exe and give it the `$(TARGET_PATH)` variable or something built using `$(Dir_bin)`. – Lars Fischer Jan 28 '17 at 12:47
  • @Vico If that compiler does not suport such an option: One naive idea is to put a copy/move command after the pawncc command. Using some string replacement to get the amx filename from `$(FULL_CURRENT_PATH)` and use `$(TARGET_PATH)` as destination. – Lars Fischer Jan 28 '17 at 12:51
  • @Vico It looks like ` -o set base name of (P-code) output file ` can be used. – Lars Fischer Jan 28 '17 at 12:54