Difference between revisions of "FreeBSD Programming Tips"

From Free Pascal wiki
Jump to navigationJump to search
m (Re-arrange content)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{LanguageBar}}
 
{{LanguageBar}}
{{Note|Work in Progress}}
 
 
= FreeBSD Programming Tips =
 
 
==Other Interfaces==
 
 
{{Interfaces}}
 
 
===Platform specific Tips===
 
 
*[[Android Programming]] - For Android smartphones and tablets
 
*[[iPhone/iPod development]] - About using Objective Pascal to develop iOS applications
 
*[[FreeBSD Programming Tips]] - FreeBSD programming tips
 
*[[Linux Programming Tips]] - How to execute particular programming tasks in Linux
 
*[[OS X Programming Tips|macOS Programming Tips]] - Lazarus tips, useful tools, Unix commands, and more...
 
*[[WinCE Programming Tips]] - Using the telephone API, sending SMSes, and more...
 
*[[Windows Programming Tips]] - Desktop Windows programming tips
 
 
===Interfaces Development Articles===
 
 
*[[Adding a new interface]] - How to add a new widget set interface
 
*[[Carbon interface internals]] - If you want to help improving the Carbon interface
 
*[[Cocoa Internals]] - Some info about the inner workings of the Cocoa widget set
 
*[[LCL Defines]] - Choosing the right options to recompile LCL
 
*[[LCL Internals]] - Some info about the inner workings of the LCL
 
*[[Windows CE Development Notes]] - For Pocket PC and Smartphones
 
  
 
==Commonly used Unix commands==
 
==Commonly used Unix commands==
Line 62: Line 36:
 
|“Super-user” root authorization||N/A||sudo
 
|“Super-user” root authorization||N/A||sudo
 
|-
 
|-
|Create symbolic link to a file or directory||N/A||ln
+
|Create symbolic link to a file or directory||mklink||ln
 
|-
 
|-
 
|Shrink executable file size||strip (included w/ Free Pascal)||strip
 
|Shrink executable file size||strip (included w/ Free Pascal)||strip
Line 68: Line 42:
 
|Download source from subversion repo||TortoiseSVN||svnlite
 
|Download source from subversion repo||TortoiseSVN||svnlite
 
|}
 
|}
 
  
 
== File system layout==
 
== File system layout==
  
 
In a console or X11 xterm, type ''man hier'' to display a detailed description of the FreeBSD file system hierarchy. Note that the FreeBSD file system hierarchy is different to other Unixes (eg Solaris) and Unix-like operating systems (eg Linux).
 
In a console or X11 xterm, type ''man hier'' to display a detailed description of the FreeBSD file system hierarchy. Note that the FreeBSD file system hierarchy is different to other Unixes (eg Solaris) and Unix-like operating systems (eg Linux).
 +
 +
== Accurate timer ==
 +
 +
[[EpikTimer]] is a programmer's stopwatch that is capable of measuring very short events with traceable high precision over long periods of time. It's simple to use, consumes virtually no CPU and requires only 25 bytes of ram to implement a timer instance. The component provides a single internal timer... but unlimited numbers can be declared externally and linked to a single EpikTimer component on the form.
  
 
== Configuration files ==
 
