Special constants in source code to be passed to compiler

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Techie42
User
User
Posts: 58
Joined: Sun Oct 30, 2005 12:28 pm
Location: UK (Berkshire)

Special constants in source code to be passed to compiler

Post by Techie42 »

Hi,

I know we can define constants within the "compiler options" area for use within compiler directives in source code, but I believe it may also be useful to be able to define special constants within the source for use within the "compiler options" area (the reverse direction of what we have now).

For example, I would like to be able to add something like the following to the head of my source code:

Code: Select all

#VERSION_MAJOR = 1
#VERSION_MINOR = 0
#VERSION_BUILD = 7
#VERSION_REVISION = 17

#VERSION_SPECIAL_MAJOR = 1
#VERSION_SPECIAL_MINOR = 2
; and so on ...
Then, I would like to be able to use these special constants in the "version info" area, in much the same way as the existing tokens %COMPILECOUNT and %BUILDCOUNT, e.g. %VERSION_MAJOR,%VERSION_MINOR, etc...

If any files are included that also define the same constants, then a compile-time error could be generated - duplicate definition.

This would permit easier version numbering within our source code, and so would be more likely to be kept up-to-date. The current facility is slightly long-winded in terms of ease of use, especially when compiling alternative versions such as special or private builds.

I hope what I am saying makes sense :)
If the temperature today was 0 degrees, how can it be twice as cold tomorrow?
User avatar
skywalk
Addict
Addict
Posts: 4000
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Special constants in source code to be passed to compile

Post by skywalk »

Yeah, it would be cool if we could edit these constants directly in the code, instead of a constrained gui.

Code: Select all

; ...located at bottom of source code.
; IDE Options = PureBasic 5.00 (Windows - x86)
; ExecutableFormat = Shared Dll
; CursorPosition = 5458
; FirstLine = 5419
; Folding = ----------------
; Executable = my.dll
; CurrentDirectory = C:\myapp\
; CompileSourceDirectory
; IncludeVersionInfo
; VersionField0 = 13.01.18.0
; VersionField1 = 13.01.18.0
; VersionField2 = YourCompany
; VersionField3 = my.dll
; VersionField4 = 13.01.18
; VersionField5 = 13.01.18
; VersionField6 = Your Description
; VersionField7 = my.dll
; VersionField9 = YourCompany
; VersionField10 = YourCompany
; VersionField13 = you@YourCompany.com
; VersionField14 = www.YourCompany.com
; VersionField17 = 0409 English (United States)
Last edited by skywalk on Sat Oct 19, 2013 5:12 pm, edited 1 time in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Special constants in source code to be passed to compile

Post by IdeasVacuum »

...outside of the PB IDE you can do that of course (I use Ultra Edit for my coding)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Franky
Enthusiast
Enthusiast
Posts: 213
Joined: Sat Apr 26, 2003 2:58 pm

Re: Special constants in source code to be passed to compile

Post by Franky »

+1

Being able to change those within the PureBasic Source would be good especially because you would be able to use these information for About-Boxes.
There's nothing worse than different VersionInformation in 2 Places, some people want to kill poor programmers like us for such things :mrgreen:

Best regards

Franky
Give Up everything but trying!
Korolev Michael
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: Special constants in source code to be passed to compile

Post by Korolev Michael »

+1, current solution is not flexible
Former user of pirated PB.
Now registered user :].
User avatar
skywalk
Addict
Addict
Posts: 4000
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Special constants in source code to be passed to compile

Post by skywalk »

Yes, there is a mix of goodies like /initial editor conditions/compiler paths/Version info/etc.
A workaround is to write a Tool that:
1) save your code
2) close your file
3) open your file in memory
4) append your desired values below
5) save the file
6) reopen file
7) compile
Currently, I let the IDE auto increment my version fields by date.
If I need better resolution than %dd, I manually edit. But that is rare.

Code: Select all

; IDE Options = PureBasic 5.20 LTS (Windows - x86)
; ExecutableFormat = Shared Dll
; CursorPosition = 66
; FirstLine = 44
; Folding = --------------------------
; Markers = 9467,9662,9818,9872
; Executable = my.dll
; CurrentDirectory = C:\myapp\
; CompileSourceDirectory
; IncludeVersionInfo
; VersionField0 = %yy,%mm,%dd,0
; VersionField1 = %yy,%mm,%dd,0
; VersionField2 = MyCo
; VersionField3 = myapp.dll
; VersionField4 = %yy.%mm.%dd
; VersionField5 = %yy.%mm.%dd
; VersionField6 = my description
; VersionField7 = my internal name
; VersionField9 = my copyright
; VersionField10 = my trademark
; VersionField13 = me@my.com
; VersionField14 = www.my.com
; VersionField17 = 0409 English (United States)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Special constants in source code to be passed to compile

Post by Kwai chang caine »

SkyWalk wrote:Yeah, it would be cool if we could edit these constants directly in the code, instead of a constrained gui.
+1
I have search today this option...and apparently that always not exist in 2018 :|
ImageThe happiness is a road...
Not a destination
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Special constants in source code to be passed to compile

Post by Josh »

