Now This Really Irritates!

Everything else that doesn't fall into one of the other PB categories.
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: Now This Really Irritates!

Post by oldefoxx »

It's about 2:30 am here. I.ve been chasing other issues about all day. The path structure is digfferent in Linux. No drive letter and colon. Use forward slashes instead of backslash. The backslash is only used to signal that the next immediate character to the right is to be taken literally, and the backslash is ignored/ If you want a backslash character in the string, you makr it a double backslash like this: "\\". but what you would get is "\". To include a space, you would enter"\ " in order to get " ". The double quotes here are only to make it apparent what I am typing. If double or single quotes are used. in pairs, you sometimes avoid having to use the backslash. I say "sometimes", because there are exceptions.

To access the folders and files allocated to the user account, you begin with "~/". The use of "~" always signifies the path of "/home/$LOGNAME". This is the same as "/home/$USER", and the same as "$HOME", And initially, the same as $PWD. The "$" denotes a variable name follows, which is a string variable. Numerical values can be derived from a string by ${#VAR},where something like VAR=17 was done previously.
Note that on the left side of the equals sign, no $ preceeds the variable name. The
$PWD refers to the Present Working Directory.

Note that unlike Windows or DOS, there is only one current directory. With DOS or Windows, you have a current directory on every mounted drive. That's because with Unix and Linux, you have one continuous file system. What you have instead are mount points, where a device is mounted and becomes addressable. Mount points are be set up in folders, and the practice has been to set them up under /mnt, or more typically now, under /media. But to ensure only one user account has that device when mounted, the $USER or $LOGNAME becomes a subfolder under /media first.

Thus, If I am running Linux from the first partition on my internal drive, I am likely running off /dev/sda1. However, if the first partition got repartitoned or moved, I might be addressing this as /dev/sda5 or higher. This is much of the reason that the use of UUIDs is taking over, because each partition keeps the same UUID unless it gets reformatted. But while UUIDs are preferred for the fstab and grub2 processes. the manual mount and umount commands still deals with device names.

I don't mount or unmount /dev/sda1. Thats the start of my file system. the one known as root and marked with "/". But i might want to mount /dev/sda2 as well. and my user name is Don, then it's contents can be accessed via the mount point at /media/Don/sda2/. You can find all the environmental variables in your current shell from a terminal window with the simple command of "printenv". It's not that different from DOS and Windows use of the "set" command at a command prompt.

But you don't need either of these commands if you already know the environmental variable name that you want. in our case, let's assume that the Linux user got the gz file, opened it with the Archive Manager. and extracted it to the lowest folder he can legitimately get to via his account. It appears to him as the Home Folder, but is actually the same as the $HOME enironmental setting. And you can get there via the use of "~" as well. So he extrracts it here. The folder's name is "purebasic", all lower case, and case is important in Unix and Linux. So building the path is easy:

"~/purebasic/examples/sources/". This is the path you would normally assume would be there. But suppose it isn't. Let's assume that it is placed inside another folder somewhere. Is there a Linux too that would find it? Actually there are several, The first one you might think of using is "find". That's good for finding a file, but you might want to look for a portion of a directory tree, which cand be a better indicator of subfolders in subfolders with a specific file at the end of your search term.

For this type of search, the "locate" command is a better choice. Here is one I just used and the results obtained:

Code: Select all

locate purebasic/examples/sources/Data/ui.xml
/home/oldefoxx/Templates/purebasic/examples/sources/Data/ui.xml
/home/oldefoxx/purebasic/examples/sources/Data/ui.xml
Locate searches databases rather than actual folders and files, so it is fast. The more characters in your search, the fewer matches turn up. But unfortunately, there is always a /Templates/ subfolder in one of the responses. You have to exclude that response separately. And if you cleaned house, you may have matches from /home/$USER/.local/share/Trash/ as well. Not likely, unless the user replaced one install of PureBasic with another.

There is perhaps a better way. Like DOS and Windows. a single period means the current directory, and a double period means the parent directory. You can use that info to do relative positioning. Or use the shell command "pwd" to find the actual path to the current directory. I wanted to compile a quick program to see what a RunProgram() and "pwd" would tell me, but this is the partition that currently has a problem with pbcompiler. I'll need to do that later. It's 6:16am and I need some sleep.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Now This Really Irritates!

Post by Vera »

@oldefoxx
If you use the compiler option '[X] Create temporary executable in the source directory'.

A - if you compile code from an existing fileNAME.pb than
--> the pb-program.out will be in the same directory as fileNAME.pb
--> ProgramFilename() = fileNAME.pb

B - if you compile code from within a new IDE-tab
--> the pb-program.out will be in the PB-home/compilers directory
--> ProgramFilename() = pb-program.out

If you DON'T use the compiler option '[X] Create temporary executable in the source directory'.

A + B: the pb-program.out will be in the /tmp directory
To find your temporary directory just try:

Code: Select all

Debug GetTemporaryDirectory()
To get GetPBInfo.pb runing under Linux I had to change two lines. You might want to apply the following and should be fine on Windows an Linux alike:

Code: Select all

EnableExplicit

; #Compiler = #PB_Compiler_Home + "compilers\pbcompiler.exe"

; Procedure StartCompiler()
;  ProcedureReturn RunProgram(#Compiler, "/STANDBY", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Write | #PB_Program_Hide)
; EndProcedure

Global StartParam.s

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    #Compiler = #PB_Compiler_Home + "compilers\pbcompiler.exe"
    StartParam   = "/STANDBY"
  CompilerCase #PB_OS_Linux
    #Compiler = #PB_Compiler_Home + "compilers/pbcompiler"
    StartParam   = "--standby"
CompilerEndSelect

Procedure StartCompiler()
  ProcedureReturn RunProgram(#Compiler, StartParam, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Write | #PB_Program_Hide)
EndProcedure
%TEMP% is a Windows environment variable. Have a look:

Code: Select all

Debug GetEnvironmentVariable("PATH")       ; these should work on all OSs
Debug GetEnvironmentVariable("HOME")
Debug GetEnvironmentVariable("USER")

Debug GetEnvironmentVariable("PUREBASIC_HOME")  ; for special people ;-)

Debug GetEnvironmentVariable("APPDATA")      ; these are WIN-only
Debug GetEnvironmentVariable("TEMP")

; To get all your 'current' EnvironmentVariables:
; compile in empty tab [unrelated program]
If ExamineEnvironmentVariables()
  While NextEnvironmentVariable()
    Debug EnvironmentVariableName() + " = " + EnvironmentVariableValue()
  Wend
EndIf
TIP: you might like to try Horst's EnvarList ... and don't miss to check out his page :-)


* * * * * * * * * * * *

@Danilo
I have trouble with: CONSTANTLIST. It's an invalid keyword and freezes the prozess. [I tried some variations, but without lucky hit]
And although INTERFACELIST seems valid it doesn't find anything (result = 0).

How did you find out those 4 needed keywords like: STRUCTURELIST .... ?
Maybe than I can figure out too which ones I would need on Linux to get results.

greets ~ Vera
Last edited by Vera on Sat Oct 03, 2015 10:55 pm, edited 2 times in total.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Now This Really Irritates!

Post by Keya »

on Mac OSX for environment variables there is also this which is just a quick ImportC away:

Code: Select all

extern char ***_NSGetEnviron(void);
but i cant really imagine many situations where you'd use that instead of PB's NextEnvironmentVariable() (although that might just be a wrapper for this?), anyway i only came across it today so just adding to the thread for documenting purposes :D

Code: Select all

ImportC ""
  _NSGetEnviron()
EndImport

Define NextEnvVar.s, *penviron = _NSGetEnviron()
*penviron = PeekI(PeekI(*penviron)) ;ptr to ptr to ptr
Repeat
  NextEnvVar = PeekS(*penviron,-1,#PB_UTF8)
  If NextEnvVar = "": Break: EndIf
  Debug(NextEnvVar)
  *penviron + Len(NextEnvVar)+1
ForEver
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

What Comes to Mind Now Is ...

Post by oldefoxx »

It would be kind of nice if the PureBasic Program Developers adopted a few added comment lines and posted them as part of their source code wnen they post on line.

The comments don't have to be that precise or structured, but would add a few missing details like:

(1) Version(s) of PureBasic it had been compiled and tested with
(2) The OS and version(s) it had been tested under, and whether 64- or 32-bit
(3) A list of the libraries used, and where these might be obtained if not part of the PureBasic or basic OS repertoire
(4) The compiler settings required, if Debug is needed, and what output is expected
(5) Any compiler directive arguments if the compiler is called directly
(6) A brief summation of what the program does
(7) Whatever else you think is helpful to know, like if this program is OS-specific because it uses the Windows APIs only found in WinXP SP3 and above.
has-been wanna-be (You may not agree with what I say, but it will make you think).
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

What;s In A Name?

Post by oldefoxx »

Vera wrote:@oldefoxx
If you use the compiler option '[X] Create temporary executable in the source directory'.

A - if you compile code from an existing fileNAME.pb than
--> the pb-program.out will be in the same directory as fileNAME.pb
--> ProgramFilename() = fileNAME.pb

B - if you compile code from within a new IDE-tab
--> the pb-program.out will be in the PB-home/compilers directory
--> ProgramFilename() = pb-program.out

If you DON'T use the compiler option '[X] Create temporary executable in the source directory'.

A + B: the pb-program.out will be in the /tmp directory
To find your temporary directory just try:

Code: Select all

Debug GetTemporaryDirectory()
The temporary directory is /tmp/ However, I used bash's locate command and could not turn up pb-program.out anywhere. I then did a "dir /tmp" to check its contents, and turned up something quite different. I then did the following command and you can see the results:

Code: Select all

sudo find / -name *.out
/home/oldefoxx/MoreStuff/BackupHB/hot/tools/Debugger/Temp/fwoutput.out
/home/oldefoxx/MoreStuff/Downloads/Python-3.4.2/Lib/test/xmltestdata/test.xml.out
/tmp/purebasic_compilation0.out
So it's now called "purebasic_compilation0.out", and if you want to keep it, you need to do a "sudo mv /tmp/purebasic_compilation0.out ~/newname, right?
has-been wanna-be (You may not agree with what I say, but it will make you think).
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: Now This Really Irritates!

Post by oldefoxx »

To get GetPBInfo.pb runing under Linux I had to change two lines. You might want to apply the following and should be fine on Windows an Linux alike:
CODE: SELECT ALL
I'll do that, just as soon as I find out where this code segment is suppose to go. You wnat it on the top, in the middle, or someplace else?
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Now This Really Irritates!

Post by Danilo »

Vera wrote:How did you find out those 4 needed keywords like: STRUCTURELIST .... ?
Maybe than I can figure out too which ones I would need on Linux to get results.
IIRC it was documented in the PB SDK. Don't have any PB installed currently,
but you could check yourself.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Now This Really Irritates!

Post by Vera »

oldefoxx wrote:So it's now called "purebasic_compilation0.out", and if you want to keep it, you need to do a "sudo mv /tmp/purebasic_compilation0.out ~/newname, right?
Yes that is possible to do. But if the debugger is enabled that executable is much bigger as without debugger turned on.

It's likely easier to use Menu: 'Compiler/Create executable', choose a path and give it a name.
(That name will be remembered for future exe-creation)

Note:
- the purebasic_compilation0.out number will encrease by one for any following compilation of some other code during the same IDE-session.
- these temp-executables will be removed when the IDE is closed. [except when the IDE crashes.]

I'll do that, just as soon as I find out where this code segment is suppose to go. You wnat it on the top, in the middle, or someplace else?
I have updated my snippet above, with the obsolet part, so it should be clearer where to insert it.
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: Now This Really Irritates!

Post by oldefoxx »

My response to this matter has just been posted. I was missing out on the fact that Create Executable was included in the Compiler menu options. But I appreciate your having answered my question so nicely.

My advice to other is, when you shop for a laptop, consider the adviseability of getting one with a backlit screen. Too much light bleeds through in the supposedly dark or unlit areas. I'm down to about a 40% setting, but that's not helping improve the contrast.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Now This Really Irritates!

Post by Vera »

Thanks Danilo :D

it's within: purebasic_home/sdk/compilerinterface.txt
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: Now This Really Irritates!

Post by oldefoxx »

; RunProgram()
;
;
; Syntax
;
; Result = RunProgram(Filename$ [, Parameter$, WorkingDirectory$ [, Flags [, SenderProgram]]])
;
; Description
;
; Launches an external program.
;
; Parameters
;
; Filename$
; The executable name including its path.
;
; Parameters$ (optional)
; Specifies the command line parameters that will be passed To the program.
;
; WorkingDirectory$ (optional)
; Specifies the directory that will then be the current directory For the launched program.
;
; Flags (optional)
; It can be a combination (using '|' Or operator) of the following values:
; #PB_Program_Wait : Wait Until the launched program quits
; #PB_Program_Hide : Launch the program in invisible mode
; #PB_Program_Open : Open the program To communicate With it Or get information about it.
; #PB_Program_Read : Read the programs console output. (stdout)
; #PB_Program_Write : Write To the input of the program. (stdin)
; #PB_Program_Error : Read the error output of the program. (stderr)
; #PB_Program_Connect: Connect another programs output To this programs input.
; A program executed With #PB_Program_Open must be closed With CloseProgram(). The 'Read', 'Write', 'Error' And 'Connect' flags require the #PB_Program_Open flag To be set As well.
;
; When using the #PB_Program_Connect flag, another program must have been started before With #PB_Program_Open And #PB_Program_Read. The number returned when running this program must be passed As the 'SenderProgram' parameter To RunProgram(). The output of the sender program will be sent directly To the input of the now executed program. Several programs may be connected in this way, To 'pipe' Data through that group of connected programs.
;
; The following functions may be used With a program that has been executed With the #PB_Program_Open flag:
;
; - IsProgram(): check If the program number represents a valid program executed by RunProgram().
; - ProgramID(): returns the OS ProcessID For the program.
; - ProgramRunning(): check If the program is still running.
; - WaitProgram(): wait For the program To End.
; - KillProgram(): terminate the program.
; - ProgramExitCode(): get the exitcode of the program.
; - CloseProgram(): close the connection To the program.
;
; The following functions may be used For programs executed With the 'Read', 'Write' And 'Error' flags:
;
; - AvailableProgramOutput(): check If the programs output is available.
; - ReadProgramString(): Read a string from the programs output.
; - ReadProgramData(): Read Data from the programs output.
; - ReadProgramError(): Read a string from the programs error output.
; - WriteProgramString(): write a string To the programs input.
; - WriteProgramData(): write Data To the programs input.
;
;
;
; Return value
;
; Nonzero If the program has been successfully launched, zero otherwise.
;
; If #PB_Program_Open was included in the Flags, the Return-value is a number that identifies the program. It may be used in calls To get information about the program such As ReadProgramString() Or ProgramExitCode() Or other functions mentioned above.
;
; Example
;
;
;
; ; Executes the PB compiler with the /? option and displays the output (windows version)
; ; For Linux/MacOS change the "/?" to "-h".
; ;
Define.s program, request, eol
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
program = #PB_Compiler_Home+"compilers/pbcompiler"
request = "-h" : eol = Chr(10)
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
program = #PB_Compiler_Home+"Compilers\pbcompiler.exe"
request = "/?" : eol = Chr(10) + Chr(13)
CompilerElse
MessageRequester("Compiler Error", " #PB_Compiler_OS = "+ #PB_Compiler_OS)
End
CompilerEndIf

; Debug program
Compiler = RunProgram(program, request, "", #PB_Program_Open | #PB_Program_Read)
; Output$ = ""
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Output$ + ReadProgramString(Compiler) + eol
EndIf
Wend
Output$ + eol
Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))

CloseProgram(Compiler) ; Close the connection to the program
MessageRequester("Output", Output$)
Else
MessageRequester("Compiler Problem:",program)
EndIf
Last edited by oldefoxx on Mon Oct 05, 2015 10:38 am, edited 1 time in total.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Now This Really Irritates!

Post by Vera »

Hey, now that's an example of my taste Image

two things:
* messagerequest() should be MessageRequester()

* to give it a chance for being regarded/added to the help-doc it should be placed in: Feature Requests and Wishlists
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: Now This Really Irritates!

Post by oldefoxx »

'''thanks for the complement. I copied it right out of the source file that compiled and ran in Linux and Windows, so I hace no idea why the MessageRequester() lost two letters. Yeah, I will submit it as you suggested, but I posted it to maybe get some other people aware that this is something that they could be doing as they keep expanding their knowlege of PureBasic. An improved "Help Doc" would be a great help to everyone.

The auto-complete feature in the IDE is how I think the Search feature in the Help section should work. Lot's of list searches accept a single key and jump to where that character got its first first chararacter match. But hit a second key, it jumps to that key as a first character match. You need a box where you type in more characters until you build up a term. Meanwhile, the list shortens as more and more terms are dropped from it. Exactly what the auto-complete feature does. But with something added - a link to that term where it is covered in the Help section.

Hey, that could be applied to the Auto-complete list as well. Save you having to click on help, click on help under help, then typing in the term to be searched for after sclcking on a search button, then after tyoing you have to click on another search buttin, and then you have to look up and down the list for something that matches. And you have to click on that to get the right panel to respond. A lot of work to get to one term's Help.

There is a Help button under the term once it's entered, but that just takes you as far as highlighting the Reference Manual section, which is just the tip of the iceburg. And #PB_ constants get no help at all. There was a point awhile back where I actually found that there was a long list of all the #PB_ constants and what procedures they pertained to, but I only found it that one time and have no idea how I stumbled onto it. If you know what I am talking about, please tell me how to get to it again? I would appreciate it. Not sure what I would use that bit of information for, but you never know.
has-been wanna-be (You may not agree with what I say, but it will make you think).
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Now This Really Irritates!

Post by Vera »

oldefoxx wrote:There was a point awhile back where I actually found that there was a long list of all the #PB_ constants and what procedures they pertained to, but I only found it that one time and have no idea how I stumbled onto it.
That must have been five days ago when jwrjrjwrjr answered to your opening posting ... and the follow ups. :wink:

Like already mentioned above I would suggest that you'd bookmark the online documentation anyway. It's often handy to have it right at hand. E.g. if you want to share a documentation-hint with others.

Now on this Reference Manual Index there are various good topics that you can only find and reach from here. It's good to review it now and then until you've become more familiar with the document.

ps: searching for any #PB_ constant will also always list the Constant Overview in the search result.
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Re: Now This Really Irritates!

Post by oldefoxx »

No, the constant list I'm thinking of appeared alphabetically down a long list in the right pane and consisted of three columns. The left column was the constant, I don't remember what the second column was, but it was mostly empty, and the third column was what that constant was used in conjunction with. At least that is the way I remember it. But I only saw it that one time, and it was back with PureBasic was on version 4. I was hot on something else, and let it go until later. Much later as things turned out.
has-been wanna-be (You may not agree with what I say, but it will make you think).
Post Reply