== Configuration files ==
Line 81: Line 58:
  
 
[https://www.freebsd.org/cgi/man.cgi?query=sysctl&sektion=3 Sysctl] provides an interface that allows you to retrieve many kernel parameters in FreeBSD (and macOS and the BSDs). This provides a wealth of information detailing system hardware which can be useful when debugging user issues or simply optimising your application (eg to take advantage of threads on multi-core CPU systems). For full details and example code, see the article [[Accessing FreeBSD System Information]].
 
[https://www.freebsd.org/cgi/man.cgi?query=sysctl&sektion=3 Sysctl] provides an interface that allows you to retrieve many kernel parameters in FreeBSD (and macOS and the BSDs). This provides a wealth of information detailing system hardware which can be useful when debugging user issues or simply optimising your application (eg to take advantage of threads on multi-core CPU systems). For full details and example code, see the article [[Accessing FreeBSD System Information]].
 +
 +
== Free Pascal Resource Compiler ==
 +
 +
Starting with Free Pascal v2.4 you can use standard .rc (resource script) and .res (compiled resource) files in your project to include resources. To turn a .rc script used in the sources into a binary resource (.res file), Free Pascal runs the appropriate external resource compiler (windres or GoRC). Therefore that resource compiler needs to be installed and present in the PATH environment variable.
 +
 +
For details of how to  install the ''windres'' resource compiler on FreeBSD, see [[Lazarus_Resources#FreeBSD|Lazarus Resources - FreeBSD]]
 +
 +
For more details on the resource compiler, see: [https://www.freepascal.org/docs-html/prog/progch13.html ''Free Pascal Programmer's guide'', chapter 13 "Using Windows resources"].
  
 
== Hardware Access ==
 
== Hardware Access ==
Line 115: Line 100:
  
 
* If FreeBSD is using a custom kernel and is running on a server,  it may not work. I don't see this as a significant defect in user applications which is its use case for my purposes.
 
* If FreeBSD is using a custom kernel and is running on a server,  it may not work. I don't see this as a significant defect in user applications which is its use case for my purposes.
 +
 +
== Networking ==
 +
 +
See this article: [[Networking]].
  
 
== Using HTTPS ==
 
== Using HTTPS ==
  
 
Placeholder. Content to come.
 
Placeholder. Content to come.
 +
 +
==Other Interfaces==
 +
 +
{{Interfaces}}
 +
 +
===Platform specific Tips===
 +
 +
{{PlatformTips}}
 +
 +
===Interfaces Development Articles===
 +
 +
{{InterfaceDevArticles}}
  
 
== See also ==
 
== See also ==
Line 124: Line 125:
 
*[[FreeBSD#Supported_FreeBSD_versions_.2811.x..12.x.29|FreeBSD supported versions]]
 
*[[FreeBSD#Supported_FreeBSD_versions_.2811.x..12.x.29|FreeBSD supported versions]]
 
*[[Installing_Lazarus#FreeBSD|Installing Free Pascal on FreeBSD]]
 
*[[Installing_Lazarus#FreeBSD|Installing Free Pascal on FreeBSD]]
*[[Installing_Lazarus#FreeBSD_2|Installing Lazarus on FreeBSD]]
+
*[[Installing Lazarus on FreeBSD]]
 
*[[Multiplatform Programming Guide]]
 
*[[Multiplatform Programming Guide]]
  
 
[[Category:BSD]]
 
[[Category:BSD]]
 
[[Category:FreeBSD]]
 
[[Category:FreeBSD]]

Latest revision as of 12:08, 31 July 2020

English (en)

Commonly used Unix commands

If you’re coming to FreeBSD from Windows, you may find some of its Unix terminal commands confusing. Here are some equivalents. For more information about a command, enter man command in a console or xterm.

Action Windows command prompt window FreeBSD console or X11 xterm
Change to a different directory cd cd
Make a new directory mkdir mkdir
Delete a directory rmdir rmdir
List file directory in chronological order with detail dir /od ls -ltr
Copy a file, preserving its date-time stamp copy cp -p
Display contents of a text file type cat
Delete a file erase rm
Move a file move mv
Rename a file ren mv
Find a file dir /s find
Grep a file findstr grep
Display differences between two text files fc diff
Change file attributes attrib chmod
“Super-user” root authorization N/A sudo
Create symbolic link to a file or directory mklink ln
Shrink executable file size strip (included w/ Free Pascal) strip
Download source from subversion repo TortoiseSVN svnlite

File system layout

In a console or X11 xterm, type man hier to display a detailed description of the FreeBSD file system hierarchy. Note that the FreeBSD file system hierarchy is different to other Unixes (eg Solaris) and Unix-like operating systems (eg Linux).

Accurate timer

EpikTimer is a programmer's stopwatch that is capable of measuring very short events with traceable high precision over long periods of time. It's simple to use, consumes virtually no CPU and requires only 25 bytes of ram to implement a timer instance. The component provides a single internal timer... but unlimited numbers can be declared externally and linked to a single EpikTimer component on the form.

Configuration files

Refer to the Multiplatform Programming Guide Configuration files section.

Accessing System Information

Sysctl provides an interface that allows you to retrieve many kernel parameters in FreeBSD (and macOS and the BSDs). This provides a wealth of information detailing system hardware which can be useful when debugging user issues or simply optimising your application (eg to take advantage of threads on multi-core CPU systems). For full details and example code, see the article Accessing FreeBSD System Information.

Free Pascal Resource Compiler

Starting with Free Pascal v2.4 you can use standard .rc (resource script) and .res (compiled resource) files in your project to include resources. To turn a .rc script used in the sources into a binary resource (.res file), Free Pascal runs the appropriate external resource compiler (windres or GoRC). Therefore that resource compiler needs to be installed and present in the PATH environment variable.

For details of how to install the windres resource compiler on FreeBSD, see Lazarus Resources - FreeBSD

For more details on the resource compiler, see: Free Pascal Programmer's guide, chapter 13 "Using Windows resources".

Hardware Access

For details on accessing hardware, see General UNIX Hardware Access

Making a Beep

As SysUtils.Beep has no effect on FreeBSD, I looked around for a way to make a beep and found nothing useful. So, I reinvented the wheel as follows:

    {$IFDEF FREEBSD}
    procedure FBSDbeep;
    var
      BProcess: TProcess;
      begin
        BProcess:= TProcess.Create(nil);
        BProcess.CommandLine := 'sh -c "echo xxxxxxx > /dev/dsp"';
        BProcess.Execute;
        BProcess.Free;
      end;
    {$ENDIF}

Note: /dev/dsp will automatically reroute to the sound device's correct device node (eg /dev/dsp0.0) using the dynamic devfs(5) clone handler.

Qualifications

  • Ok, it's more of a burp than a beep, but it serves the purpose. If you're really fussy, you could send a real .wav file to /dev/dsp and play any musical note(s) you desire.
  • If FreeBSD is using a GENERIC kernel, it will work.
  • If FreeBSD is using a custom kernel and it's a desktop system, then it will most probably work because who doesn't want sound on their desktop system.
  • If FreeBSD is using a custom kernel and is running on a server, it may not work. I don't see this as a significant defect in user applications which is its use case for my purposes.

Networking

See this article: Networking.

Using HTTPS

Placeholder. Content to come.

Other Interfaces

Platform specific Tips

Interfaces Development Articles

See also