Kwai chang caine wrote:
SkyWalk wrote:Yeah, it would be cool if we could edit these constants directly in the code, instead of a constrained gui.
+1
I have search today this option...and apparently that always not exist in 2018 :|
Do you mean constants like this?

Code: Select all

  #PB_Editor_FileVersionNumeric
  #PB_Editor_ProductVersionNumeric
  #PB_Editor_CompanyName
  #PB_Editor_ProductName
  #PB_Editor_ProductVersion
  #PB_Editor_FileVersion
  #PB_Editor_FileDescription
  #PB_Editor_InternalName
  #PB_Editor_OriginalFilename
  #PB_Editor_LegalCopyright
  #PB_Editor_LegalTrademarks
  #PB_Editor_PrivateBuild
  #PB_Editor_SpecialBuild
  #PB_Editor_Email
  #PB_Editor_Website
sorry for my bad english
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Special constants in source code to be passed to compile

Post by Kwai chang caine »

Hello JOSH :D

Yes i have found it now, i'm really happy :D , but sad few seconds later :|
Because this CONSTANT is apparently ReadOnly, i don't understand why :(
If you enter a value to them you have the debug

Code: Select all

#PB_Editor_FileVersionNumeric = "1.1.1.1"
#PB_Editor_ProductVersionNumeric = "1.1.1.1"
#PB_Editor_CompanyName = "kkkk"
#PB_Editor_ProductName = "oooo"
#PB_Editor_ProductVersion = "pppp"
#PB_Editor_FileVersion = "5555"
#PB_Editor_FileDescription = "6666"
#PB_Editor_InternalName = "juiyt"
#PB_Editor_OriginalFilename = "fffff"
#PB_Editor_LegalCopyright = "oiuty"
#PB_Editor_LegalTrademarks = "ggggg"
#PB_Editor_PrivateBuild = "xxxxx"
#PB_Editor_SpecialBuild = "wwwww"
#PB_Editor_Email = "zzzzzz"
#PB_Editor_Website = "aaaaaaa"

Debug #PB_Editor_FileVersionNumeric
Debug #PB_Editor_ProductVersionNumeric
Debug #PB_Editor_CompanyName
Debug #PB_Editor_ProductName
Debug #PB_Editor_ProductVersion
Debug #PB_Editor_FileVersion
Debug #PB_Editor_FileDescription
Debug #PB_Editor_InternalName
Debug #PB_Editor_OriginalFilename
Debug #PB_Editor_LegalCopyright
Debug #PB_Editor_LegalTrademarks
Debug #PB_Editor_PrivateBuild
Debug #PB_Editor_SpecialBuild
Debug #PB_Editor_Email
Debug #PB_Editor_Website
If you compile, this CONSTANT is not sending to the compiler :shock:
The EXE not have the information in the windows explorer

Apparently only the value writing in the compiler panel is using :|
Or obviously if you modify the IDE file

Code: Select all

; IDE Options = PureBasic 5.61 (Windows - x86)
; CursorPosition = 3
; FirstLine = 1
; Folding = -
; Executable = PbExe.exe
; CompileSourceDirectory
; DisableCompileCount = 32
; IncludeVersionInfo
; VersionField0 = 1.1.1.1
; VersionField1 = 1.2.33.44
; VersionField2 = aaaaaaaaaaaa
; VersionField3 = zzzzzzzzzzzzz
; VersionField4 = eeeeeeeeeeeee
; VersionField5 = rrrrrrrrrrrrrr
; VersionField6 = tttttttttttttttttttt
; VersionField7 = yyyyyyyyyyyyyyyyyyy
; VersionField8 = uuuuuuuuuuuuuuuuuuu
; VersionField9 = iiiiiiiiiiiiiiiii
; VersionField10 = oooooooooooooooo
; VersionField11 = pppppppppppppppppppppp
; VersionField12 = qqqqqqqqqqqqq
; VersionField13 = sssssssssssssssss
; VersionField14 = dddddddddddddddddd
; VersionField18 = cacahuette
; VersionField19 = Kepi
; VersionField20 = couette
; VersionField21 = ffffffffffff
; VersionField22 = ggggggggggggg
; VersionField23 = hhhhhhhhhhhhh
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Special constants in source code to be passed to compile

Post by Kwai chang caine »

Please FRED, can you tell me if it's a choice to not allow modify this constant in the code
Or it's because it's impossible to do ?
ImageThe happiness is a road...
Not a destination
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 346
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Special constants in source code to be passed to compile

Post by Mindphazer »

Kwai chang caine wrote:Please FRED, can you tell me if it's a choice to not allow modify this constant in the code
Or it's because it's impossible to do ?
These constants are the result of what is set in the IDE. So you can't modify them, you can only read them
MacBook Pro 14" M1 Pro - 16 Gb - MacOS 14 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Special constants in source code to be passed to compile

Post by Kwai chang caine »

Hello Mindphazer :D

Yes, i have understand that, but you believe it's a choice of FRED or it's really impossible to do, even if FRED have wanted to adding this fonction ?
ImageThe happiness is a road...
Not a destination
Post Reply