Re: [fpc-pascal] "Unexpected end of file" when having an open comment after the final "end."

2024-02-08 Thread Travis Siegel via fpc-pascal
No, the original post has the correct program, dropping a ";" in that 
spot is incorrect syntax.


The problem comes in because there is an open comment, but no close 
comment.  If you add the closing } the compiler behaves properly.


On the other hand, I do understand that once the "end." is encountered, 
further processing is unnecessary, and so the error shouldn't occur, 
because any text showing up after that should be ignored.


Honestly, it's is a case of six of one, half dozen of the other. It's 
all in the design of the compiler.  I personally wouldn't consider it a 
bug, but I can see why some folks would, so 



On 2/8/2024 7:01 PM, Martin Wynne via fpc-pascal wrote:

Hi Thomas,

The error is not the file content after "end.".

The error is not having the expected "end;" after "begin".

This works ok:

_

program test;

begin
end;

end.

abc 123

_

Martin.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Travis Siegel via fpc-pascal


On 1/7/2024 1:09 PM, Florian Klämpfl via fpc-pascal wrote:



Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal 
:


Just for comparison, I fired up Think Pascal and made Hello world!

Plain Hello world, closes so quickly that you don't have time to see 
it: 4625 bytes.


Including ShowText and while not Button do; 4639 bytes.

Yes, less than 5k! Progress?


https://github.com/chainq/amiga-tiny-hello-p

244 bytes with FPC.

Not that it's 100 percent relevant, but I always use powerbasic 
(https://www.powerbasic.com) when it's a matter of size, since 
powerbasic and it's console compiler produces a hello world program of 
just 7,168 bytes which is still a windows executable, and works on 
just about any version of windows.


I've never found any windows compiler that produces smaller executables 
by default.


Even their powerbasic windows compilers do an admirable job of keeping 
the executable sizes down to amazing numbers.


I have an epub reader I've been working off and on for the last couple 
years, and even with a complete gui and significant functionality, my 
epub reader clocks in at a whooping 75,776 bytes.


I've never gotten such results from any other windows compiler, and 
indeed, a great deal of linux compilers can't match that.


Of course, I *always* use FPC when a I need the program on multiple 
platforms, though I do tend to use java when I need a gui on multiple 
platforms, as I can just throw up the grid format, then not have to 
worry about how the gui looks, which is great for me, because it's 
either that, or have a sighted individual pour over the gui with me 
until I get it right.  It's just easier to use grid mode on java. :)


For what it's worth though, generally, I find FPC to be considerably 
better than anything cross platform except of course for GCC.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Travis Siegel via fpc-pascal
For what it's worth, the hello world program in powerbasic 
(https://www.powerbasic.com) comes to a whooping 7,168 bytes. That's the 
console version, not the gui version, that's a bit bigger, but by not 
much more.  I have an epub reader I've been working on for a few years, 
on and off, and that program which has a complete gui, web browser 
calls, and the like, weighs in at just over 75K.  I always use 
powerbasic if I'm writing a windows only program, since it's ability to 
produce such small executables is well known.  Heck, it even has a 
#bloat command in the compiler to artificially inflate the size of the 
exe files it builds, because so many didn't believe that it was 
producing an actual windows binary.


I use FPC when working on cross platform programs, since it can compile 
for many platforms, unless I need a gui.  In that case, I use java, 
since I can put it in grid mode, and then I don't have to worry about 
how the gui is laid out.  Something that typically takes sighted 
assistance, and a great deal of time otherwise.


Of course, GCC produces small binaries too, and I'll use that too when 
the need arrises.


It all depends on what I am working on, and where it is going to run.


On 1/7/2024 7:33 PM, Michael Van Canneyt via fpc-pascal wrote:



On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote:



- FPC compiled as is: 388976 B
- FPC compiled with full smartlinking: 55920 B
- FPC compiled with C linkage: 388760 B
- FPC compiled with full smartlinking and C linkage: 56792 B


Maybe it is a good idea to add these numbers to the above WIKI page, 
to quantify

the discussion and to illustrate what the effect is of various options.


Probably... 🤷‍♀️

And just for the fun of it, the size if the RTL is compiled into a 
dynamic package and that is used:


- no smartlinking: 15784 B
- with smartlinking: 15608 B

With the librtl.so having a size of 649912 B which will ammortize 
itself if multiple applications use dynamic packages.


Nice result. Smaller than a C program :-)



I think we should also explain why linking to C has almost no effect 
on actual binary size.


That's mainly because the functions that differ between FPC_USE_LIBC 
and not are rather slim syscalls anyway, so the main bunch of Pascal 
code is still the same in both cases.


I know this, but most likely users will not realize this... :-)

Michael.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] A new FP-like fork of Oberon

2023-10-27 Thread Travis Siegel via fpc-pascal

I too would like this system if possible.


On 10/27/2023 6:19 AM, Adriaan van Os via fpc-pascal wrote:

Liam Proven via fpc-pascal wrote:

On Thu, 26 Oct 2023 at 08:57, Adriaan van Os via fpc-pascal
 wrote:
It might interest you that I ported the Oberon-0 compiler, from the 
book Compiler Construction, to

FreePascal.


It does indeed! Is that FOSS? Is the code anywhere online?


There are still a few changes I want to make, before putting it on 
github. However, I can send you the current code by private email.


Regards,

Adriaan van Os

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] ideas for using a speech-to-text model with a fpc program

2023-09-28 Thread Travis Siegel via fpc-pascal
I'm not exactly sure what the end goal is, but Microsoft has API calls 
for text to speech.  I don't know if they have any for the language 
you're using, but if they do, sending the text to the speech routines is 
fairly straightforward in FPC, In fact, there was a discussion about 
that very thing here a couple months ago, you can find it in the 
archives if you need/choose to go that route.



On 9/25/2023 12:06 AM, Rafael Picanço via fpc-pascal wrote:

Hi guys,

I am looking for some advice on how to use a speech-to-text model with 
a fpc program designed to teach reading of invented words 
composed from 8 brazilian portuguese phonemes (four consonants and 
fours vowels).


So, right now 
(https://github.com/cpicanco/stimulus-control-sdl2/blob/hanna/src/sdl.app.audio.recorder.devices.pas) 
the program uses SDL2 to record short 4-5s audio streams and save each 
recording to a wav file using fpwavwriter. Each audio stream/file is 
supposed to be a word spoken by a student during a recording/playback 
session of a word presented on screen. The participant will click a 
button to finish the session. Then, the program will start a 
speech-to-text routine and give some feedback.


There will be two speech-to-text routines. The first one will be a 
human transcription (nothing new here for me). The second one will be 
an IA transcription.


I am looking for an approach to read the raw stream (or the saved file 
if no direct stream support) and pass it to a speech IA model (for 
example, whisper) and then return some text output for further processing.


Using python, Whisper Medium (multilanguage), I got some good 
(although slow) results without any fine tuning. However, I am 
considering using Transformers if any fine tuning turns out to be 
necessary.


So, in this context, what would be "the way to go" for using the final 
model with free pascal? Calling a script with TProcess? Please, can 
you shed some light on here?


Best regards,
R

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Microsoft SAPI on Freepascal

2023-06-26 Thread Travis Siegel via fpc-pascal

Also, for what it's worth, your code works fine on fpc 3.20.


On 6/26/2023 11:04 PM, James Richters via fpc-pascal wrote:

I appreciate the help with this.  I'm still confused.
In my original post, I  already had CoInitialize,   CoUninitialize; and Unit
ComOBJ,  Unit Windows and Unit ActiveX I was still getting EOleError:
Variant does not reference an automation object.

Do I need to do all this Change FPU stuff?

I'm sure I'm doing something wrong but I still can't get it to work. Here's
my original program.  I wasn't even trying to change the voice yet.  What do
I need to do to this to make it work?

James

{$mode objfpc}

uses
CRT, Windows, SysUtils, ComObj, Variants, OLEServer,  Classes,  ActiveX,
ShellApi;

var
   SavedCW: Word;
   SpVoice: Variant;
   MyWideString: WideString;
begin
   CoInitialize(nil);
   SpVoice := CreateOleObject('SAPI.SpVoice');
   MyWideString := WideString('Hello, the time is ' + TimeToStr(Now));
   Writeln(MyWideString);
   // Change FPU interrupt mask to avoid SIGFPE exceptions
   SavedCW := Get8087CW;
   try
 Set8087CW(SavedCW or $4);
 SpVoice.Speak(MyWideString, 0);
   finally
 // Restore FPU mask
 Set8087CW(SavedCW);
   end;
   Writeln('Press Any Key');
   ReadKey;
   CoUninitialize;
end.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Microsoft SAPI on Freepascal

2023-06-26 Thread Travis Siegel via fpc-pascal
Hmm, ok, apparently something changed in the way FPC handles objects 
between 3.31 and 3.20 (the version I'm using).


Thought I had 3.22, but .

I guess it could be a sapi version difference too, but I don't know how 
to check that.



On 6/26/2023 11:15 PM, James Richters wrote:

When I run the code below I get:
An unhandled exception occurred at $004143C0:
■ Free Pascal IDE Version 1.0.12 [2022/02/07]
■ Compiler Version 3.3.1-10077-gc8403ad49e
■ GDB Version GNU gdb (GDB) 7.2
Running "i:\programming\sapi.exe "
EOleError: Variant does not reference an automation object
   $004143C0
   $004194DD
   $0040B991
   $0040193B  SPEAK,  line 13 of i:/programmingl/sapi.pas
   $00401962  main,  line 17 of i:/programming/sapi.pas

program voice;
uses
comobj;

procedure speak(s : string);

var
v : olevariant;

begin
v:=CreateOleObject('SAPI.SpVoice');
v.Speak(s);
end;

begin
speak('Hello.');
end.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Microsoft SAPI on Freepascal

2023-06-26 Thread Travis Siegel via fpc-pascal


On 6/26/2023 6:26 PM, Michael Van Canneyt via fpc-pascal wrote:



On Mon, 26 Jun 2023, James Richters wrote:



I tried to make your example into a FPC program without Lazarus:
{$mode objfpc}{$H+}
uses
 comobj;
var
 SavedCW: Word;
 v: OleVariant;
begin
  v:=CreateOleObject('SAPI.SpVoice');
  v.Speak('Hello');
End.
I get:
Running "i:\programming\gcode\mill\sapi.exe "
An unhandled exception occurred at $00414370:
EOleError: Variant does not reference an automation object
 $00414370
 $0041948D
 $0040B941
 $004018DF  main,  line 9 of i:/programming/gcode/mill/sapi.pas


I suspect COM is not properly initialized, and that Lazarus does this 
for you.

(it needs com for some components on windows)

So, try adding unit windows to the uses clause and add

CoInitialize(nil);

as the first statement of your program.


Not necessary at all.

The version I got working using just fpc (I don't use lazarus, or even a 
gui (in most cases) I've not figured out how to generate accessible guis 
from a pascal program.  When I need a GUI, I'll either use java (and 
tell it to use grid layout so I don't have to mess with placement), or 
I'll use powerbasic, and generate the GUI separate from the program 
using their tools, then just drop the code in where it's needed to make 
the GUI code work.  It uses DDT methods to generate the GUI, and that 
works just fine with screen readers.  I don't know how to do that with 
FPC, so I generally don't use it when a GUI is required.


But, back to the point.

For me, the code:


program voice;
uses
comobj;

procedure speak(s : string);

var
v : olevariant;

begin
v:=CreateOleObject('SAPI.SpVoice');
v.Speak(s);
end;

begin
speak('Hello.');
end.


It's not a whole lot different from the one posted above, but it might 
help point to the issue.


For me, the line

v.Voice:=v.GetVoices().Item(0);

(or any other number) causes a similar but different error from the one 
received from the original poster in his code, so it could be, (but 
likely isn't) related.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Microsoft SAPI on Freepascal

2023-06-26 Thread Travis Siegel via fpc-pascal


On 6/26/2023 3:51 PM, Michael Van Canneyt via fpc-pascal wrote:

Try changing the selected voice to 0 instead of 1.


Yeah, already tried that, didn't help any. *grumble*

Because I use a screen reader, I have multiple sapi voices installed, 
(though I rarely use them), but I haven't played with the code enough 
just yet to see why it fails when it tries to select one, when not 
selecting one works just fine 


It's important enough, I'll try to figure it out, but if it fails, it's 
not a real issue, since the default voice is fine with me anyway.


On the screen reader, I actually use the espeak engine, so I don't use 
the sapi voices under normal circumstances anyhow, but it would be 
useful to know how to switch voices, perhaps I could add a read out loud 
functionality to my epub reader.  Some folks seem to like that sort of 
thing.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Microsoft SAPI on Freepascal

2023-06-26 Thread Travis Siegel via fpc-pascal
Thank you, this one works for me with a command line compile.  I 
compared the two programs, and the line that asks for the voices is the 
culprit.


I'll have to do some digging to see why that line breaks the runtime 
execution.


But at least I can make it work now.  I'd always used powerbasic when I 
needed to work with com objects, good to know I can do the same thing in 
fpc now.



On 6/26/2023 2:12 PM, Rik van Kekem via fpc-pascal wrote:

Op 25-06-2023 om 22:46 schreef James Richters via fpc-pascal:
I gave up on doing it directly, it seems SO convoluted to do with FPC 
with the COM unit and all this stuff I just don’t understand,
and it’s SO simple to do with a VBS script in just 3 lines and it 
just works!(it would only be 2 lines if I didn’t want Microsoft Zira)

You didn't mention the version of FPC/Lazarus you were using.

I had a simple example which worked for me (but your example also 
directly worked for me in trunk).


program Project1;
{$mode objfpc}{$H+}
uses
  Classes, ComObj;
var
  Voice: olevariant;
begin
  Voice := CreateOLEObject('SAPI.SpVoice');
  Voice.Speak('I am speaking.', 0);
  Voice.Speak('I am also speaking.', 0);
end.

I didn't even have the problem with any EZeroDivide exception.

--
Grtz,
Rik van Kekem


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Microsoft SAPI on Freepascal

2023-06-26 Thread Travis Siegel via fpc-pascal
Does the form code do something different than the command line? When I 
try to run this code, I get an unhandled exception error.


Any idea how to fix?


On 6/26/2023 1:54 PM, Michael Van Canneyt via fpc-pascal wrote:



On Sun, 25 Jun 2023, James Richters via fpc-pascal wrote:

I gave up on doing it directly, it seems SO convoluted to do with FPC 
with the COM unit and all this stuff I just don’t understand,
and it’s SO simple to do with a VBS script in just 3 lines and it 
just works!  (it would only be 2 lines if I didn’t want Microsoft Zira)


I don't know what people advised you, but what you want to do needs 3 
lines

of code only:

I created a lazarus application, dropped a button and in the onclick I 
call

speak('hello'). It just works.


--
uses comobj;

procedure speak(s : string);

var
  v : olevariant;

begin
  v:=CreateOleObject('SAPI.SpVoice');
  v.Voice:=v.GetVoices().Item(1);
  v.Speak(s);
end;

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  speak('hello');
end;
--

No need to write a script, call tprocess etc. You can do everything 
right in fpc as simple as this.


Michael.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Legitimate use of for and break

2023-06-18 Thread Travis Siegel via fpc-pascal



On 6/18/2023 6:53 AM, Bernd Oppolzer via fpc-pascal wrote:


The compiler is a self-hosting compiler (like most Pascal compilers, I 
believe) and up to 2011
there were many exits from loops bye putting a label after the loop 
and using GOTO
(because of the absence of BREAK). Similar use of GOTO to implement 
CONTINUE and RETURN.



Heh, interesting enough, I've never used goto in a pascal program 
either, but at least I was aware that keyword existed. :)


It's taken some work at times *not* to use goto, but I learned goto was 
a bad thing when I was first learning to code, way back in the mid 80s, 
so I've never used it except in basic code, where it's often impossible 
to avoid, with the way code is written.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Legitimate use of for and break

2023-06-18 Thread Travis Siegel via fpc-pascal


On 6/18/2023 1:04 AM, Hairy Pixels via fpc-pascal wrote:
I don't remember break NOT being in Pascal. How did you exit a loop 
otherwise, goto? Break is common in basically all languages now. Can't 
think of a language I've used without it.


Use a variable, set the variable when you hit an exit criteria, then 
before repeating the loop, check the variable, if it's true, exit the 
loop (exit does this), or just craft the loop (easy to do if it's a loop 
until construct) so it exits the loop automatically.  Probably not as 
efficient as break, but since I didn't know it was a valid command, 



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Legitimate use of for and break

2023-06-17 Thread Travis Siegel via fpc-pascal
This is interesting, because it's the first time I've ever seen "break" 
as a valid command in pascal, and I've been using pascal since the 
mid/late 80s.  All kinds of dialects too, and I've never seen break as a 
keyword.  C, Python, Perl, sure, even shell scripts, but pascal? Never 
seen it used before.  Is this a relatively new addition to fpc or something?



On 6/16/2023 1:51 PM, Hairy Pixels via fpc-pascal wrote:



On Jun 16, 2023, at 6:23 PM, Thomas Kurz via fpc-pascal 
 wrote:

Whether it's elegant is a different question. In my opinion YES because it often gives better 
readable code than nested "if" statements inside the loop. But I've also read that using 
"break" is discouraged because it shows a bad choice of the loop range.

This is highly suspect. Doing an early break in loops is the essence of how to 
do linear searching. No idea who thinks that's a bad idea.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Function to create a record ?

2023-06-04 Thread Travis Siegel via fpc-pascal
Depending on the compiler *not* to overwrite local variables is most 
certainly the wrong way to go with this.  You really should create 
either a global record/object, or use functions to pass around the 
information you need.  Expecting the operating system to keep local 
variables after the area goes out of scope is just begging for errors 
later on when the compiler/os treatment of said areas changes.



On 6/4/2023 1:37 PM, Steve Litt via fpc-pascal wrote:

Henry Vermaak via fpc-pascal said on Fri, 2 Jun 2023 09:38:17 +0100


On Fri, 2 Jun 2023 at 01:36, Steve Litt via fpc-pascal
 wrote:

 fillchar(junkvar, junkvar_size, 'b');
 person := modperson(person, 'Martin');
 person := modperson(person2, 'Maria');

Maybe a typo? (E.g. person2 := modperson(person2, 'Maria'))

Henry

Thanks Henry!

You're right: Changing the second person := to person2 := did just what
I wanted it to do.

Because returning a local array or string as a function return in C
leads to horrible intermittents due to the local going out of scope and
relinquishing the local's stack, which can then be overwritten, I added
a procedure, a function, and a main program statement which each
consumed two million bytes of local variables, and the person and
person2 didn't get overwritten. Very cool.

When I increased the huge local vars to three million bytes, the
program segfaulted. I figure I just ran it out of stack, but until I
did, the huge local vars didn't trash the contents of person and
person2.

Thanks for your help.

SteveT

Steve Litt
Autumn 2022 featured book: Thriving in Tough Times
http://www.troubleshooters.com/bookstore/thrive.htm
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why does RunCommand not produce the correct output?

2023-05-01 Thread Travis Siegel via fpc-pascal
Well, you could use the infile and outfile redirect functionality.  I 
don't know how it's done in fpc, but the manual should get you the 
proper syntax.  Simply redirect the text output to a file or buffer, 
then redirect the input file buffer as well, and feed the output from 
the first command to the input of the next one.  I've seen it done, but 
it was quite some time ago, and I don't remember the specifics.  With 
this method, it would take multiple steps, but you could then control 
the process from start to finish.  The only issue is you'll have to put 
in the full path of the commands you're running, since there won't be 
any shell running to use the path for locating the programs you want.


In all likelihood, the programs you're using will be in /usr/bin, but 
unfortunately, there's no guarantee of that.



On 5/1/2023 5:38 PM, Bo Berglund via fpc-pascal wrote:

On Mon, 1 May 2023 14:25:28 -0400, Travis Siegel via fpc-pascal
 wrote:


You could just add the line:

#!/bin/bash

to the first line of your script, then just call the script from your
program.

Alternatively, you could call the bash command, and pass the command to
it that way, either one should get you the output you desire.

I did already create a script "listserial" that does the extraction:
(long line split by newsreader)

-
#!/bin/bash
SERLIST=$(ls -l /sys/class/tty/*/device/driver | grep -v
"platform/drivers/serial8250" | awk '{print $9}' | awk -F'/' '{print "/dev/"
$5}')
echo $SERLIST
-

This successfully lists the available serial ports by their device name, which
can be used to open the port using the built-in serial unit functionality.

Of course I *could* call the script from the program but I wanted it all be
within the FPC program itself...

But it can be done by calling the standalone script file of course...



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why does RunCommand not produce the correct output?

2023-05-01 Thread Travis Siegel via fpc-pascal
As mentioned in another post, you'll need to run a shell, (whether it be 
bash or another system provided shell), in order to process the 
commands.  If you run the commands directly, there is no shell 
interpretation, and the | which passes the output of one command to the 
input of the next one won't function as expected,


I don't know what environment processes commands if you run the commands 
without a shell environment, it could be FPC, or it could be something 
buried in the linux environment, I've never bothered to look up the 
answer, but it certainly won't have the redirection capability of the 
linux shells provided by the system, and actually, can behave 
differently, depending on which shell is used.


You could just add the line:

#!/bin/bash

to the first line of your script, then just call the script from your 
program.


Alternatively, you could call the bash command, and pass the command to 
it that way, either one should get you the output you desire.





On 5/1/2023 11:00 AM, Bo Berglund via fpc-pascal wrote:

I am trying to create a function to list the available serial ports on a Linux
device. But I have trouble getting commands which work on a terminal to also
work when run from my console program.

When I run this conmmand in the terminal I get the correct reply:

$ ls -l /sys/class/tty/*/device/driver | grep -v "platform/drivers/serial8250" |
awk '{print $9}' | awk -F'/' '{print "/dev/" $5}'

/dev/ttyAMA0

But when I use RunCommand() in FPC it does not work long line wrapped by
newsreader):

program listserialports;
{$mode objfpc}{$H+}

uses
   baseunix, classes, sysutils, process;

function ListSerialPorts: integer;
var
   ListCmd: TProcessString;
   OutData: string;
begin
   Result := 0;
   ListCmd := 'ls -l /sys/class/tty/*/device/driver | grep -v
"platform/drivers/serial8250" | awk ''{print $9}'' | awk -F''/'' ''{print
"/dev/" $5}''';
   Writeln('Command: ' + ListCmd); //To see what is actally sent to Linux
   RunCommand(ListCmd, OutData);
   Writeln(OutData);
end;

begin
   ListSerialPorts;
   Writeln('Done');
end.

I see the command being executed but there is an empty output.
If I copy the dislayed command and paste it in and run it I get the result as
shown above. So there should be no typo in the command line, right?
Still no output...

What can I do?
(I have created a shellscript with the same command string and it runs just fine
and prints the data on screen.
But I need the function in order to populate a control with the output inside a
GUI program once thus function works.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Oberon-0

2023-04-18 Thread Travis Siegel via fpc-pascal
Gcc has already been ported to the propeller II, (and it runs on the 
original propeller too), so porting other languages should be 
"relatively" easy.  I've not made the attempt to port anything yet 
though, mostly because I've been out of the propeller world for a couple 
years, and now that the version 2 is out, I'm trying to reestablish some 
working environments so I can use the propeller 2.  I have bought some 
of the mystery boxes, which gave me a propeller 2 edge board with 32MB 
of ram, but I don't think I have an actual propeller 2 just yet.  
Needing others to id things for me is making the list of products I have 
hard to create, but I'm getting there.


Anyway, since gcc exists, any compiler that uses gcc as the backend 
should be possible to port.  I've thought about porting FPC, but I'd 
have to start with a version that's already meant for smaller systems, I 
do believe someone posted a link to one a few months ago, perhaps that 
one could be used as a jumping off point, would be interesting to see 
pascal available for the propeller boards.



On 4/18/2023 6:21 AM, Markus Greim via fpc-pascal wrote:

Hi Adriaan,

whats about a Oberon-0 compiler compiling to Forth?
And then Forth to MacOSX? (RetroForth, Swift or whatever)

That may sound silly, but such a Compiler would help a lot to port 
Obern to other platforms resp Microcontrollers etc.

For example to the Propeller II 

Kind Regards

Markus
Sent from Front
On April 18, 2023 at 12:13 PM GMT+2 fpc-pascal@lists.freepascal.org 
wrote:


Any suggestions for running simple Oberon-0 programs on the MacOSX 
command-line ? EIther by emulating its RISC processor or by changing 
the Oberon-0 compiler ? I prefer not to load the entire Oberon system 
(for which there do exist emulators).


Regards,

Adriaan van Os
___
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pause Key

2023-04-13 Thread Travis Siegel via fpc-pascal
I know of no way to obtain the pause key status under windows.  I can 
get the scroll lock status, but not the pause key, never did figure that 
one out.  Windows uses it though, I don't know if it's a standard thing, 
or something I have installed, (though if it is an installed program, I 
haven't a clue which one).  When I hit the pause key, it brings up the 
screen snippet dialog.


Since the scroll lock key is readable though, you could use that for a 
pause function.  Almost nobody uses that key, so interference should be 
minimal.



On 4/13/2023 8:31 PM, James Richters via fpc-pascal wrote:

Does anyone know what's up with the Pause key in Windows?
Is there some way to tell if it was pushed?
I have a need for the user to pause execution of my Freepascal program, I
have a pause key.. seems like there should be some way to use it.

James

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting old pascal written for Pascal/MT+ compiler

2023-04-04 Thread Travis Siegel via fpc-pascal
I'm not positive, because I've never used them, but I'm pretty sure 
variables configured as const, can't be changed once they're defined.  
If that's your intent, then feel free to use them, but it sounds like 
you're trying to make variables (not constant values) last for the whole 
program, with manipulation being allowed.  In that, case, simply define 
them in the var section before you do any of the functions and 
procedures.  That will make them visible for the whole program, and they 
won't go out of scope.  I know many folks contend that global variables 
should be kept to a minimum, and scope should be carefully evaluated, 
and only allow variables to be usable when they're actually needed, and 
to some degree, I agree, but there's times when it's just too darned 
convenient to have something accessible for the whole program over 
multiple functions/procedures, and in those cases, I see nothing wrong 
with having as many globals as you need.


Often, when I'm doing a quick and dirty program, (I.E. one to change a 
data file from one format to another), I won't even bother with 
functions and procedures, just write the whole program as one big main 
procedure, since it's only being run once or twice, then never used 
again, I see nothing wrong with this approach either, and in that case, 
all variables are global.


No reason you can't do the same, and not depend on quirks of the 
compiler to keep your items in scope especially when they clearly 
shouldn't be.




Am 04.04.2023 um 08:16 schrieb Jacob Kroon via fpc-pascal:


I was able to write a couple of perl-scripts that are able to convert 
my old Pascal sources to something that fpc can parse. Amongst other 
things, the scripts inject the "public name"/"external name" 
annotations so that the program can link.


But I suspect I have a new problem: With the old Pascal/MT+ compiler 
it would appear that local variables declared in functions/procedures 
have a life-time that spans the whole program, like a "static" 
declared variable in C. With fpc, it looks like locally declared 
variables are automatic, put on the stack(?), and so they go out of 
existence once out of scope ?


The program depends on this feature in the old compiler. I did some 
googling and found that putting local variables in a "const" section 
instead of "var" would make them have a "whole-program" lifetime, but 
then I need to provide them with an initial value.


Do I have any other option besides changing from "var" to "const" 
everywhere, and provide initial values in all declarations ?


Regards
Jacob



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-01 Thread Travis Siegel via fpc-pascal
Generally, raspberry pi devices connected to other devices will (by 
default) use python for their programming.  The python libs have all the 
setup and tear down code built in.  You can use C as well, so I see no 
reason why FPC couldn't be used.  It's probably going to take some work 
though.  You'll need to either find the appropriate python files, and 
port them to FPC, or convert the C headers into something pascal can 
understand.  I've never made the attempt to do this, though now that you 
bring this up, I might just take a crack at it.  Up until now, I've used 
C (since I'm not a fan of python) when talking to raspberry connected 
devices, but I'm pretty sure I've seen posts where folks were using 
other languages such as PHP or Java to talk to the pi devices, so those 
header files have most certainly been ported to other languages. It's 
possible someone already did the pascal port, though I can't point to 
one.  I've not been messing with my raspberry pis for the last year or 
so because of moving, and things are just now getting back to normal (I 
hate moving), and I need a new pi anyhow, so perhaps I will get back to 
it this year, but the reason I say this, is because I've not kept up 
with the pi forums, so I don't know what's happening around the pi 
ecosystems lately, which is why I can't answer the question directly, 
though it's certainly more than possible.


Sorry I don't have more solid information for you.


On 4/1/2023 6:22 PM, Giuliano Colla via fpc-pascal wrote:

Il 01/04/2023 21:56, Bo Berglund via fpc-pascal ha scritto:

I need to read and write data to an EEPROM connected by I2C on a 
RaspberryPi4.

The I2C channel is found in /dev as i2c-1:

$ ll /dev/i2*
crw-rw 1 root i2c 89, 1 2019-02-14 11:12 /dev/i2c-1

In this channel the EEPROM CAT24C128 is at address 0x50
The data on the device is organized as 256 pages of  64 bytes data 
each AFAIU.


I can check the EEPROM using i2c-tools, which I have installed, but I 
am unsure

if the read is correct...

Question:
Can I use Linux file system commands to read/write the data on the 
i2c EEPROM

memory device and if so how from fpc?

I have installed the current versions of Lazarus and Fpc on the RPi4 
itself.





I2c is a serial protocol. All what the hardware can see is just a pair 
of bits: a clock line and a data line. I2c-tools provides the required 
software to write and read those two bits. In your case for 
programming the EEPROM and reading it back. The linux kernel uses 
i2c-tools and knows what i2c-tools tell it.


I don't know if i2c-tools can be required to emulate a block device 
thus providing the system a block device, which then becomes readable 
by any means. But even if it does, and you can read your EEPROM from 
fpc, or whatever software you like, you will not gain any advantage, 
because the reading mechanism will be implemented by i2c-tools, and it 
will be exactly the same when verifying after programming. If reading 
was wrong, it will be wrong again, if it was good it'll be good again. 
Forget about writing. Writing an EEPROM is a complex procedure. If 
i2c-tools knows how to do it, let it do it.


If you really need an independent verification, you should find an 
adapter which accepts your EEPROM and makes it accessible via a block 
device interface, such as USB. I don't know if such adapter does 
exist, but it's the only way.


Giuliano


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-01 Thread Travis Siegel via fpc-pascal
On unix (and all of it's derivatives, everything is a file, including 
connections to other systems.  You can treat it like a file, and in 
(most) circumstances, it will operate just as if it were a local file.


Some devices require special handling, but for the most part, if it's 
listed as a file on the system, you can read it as one.


Of course, permissions apply, so creating files or reading them may be 
limited by user/group permissions, so there's no guarantee that just 
because the file is there, you'll be able to read it.



On 4/1/2023 3:56 PM, Bo Berglund via fpc-pascal wrote:

I need to read and write data to an EEPROM connected by I2C on a RaspberryPi4.
The I2C channel is found in /dev as i2c-1:

$ ll /dev/i2*
crw-rw 1 root i2c 89, 1 2019-02-14 11:12 /dev/i2c-1

In this channel the EEPROM CAT24C128 is at address 0x50
The data on the device is organized as 256 pages of  64 bytes data each AFAIU.

I can check the EEPROM using i2c-tools, which I have installed, but I am unsure
if the read is correct...

Question:
Can I use Linux file system commands to read/write the data on the i2c EEPROM
memory device and if so how from fpc?

I have installed the current versions of Lazarus and Fpc on the RPi4 itself.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Cross-compile for Linux Arm (RaspberryPi) on Windows 10?

2023-03-25 Thread Travis Siegel via fpc-pascal
If you're not opposed to copying files anyhow, why not setup a script to 
do the compile for you on the pi?


You just need to setup your pi with ssh keys, then use scp to move the 
files, ssh to do the login, then just run the shell script to do the 
compiling.


If you configure the ssh keys properly, you can use windows batch files 
(or power shell scripts), that would simply copy the files to the right 
place on the pi, then ssh in (or in your case, vnc I suppose), then just 
run the script to do the compile.  I don't know if vnc can handle that 
by itself, so you could use a single script, having never used it, but I 
do this kind of thing all the time.  I have the pi setup to accept ssh 
logins so passwords aren't necessary, then I can just scp a file to the 
pi, then ssh in and uncompress the file, and run the compile command, 
and it's all done.  Admittedly, it's a two step process, but it works 
well enough.


I do use FPC, though I don't use lazarus, mostly because it's not really 
all that compatible with screen readers, so most of my compiling is done 
via command line, (even on windows development environments), so I don't 
know if this suggestion can work for you, but I use it regularly when 
cross compiling for linux/raspberry pi/OSX, and it works well for me.





On 3/25/2023 7:07 PM, Bo Berglund via fpc-pascal wrote:

On Sat, 25 Mar 2023 23:25:07 +0100, Bo Berglund via fpc-pascal
 wrote:


I have latest Lazarus/Fpc on my Windows 10 main computer, but also on a number
of RaspberryPi (3 and 4) devices. If I create an application on Windows and want
to build the same for RPi, then I have to transfer the sources (via Subversion)
to the RPi and build there.

And doing so requires me to use VNC to connect to the RPi, which is less than
optimal.

Now I wonder how to set up FPC on Windows to cross-compile for Raspberry Pi
(arm6/arm7 processor and Debian based Linux)?

The freepascal Wiki articles I have found are either outdated or do not describe
enough in detail how one can do this...

So is there some up-to-date article describing it?

I have found this: https://wiki.freepascal.org/Cross_compiling

and it actually mentions RaspberryPi in passing, so I guess that is encouraging.

Since I have RPi units with Lazarus/FPC installed there is also a directory:

$HOME/lib/fpc/3.2.2/units which contains subdir arm-linux

If I tar this arm-linux dir I get a file arm-linux.tgz which is about 52 MB in
size.

Do I extract this into my Windows FPC 3.2.2 installation somewhere in order to
be able to cross-compile?

Below the Lazarus installation dir /dev/lazarus/2.2.4 I also have this dir:

/dev/lazarus/2.2.4/units/arm-linux and this is 233 KB in size.
Do I tar and copy this too into my Windows Lazarus/FPC installation?

It contains only 2 subdirs:
/dev/lazarus/2.2.4/units/arm-linux/gtk2
/dev/lazarus/2.2.4/units/arm-linux/nogui

If so, where do I deposit these files on Windows?
I have used the SourceForge installer to get the Lazarus 2.2.4 installed.

Do I drop them off into a new ...\fpc\3.2.2\units\arm-linux directory even
though they came from two different places on the live system?

Grateful for some advice, I have never done this ever before...



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] possible bug in blockwrite

2023-03-05 Thread Travis Siegel via fpc-pascal
I'm using FPC 3.2.0, though I doubt anything changed in the most recent 
releases, though I'll try those if folks think it's worth doing so.


What I ran across yesterday while doing a search for other things was 
some posts about updating a single line in a file using free pascal.  
The solutions mostly centered around using stream objects or the inifile 
objects in lazarus.


This reminded me that I used to do this exact thing under turbo pascal 
by using blockread/writes, and treating the text file as a binary one.  
This allowed me to make changes without having to rewrite the whole 
file, something even inifile still does.


To make a long story short, I tried that technique in FPC, and was a bit 
surprised by the results.


What happens is this:

On tp, I could open a file with a blocksize of 1,

reset(file1,1);

which would allow me to move through the file, and blockread/blockwrite 
whe ever I so chose to do so.


The problem with FPC comes in when I try this using strings.

For some reason, FPC treats the binary mode of the file as a license to 
treat each item written to it as a binary blob as well, and this breaks 
tp functionality.


For example.

Let's say I have a 5 byte string:

st1 := '12345';

Now, if I blockwrite this to the file under tp:

blockwrite(f1,st1);

The 1 for blocksize wasn't necessary, because tp already knows the 
blocks are of size 1 due to the reset command.


Now, if you were to open that text file in an editor, you would see 
12345 as the first five bytes of the file (assuming I'd not moved the 
file pointer elsewhere first).


Interestingly enough, with FPC, it actually writes 6 bites, (and the 
blockcount is necessary).


blockwrite(f1,st1,6);

The reason it needs the extra byte is because the byte 0 (the one that 
stores the size of the string) is also written to the file. TP did not 
behave this way, though I don't know about delphi, though I'd doubt it dit.


It is fixable, one can simply return to the initial write location and 
write a space character to remove the offending character.


However, this doesn't account for long strings (haven't tested to see 
what happens in that case)


or other structures that might have additional overhead.

I would expect FPC to write just the structure elements, not the 
housekeeping bytes that go along with them when doing a blockwrite.


Is this a bug, or is this a deliberate design decision, and if so, can 
we talk about changing it's behavior?



The other issue I encountered while performing this test is when 
converting between strings and numbers, FPC does not follow TP 
functionality either.  That one at least is documented, so I was able to 
see why it did things the way it did.  However, this too, I think should 
be changed to behave as tp did, in that it simply ignored nonnumeric 
characters in the string, instead of aborting processing.


At the very least, it should go ahead and convert the numbers it did get 
before encountering a nonnumeric value instead of aborting the whole 
conversion attempt.


This can be demonstrated by something like this:

st1 := '123';

val(st,number,code);

(this produces a value in number of 123 as it should).

But, when one does:

st1 := #49+#50+#51+#13;

then the same code:

val(st,number,code);

produces an error, and code has the value of 4, (the place in the string 
where the error occurred), but number has a value of 0.


In tp, number would still have a value of 123, because it would simply 
ignore the carriage return at the end of the string.


I'm sure this one is by design (at least the not ignoring other 
charaters part, probably not the skipping assigning a value entirely 
part), but it would be helpful if it were modified to simply ignore all 
nonnumeric characters in the conversion string, the way tp handled it.


Comments?

I've built in workarounds in my program to solve both of these issues, 
but it'd be nice if I didn't have to do that.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FreePascal and the OrangePi

2022-10-21 Thread Travis Siegel via fpc-pascal
When I installed fpc on my raspberry pi, I compiled from source, but 
that was when the pi was relatively new.  I'm fairly certain there's a 
release for the pi.  If the orange one has an arm processor, the release 
for the raspberry should work on the orange as well.



On 10/21/2022 6:19 PM, Terry A. Haimann via fpc-pascal wrote:

Dumb ?

What download should I use to install the latest version of FreePascal
on the OrangePi 4 LTS, I am running Debian 3.0.6 Bullseye.

The Orange Pi 4 LTS is an SBC running an ARM Processor.
Rockchip 3399 SOC

http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/orange-pi-4-LTS.html

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] mciSendString with long file names

2022-09-22 Thread Travis Siegel via fpc-pascal
A solution I started using, because the mci commands (for some reason) 
don't handle all mp3 files I have, was to use a dll called fmod.dll.  It 
handles several formats, not just mp3, and it can be started on another 
thread, then ignored.  I've used it to build a much better mp3 player 
than I was able to make using the mci commands, since now I can handle 
other formats as well, which helps since interestingly enough, I'm still 
finding files in other formats burried in my collections, and so far, 
the fmod program handles them all nicely


It can't be used in a commercial application, but it doesn't sound like 
yours is, so you should be ok.



On 9/22/2022 4:22 PM, James Richters wrote:

Sorry for the confusion.   Let me clarify:

The freepasal program is always run on a Windows system,  mciSendString is a 
Windows function.  I've seen solutions for this problem that use the NTFS 8.3 
Short file name... Which I thought would work, but, for my application it won't 
work because the file is being loaded off a network drive, and the SERVER for 
the file is a Linux server.. but even though it's a Linux server, the path on 
my windows system is still uses backslashes not forward slashes... It's a 
FreeNAS server with Windows file sharing.  Anyway the point was that only 
windows NTFS formatted drives have the short file name.. so that solution won't 
work at all.  I want the program to be able to play the sound file no matter 
where the file is stored on the network or on a flash drive or a ramdrive.. 
etc,  and not have a requirement that it is an NTFS drive.

So it has to work with windows paths.  Almost all windows applications just put 
it in quotes, but mciSendString does not play nice.  I think it was invented 
during 8.3 limitations and it was only hacked to kind of work with long file 
names.. not really work properly.  The Alias method does work, but it's not so 
convenient for Asynchronous mode because it leaves the file open.. if you close 
it before it finishes playing, it stops and if you wait for it to finish and 
then close it.. well, that's just not asynchronous.

James

-Original Message-
From: fpc-pascal  On Behalf Of Travis 
Siegel via fpc-pascal
Sent: Thursday, September 22, 2022 3:27 PM
To: ja...@productionautomation.net; FPC-Pascal users discussions 

Cc: Travis Siegel ; James Richters 

Subject: Re: [fpc-pascal] mciSendString with long file names

That's on windows, you said the program was running on linux.  In that case, 
backslashes will escape the spaces, allowing the path to be found properly.

Windows paths are different, as mentioned before, they can be escaped too, but 
the character is different.

On 9/22/2022 2:57 PM, James Richters via fpc-pascal wrote:

Won’t backslashes before each space be defining a subdirectory?

If my path looks like:
C:\Program Files\My Program\Some File.MP3 I don't see how changing it
to:
C:\Program\ Files\My\ Progam\Some\ File.MP3 can possibly work.. it's just 
butchering the path.

James


From: fpc-pascal  On Behalf
Of Travis Siegel via fpc-pascal
Sent: Wednesday, September 21, 2022 4:15 PM
To: FPC-Pascal users discussions 
Cc: Travis Siegel ; Jean SUZINEAU

Subject: Re: [fpc-pascal] mciSendString with long file names

Adding a backslash (\) before each space should do the job nicely.  I have had similar 
issues on linux and windows with some commands, and adding the escape characters to the 
filename almost always fixes the problem.  The only time it didn't, was when the filename 
started with a dash "-" character.  Otherwise, the backslash always works for 
me.

On 9/20/2022 4:16 PM, Jean SUZINEAU via fpc-pascal wrote:
May be by escaping the spaces with ^ ?
Something like:  MyFileName:= StringReplace(MyFileName, ' ', '^ ',
[rfReplaceAll]); ^ is the escape char for cmd.exe but may be it is active in 
this context too ?
Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit :
I just tried it that way:
Var
pcmd: String;
MyFileName: String;
   
pcmd:='play "'+MyFileName+'"'+#0;

mciSendString(@pcmd[1],Nil,0,0);
   




___
fpc-pascal maillist  -  mailto:fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] mciSendString with long file names

2022-09-22 Thread Travis Siegel via fpc-pascal
That's on windows, you said the program was running on linux.  In that 
case, backslashes will escape the spaces, allowing the path to be found 
properly.


Windows paths are different, as mentioned before, they can be escaped 
too, but the character is different.


On 9/22/2022 2:57 PM, James Richters via fpc-pascal wrote:

Won’t backslashes before each space be defining a subdirectory?

If my path looks like:
C:\Program Files\My Program\Some File.MP3
I don't see how changing it to:
C:\Program\ Files\My\ Progam\Some\ File.MP3 can possibly work.. it's just 
butchering the path.

James


From: fpc-pascal  On Behalf Of Travis 
Siegel via fpc-pascal
Sent: Wednesday, September 21, 2022 4:15 PM
To: FPC-Pascal users discussions 
Cc: Travis Siegel ; Jean SUZINEAU 

Subject: Re: [fpc-pascal] mciSendString with long file names

Adding a backslash (\) before each space should do the job nicely.  I have had similar 
issues on linux and windows with some commands, and adding the escape characters to the 
filename almost always fixes the problem.  The only time it didn't, was when the filename 
started with a dash "-" character.  Otherwise, the backslash always works for 
me.

On 9/20/2022 4:16 PM, Jean SUZINEAU via fpc-pascal wrote:
May be by escaping the spaces with ^ ?
Something like:  MyFileName:= StringReplace(MyFileName, ' ', '^ ', 
[rfReplaceAll]);
^ is the escape char for cmd.exe but may be it is active in this context too ?
Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit :
I just tried it that way:
Var
pcmd: String;
MyFileName: String;
  
pcmd:='play "'+MyFileName+'"'+#0;

mciSendString(@pcmd[1],Nil,0,0);
  




___
fpc-pascal maillist  -  mailto:fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] mciSendString with long file names

2022-09-21 Thread Travis Siegel via fpc-pascal
Adding a backslash (\) before each space should do the job nicely.  I 
have had similar issues on linux and windows with some commands, and 
adding the escape characters to the filename almost always fixes the 
problem.  The only time it didn't, was when the filename started with a 
dash "-" character.  Otherwise, the backslash always works for me.



On 9/20/2022 4:16 PM, Jean SUZINEAU via fpc-pascal wrote:


May be by escaping the spaces with ^ ?

Something like:  MyFileName:= StringReplace(MyFileName, ' ', '^ ', 
[rfReplaceAll]);


^ is the escape char for cmd.exe but may be it is active in this 
context too ?


Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit :


I just tried it that way:

Var

pcmd: String;

MyFileName: String;

pcmd:='play "'+MyFileName+'"'+#0;

mciSendString(@pcmd[1],Nil,0,0);




___
fpc-pascal maillist  -fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get highest element of a StringList

2022-09-10 Thread Travis Siegel via fpc-pascal
But, if that (eventually) leads to the highest one, and that's all 
that's desired, why not just use the whole expression variable := 
pred(f.Count) instead of the whole loop?


Wouldn't that accomplish the same thing?

Why the loop?


On 9/10/2022 3:44 PM, Thomas Kurz via fpc-pascal wrote:

If you just don't like the "-1" for readability, you might also wan't to 
consider using

for i := 0 to Pred(f.Count) do ...


- Original Message -
From: Thomas Kurz via fpc-pascal 
To: 'FPC-Pascal users discussions' 
Sent: Saturday, September 10, 2022, 21:37:34
Subject: [fpc-pascal] Get highest element of a StringList

Try this (note the "modeswitch"):

program Project1;

{$modeswitch typehelpers}

uses
   Classes,
   SysUtils;

type TStringListHelper = class helper for TStringList
   function High: NativeInt;
end;

function TStringListHelper.High: NativeInt;
begin
   Exit (Self.Count-1);
end;

var
   f: TStringList = nil;
   i: Integer;

begin
   f := TStringList.Create;
   f.Add ('hallo');
   f.Add ('welt');
   f.Add ('!');
   for i := 0 to f.High do Writeln (f[i]);
   FreeAndNil (f);
end.





- Original Message -
From: James Richters via fpc-pascal 
To: 'FPC-Pascal users discussions' 
Sent: Saturday, September 10, 2022, 19:57:51
Subject: [fpc-pascal] Get highest element of a StringList

This Helper sounds like a nice way to do it.  I need the numerical index of
the loop so this would be more straight forward.
Would I then do something like :
For I:= 0 to MyStringList.High Do
?

When I try to add the Type statement:
type TStringListHelper = class helper for TStringList function High:
NativeInt; end;
I getError: Identifier not found "class"

I have the Classes unit.  Is there something else I am missing?

James


Another alternative would be declaring a helper:
type TStringListHelper = class helper for TStringList function High:

NativeInt; end;


function TStringListHelper.High: NativeInt; begin
  Exit (Self.Count-1);
end;

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Cross-compiler for ARM64 on Windows available?

2022-06-23 Thread Travis Siegel via fpc-pascal
There actually is a 64-bit version of xp, but it's not compatible with 
very much.  Apparently, it didn't have an emulator in it, so running 
32-bit software wasn't something it did by default.  I never did figure 
out if it could be made to run 32-bit software or not, I just gave up on 
it, (more precisely, the person I installed it for gave up on it), 
because everything they tried to install wouldn't work, because it 
wasn't 64-bit.


Even so, I have no idea if the FPC cross compiler would work on such a 
machine anyway, and I no longer have a machine on which I can test said 
version of windows anyhow, (come to think of it, I don't think I have 
the install disk for it anymore either), so that will have to remain a 
mystery.



On 6/21/2022 10:36 AM, Pierre Muller via fpc-pascal wrote:

Hello,

  this is normally a native aarch64-win64 compiler,
not a cross-compiler package to be installed on linux.

  Note however that, as stated below, this was never tested.
It will also not run on a Windows XP, unless
you have an aarch64-windows_XP, but I am not aware
of the existence of such machines.

Regards,

Pierre


Le 21/06/2022 à 11:14, Wolfgang Hubert a écrit :

Hi all,



Pierre Muler via fpc-pascal wrote:


You might also try this "completely untested" cross-installer:


ftp://ftp.freepascal.org/pub/fpc/snapshot/trunk/aarch64-win64/fpc-3.3.1.aarch64-win64.built.on.x86_64-linux.tar.gz 





Thank you for pointing me to this installer. Since I am a Windows XP 
user

and also blind, it would be too much effort for me to install a Linux
machine or compile the compiler myself. I would rather wait until a 
compiler

for the Windows host is available.



If anyone has one, please let me know.



Regards,



Wolfgang

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Getting Last User Input reliably

2021-12-03 Thread Travis Siegel via fpc-pascal
If there's some sort of a configuration file, just write out the 
time/date info at the time of leaving the input, then when that routine 
gets called again, grab the current time/date, and perform a 
comparison.  That should allow you to bypass any roll overs of any kind 
(unless it goes past the operating system's time keeping abilities), 
which isn't likely.



On 12/3/2021 10:30 AM, Luca Olivetti via fpc-pascal wrote:

El 3/12/21 a les 14:52, James Richters via fpc-pascal ha escrit:
I'm trying to get the time lapsed since the last user input with 
keyboard or

mouse on a Windows PC.  For this I am doing:

GetLastInputInfo(Last_Input_Info);
IdleTime:= (GetTickCount - Last_Input_Info.dwTime) DIV 1000;


I was going to suggest

IdleTime:= DWORD(GetTickCount - Last_Input_Info.dwTime) DIV 1000;


but then I saw


On top of all this, I need to allow for the
possibility that there was no user input for more than 25 days.. 
which is
quite likely. 


so that's not going to work, sorry. I'm using the above for short 
intervals and it works in spite of the rollover (unless you enabled 
overflow checking, but that's another issue).


Bye

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-16 Thread Travis Siegel via fpc-pascal


On 10/16/2021 6:06 PM, Bo Berglund via fpc-pascal wrote:

Meanwhile the strace outputs stuff like this to the screen:
strace: Process 6360 attached
strace: Process 6361 attached
strace: Process 6362 attached
strace: Process 6363 attached
strace: Process 6364 attached
strace: Process 6365 attached
strace: Process 6366 attached
strace: Process 6367 attached
strace: Process 6368 attached
strace: Process 6369 attached
strace: Process 6370 attached
strace: Process 6371 attached
strace: Process 6372 attached

I don't understand what this means either

It looks like your application is spawning additional processes. If it's 
supposed to do that, then all is well.  If it isn't supposed to do that 
when it's idling, then you have some troubleshooting to do. :)



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to list IP and MAC of network adapters on Windows?

2021-09-10 Thread Travis Siegel via fpc-pascal
I don't know how much it will help, but windows has a similar command to 
linux ifconfig, only on windows it's called ipconfig.


Hope this helps.


On 9/10/2021 3:03 AM, Bo Berglund via fpc-pascal wrote:

Is there a way to enumerate the active adapters on a Windows computer with their
IPv4 and MAC addresses?

I am trying to convert a Linux reporting script to Windows, but I have a hard
time finding a suitable Windows command. The script uses common Linux commands
and tools to get the eth0 and wlan0 data (IPv4 and MAC addresses) and then to
POST it to my website mailer (php script) via curl. See below.

I have curl on Windows too so once the data are found the same command can be
used here as well, but the network info extraction seems to be a lot harder.

So I figured I could write a small FPC command line tool to extract this
information and use it in the batch file.

But is there some such call available in FPC or standard packages like LNet or
similar?

On Linux I can do this in the bash script:

MyName=$(hostname)
IPAddr=$(ifconfig eth0|grep "inet "|sed 's/ *inet //;s/ .*//')
IPAddrWiFi=$(ifconfig wlan0|grep "inet "|sed 's/ *inet //;s/ .*//')
IPMac=$(ifconfig eth0 | grep -Eo ..\(\:..\){5})
IPMacWiFi=$(ifconfig wlan0 | grep -Eo ..\(\:..\){5})

I don't believe there is a similar command line way on Windows, so therefore I
ask for a FPC way of getting it.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Hello, new Pascal programmer. had a question!

2021-08-31 Thread Travis Siegel via fpc-pascal
Although not likely in this case, I am visually impaired, use a screen 
reader, and find the Lazarius IDE nearly unusable.  Of course, I've not 
touched it in years, because my first attempt at using it failed 
miserably, so for me, I simply use notpad, pico, nano, or text edit 
(depending on what platform I'm using), and simply compile from the 
command line for all of my pascal work. Possibly, the original poster is 
facing a similar challenge, and only wants to learn console programming, 
to keep things simpler. As already mentioned, OOP isn't really that 
simple to wrap your brain around, especially if you're a new programmer, 
and don't have the framework already built to understand how it all works.


I'd honestly love to use an IDE for programming, as it would cut down on 
the amount of manual work required to get things done, but there are 
precious few that work well with screen readers, and so generally we're 
reduced to using text editors, and manual compiling.  Nothing wrong with 
that method, it works, it just isn't as efficient as it might otherwise be.


Powerbasic has a decent IDE, and I'll sometimes use that when powerbasic 
is required for a project, but I've gotten so used to command line and 
text editors, I rarely even bother with IDEs, even when I know they work.


Powerbasic, FPC, java, python, gcc, and G++ are the languages I use most 
often, and I think I'd be hard pressed to find something I'd be 
comfortable with using all of them with a single IDE anyway, so I just 
don't bother.



On 8/31/2021 9:52 AM, geneb via fpc-pascal wrote:

On Tue, 31 Aug 2021, Liam Proven via fpc-pascal wrote:


Plain old FreePascal is approachable. Object Pascal is deeply
intimidating, and I'm not sure it's worth the entry price.



Liam, I think you're mixing the language with the framework.

I'll be the first person to agree with you that doing a gui 
application in Delphi (and realistically, any RAD environment) can be 
intimidating if you don't know that you're looking at "event driven 
programming" vs "procedural programming"  With a Delphi/VB/Etc GUI 
application, /everything/ (for the most part) is kicked off by an 
event of some kind. A mouse movement, button click, etc.  This can be 
painfully confusing - it was for me when I started working with VB 3.0 
when it was released (I'd skipped VB DOS & 2.0).


You can easily write procedural programs in Delphi, but you have to 
create a "console" project first in order to do that.  The same holds 
true for FPC, but FPC's default is console.


For the OP, if they would like to use Lazarus, they just need to make 
sure that when they create a new project, that it's a console mode 
project.


Make sense?

g.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Will the size of an executable depend on the uses clause

2021-06-17 Thread Travis Siegel via fpc-pascal
Heh, how very cool.  I wasn't aware powershell could do such things.  
All kinds of new things learned in this thread.  Thanks for that.



On 6/17/2021 5:08 AM, Jean SUZINEAU via fpc-pascal wrote:

10 kb of Powerbasic ... you're cheating, it's pascal here ;-)
You can do this with just 1kb of PowerShell ...
( may be Pascal script could even be shorter ...)

File uptime.ps1 :

$MethodDefinition = @"
[DllImport("kernel32")] public extern static UInt64 GetTickCount64();
"@

$Kernel32 = Add-Type -MemberDefinition $MethodDefinition -Name 
'Kernel32' -Namespace 'Win32' -PassThru


#milliseconds
$tc= $Kernel32::GetTickCount64()

# seconds
$t= ($tc-$tc % 1000)/1000
$s= $t%60

# minutes
$tm=($t-$s)/60
$m= $tm % 60

#hours
$th=($tm-$m)/60
$h=$th % 24

#days
$d=($th-$h)/24

$Result="{0:d2}:{1:d2}:{2:d2}" -f $h,$m,$s
if ($d -ne 0)
  {
  $Result= "{0} {1}" -f $d,$Result
  }
Write-Host $Result

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Will the size of an executable depend on the uses clause

2021-06-16 Thread Travis Siegel via fpc-pascal
Thanks for the sample.  For what it's worth, I got the executable down 
to just 10K using powerbasic version 6,  I suspect that's as small as it 
can get, since I did have to include a winbase.inc that comes with the 
compiler to get the function call of the GetTickCount64 call.  But then 
again, I cheated a bit by only having a single print statement where I 
formatted the output to my liking by simply using semicolons to string 
the various pieces of information together.


Powerbasic isn't cross platform, but it does consistently produce the 
smallest executables I've ever seen in the windows environment, and I've 
been using it for more than 20 years.


I do use fpc when I need cross platform capabilities though, so there is 
that.



On 6/16/2021 5:49 PM, Jean SUZINEAU via fpc-pascal wrote:

My best score is 67 kb after strip -s with the code below ... ;-)

Of course it will not work on every  version of Windows.

program uptime;

function GetTickCount64: QWord; stdcall; external 'kernel32.dll';

function _2d( _i: Integer): String;
begin
 Str( _i, Result);
 if Length(Result) < 2 then Result:= '0'+Result;

end;

function FormatUpTime( _tc: QWord): String;
var
   t, d, h, m, s: Integer;
   sd: String;
begin
 t:= _tc div 1000;
 s:= t mod 60;
 m:= (t div 60) mod 60;
 h:= (t div 3600) mod 24;
 d:= (t div 86400);

 Result:= _2d(h)+':'+_2d( m)+':'+_2d( s);
 if 0 = d then exit;

 Str( d, sd);
 Result:= sd+' '+Result;
end;

begin
 WriteLn( FormatUpTime( GetTickCount64));
end.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Can a console app running as Linux service restart itself?

2021-05-20 Thread Travis Siegel via fpc-pascal
If you didn't have the configuration setup as required, you could still 
spawn a second process to kill and restart your process as well, this 
works too, but Michael's suggestion is probably much cleaner, and in all 
likelihood, is probably the preferred method, but I know folks struggle 
with the whole system process configuration issue, so some go the other 
route just for simplicity sake.



On 5/20/2021 12:03 PM, Bo Berglund via fpc-pascal wrote:

On Thu, 20 May 2021 17:13:16 +0200 (CEST), Michael Van Canneyt via fpc-pascal
 wrote:



On Thu, 20 May 2021, Bo Berglund via fpc-pascal wrote:


On Thu, 20 May 2021 14:52:47 +0200 (CEST), Michael Van Canneyt via fpc-pascal
 wrote:



On Thu, 20 May 2021, Bo Berglund via fpc-pascal wrote:


I would like my service application to restart itself once per 24 hours, but
only when nothing else is going on. So the application itself would know this
but how can I make it restart itself (as the service)?

Just exit ?
If you configured systemd to start your app correctly it will restart it.


Is it as simple as that? Here is my service file:

[Unit]
Description=SSRemote Server
Wants=network.target
After=syslog.target network-online.target

[Service]
Type=simple
ExecStart=/agi/ssremote/bin/SSRemoteServerLx
Restart=always  #<== This
RestartSec=10   #<== And this
KillMode=process
User=pi

[Install]
WantedBy=multi-user.target

Do these 2 marked lines mean that if the service application just exits (with no
exit code) systemd will restart it after 10 seconds?

Yes.


And:
Right now I am running it as user pi as shown above, is there some reason I
should run it as root instead?

Running as root is not recommended. You can do it, but I would not.


Thanks Michael, much obliged!
Makes things so much simpler. Just exit at the appropriate time. :-)


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to find where my app consumes CPU?

2021-05-19 Thread Travis Siegel via fpc-pascal


On 5/19/2021 9:53 AM, Henry Vermaak wrote:

On Wed, 19 May 2021 at 14:36, Travis Siegel via fpc-pascal
 wrote:

No doubt your sleep code works just fine.

I'm not saying the sleep command doesn't work.

I'm saying the sleep command doesn't release unused cpu cycles for other
threads/programs to use.

No, fpc uses nanosleep() inside sysutils.sleep() which is documented
to suspend execution (i.e. no busy waiting) so the kernel will switch
to another thread/process.


That's useful information.

I did run across nanosleep in my digging, but I wasn't aware the sleep 
command called it.


I'm still a (little) puzzled though, why there are so many different 
suspend/sleep modes in linux kernel implementations. They appear to do 
similar things, so perhaps it's just incremental differences, depending 
on what's trying to be accomplished, or maybe, under the hood, they all 
call the same routines, I can't really say, but it sure has been 
educational digging around to find answers.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to find where my app consumes CPU?

2021-05-19 Thread Travis Siegel via fpc-pascal

No doubt your sleep code works just fine.

I'm not saying the sleep command doesn't work.

I'm saying the sleep command doesn't release unused cpu cycles for other 
threads/programs to use.


Apparently, if you want that behavior, you need to yield the cpu time 
your process would otherwise take, that's done with a different kernel 
function than sleep.


Alexander hit the nail on the head though with his solution, so I'm 
satisfied that the original poster got what he needed, and I learned 
something new about linux processes as well, which makes for a good all 
around solution.


On 5/19/2021 6:02 AM, Mattias Gaertner wrote:

On Tue, 18 May 2021 18:37:38 -0400
Travis Siegel via fpc-pascal  wrote:


Apparently, you can release cpu cycles, but it's with the sched_yield
(section 2 in the man pages), not the sleep command on linux.

What sleep command are you referring to?
What do you mean with cpu cycles?

Sleep works pretty well under Linux:

uses sysutils;
var i: integer;
begin
   for i:=1 to 1 do sleep(1);
end.

time ./test1

real0m10,791s
user0m0,021s
sys 0m0,018s

Mattias

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to find where my app consumes CPU?

2021-05-18 Thread Travis Siegel via fpc-pascal
Apparently, you can release cpu cycles, but it's with the sched_yield 
(section 2 in the man pages), not the sleep command on linux.


So, apparently, the sleep is still using full system recourses, even 
though it's just waiting.  You apparently have to release cpu time with 
the sched_yield command to make it actually give up time slices., and 
even then, it's not clear it will actually do so, the description claims 
it simply moves your application to the end of the cue, which doesn't 
really give away it's cpu cycles, just changes it's location in the 
execution order.


Perhaps it will help with the cpu usage though, I've not done any 
testing to see how (or not) it affects cpu.



On 5/18/2021 6:29 PM, Bo Berglund via fpc-pascal wrote:

On Tue, 18 May 2021 21:40:15 +, Alexander Grotewohl via fpc-pascal
 wrote:


if it's waiting on keyboard input you might be better off using select() for
that instead of looping and checking for keyboard input each go around.

sleep() might already do something similar with a zero timeout but even that
would probably be insufficient

As I tried to explain at the start of this thread my application runs as a
*systemd service* on Linux, so there is absolutely no keyboard input.

The main program looks like this after initializations etc:

   try
 try
   bSTerm := False;
   bSInt := False;
   bsHup := False;
   {$IFDEF UNIX}
   fpSignal(SigTerm, SignalHandler(@handleSignal));
   fpSignal(SigInt, SignalHandler(@handleSignal));
   fpSignal(SigHup, SignalHandler(@handleSignal));
   {$ENDIF}

   Debug_Writeln('Enter eternal loop');
   FLogServ.StdLog('Enter eternal loop');

   While not (bSTerm or bSInt or bsHup) do
   begin
 //Here is where the server runs as defined elsewhere
 //Eternal loop to wait for system messages
 Sleep(1); //To not hog the CPU
 CheckSynchronize; //To get thread comm working
   end;

   Debug_Writeln('Exit eternal loop');
   FLogServ.StdLog('Exit eternal loop');
 except
   on E: Exception do
   begin
 FLogServ.ExceptionLog('Unhandled exception: ' + E.Message);
   end;
 end;
   finally
 ShutdownServer;
   end;

As you can see it sits in the eternal loop until the system sends a "signal" to
it to stop. So systemd does that if I issue a sudo systemctl stop myservice and
this works fine.
Could this tiny loop consume 6-7% CPU cycles?



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to find where my app consumes CPU?

2021-05-18 Thread Travis Siegel via fpc-pascal
I'm not positive, but I'm pretty sure the sleep command in linux does 
not behave the same way it does in windows.


As you know, in windows, a sleep command (even if delivered with a 
parameter of 0) gives up time slices to other programs on the system.  
This does not appear to be the case on linux.


On linux, the sleep command simply suspends the process for the 
specified amount of time, but so far as I can tell, does nothing for 
unused cpu cycles.


I've done a little digging, but I can't find any way on linux to give 
away unused cpu cycles.


Perhaps the linux task switcher doesn't allow for this capability?


On 5/18/2021 3:59 PM, Bo Berglund via fpc-pascal wrote:

I have a pretty sizable console app written with Delphi 15 years ago but ported
to Linux using FreePascal (3.2.0) with Lazarus (2.0.12) as IDE. It runs as a
systemd service on a Raspberry Pi3.

Basically it is a scheduler, which checks every minute if there is a task to
run, otherwise it waits for the next minute to pass.

Meanwhile in another thread there is a TCP/IP socket server active for
communicating with the app over the network. So it is listening for incoming
connections.

This is working seemingly OK, but today when I checked the RPi I found using top
that it was running 11% CPU, which is strange because it has nothing to do at
the moment.

I have tried to be as conservative as possible regarding wait loops etc so in
such loops I always have a sleep() call, which in my Windows experience used to
stop excessive CPU usage.

So I was surprised to find the high CPU usage and now I am at a loss on how to
find *where* this is happening...

Any ideas on how to proceed?
Is there some Lazarus way to find this?
(But I cannot really run the application in service mode from within Lazarus...)



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Dependency of OpenSSL 1.0.2 still in FPC 3.2.0 on some platforms?

2021-05-17 Thread Travis Siegel via fpc-pascal
The -dev part of the package is necessary for the headers used for 
compiling, any target system running the finished product will not 
require the -dev version of the packages to be installed, since they 
won't be using the header files directly.



On 5/17/2021 6:20 PM, Bo Berglund via fpc-pascal wrote:

On Mon, 17 May 2021 23:20:16 +0200, gebylist via fpc-pascal
 wrote:


?Dne 17.05.2021 v 22:06 Bo Berglund via fpc-pascal napsal(a):

And that is what I have done, it is listed in uses of my mailsupport source file
as:
uses
Classes,
SysUtils,
smtpsend,
ssl_openssl, //<= Here
synautil,
mimemess,
mimepart;

Yet it is "not compiled"...

Very confusing.


It is because loading of ssl_openssl plugin failed. Have you installed
OpenSSL libraries on your RPi?

How is that done?
Is not openssl part of the Debian and derivatives Linux distros?

Well, I Googled and found a suggested remedy:
sudo apt install libssl-dev

After this was done I ran the exact same code in Lazarus debugger and this time
it got through and the emails were delivered!


Check function |InitSSLinterface in ssl_openssl_lib unit. I personally
never test ssl_openssl on RPi, maybe some error is here.|


Follow-on question:
Do I have to install dev packages like this on the  target system as well (one
where the application is not going to be built on?

Or is it only needed to be on the *development* system?



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Dependency of OpenSSL 1.0.2 still in FPC 3.2.0 on some platforms?

2021-05-06 Thread Travis Siegel via fpc-pascal


On 5/6/2021 7:54 AM, Bo Berglund via fpc-pascal wrote:



On Wed, 5 May 2021, Nico Neumann via fpc-pascal wrote:


Indy has support for OpenSSL 1.1.1, just not officially (yet).
See https://github.com/IndySockets/Indy/pull/299


THe SMTP server I use requires SSL on port 465.
I have only ever used Indy for things like this.

Use package laz_synapse (in online package manager), unit smtpsend.

I'm using it in FPC and Delphi even today.
In general, it works a lot easier/simpler than Indy.

Unless you need some weird/outdated protocols,
I highly recommend Synapse over Indy.


So only if the emailing synapse is guaranteed GUI-free can I use it.

I may even use some external program for mailing by using TProcess to run it
But what? THere used to be something called sendmail or similar in Linux but
right now I cannot see it on my boxes. And I am uncertain if it can do SSL
logins and accept attachment files.

For some reason, sendmail has fallen out of favor, (likely because of 
it's conceived difficult setup), and most linux distros now use postfix, 
which in my opinion isn't any easier to configure, but it does allow for 
a wider range of options.


If you check your linux boxes, you'll probably see postfix as the mta, 
and it can indeed be called to transfer mail from programs. I don't have 
any examples of this, but the documentation says it can be done.  I 
don't know if there's another program application programmers use, but 
with some digging, you should be able to get it to work.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Abstract classes ignored

2021-04-18 Thread Travis Siegel via fpc-pascal


On 4/18/2021 11:55 AM, Graeme Geldenhuys via fpc-pascal wrote:

On 17/04/2021 10:09 pm, Sven Barth via fpc-pascal wrote:

but Delphi compatbility is more
important here, thus the default is a warning and not an error.

How is this beneficial? The compiler should help the developer, but here
it was decided that it's beneficial for the program to crash at runtime,
because follow the broken Delphi compiler is more important! *shrug*

Such decisions really make me worry about the future of FPC. It ends up
being NO better than Delphi, so why bother using FPC then. Stick to
Delphi instead.


If you're willing to pay for me to obtain a delphi license, then I'd 
happily switch.  Seeing as how they charge over a thousand dollars even 
during their supposed sales, I have no interest in spending that kind of 
money for an environment that FPC offers for free. That means I don't 
have to spend my limited income on a license for a program I use a few 
times a year.


Admittedly, part of the reason I use it so rarely is because I really 
need to dig into it's gui and tcp capabilities (I program from the 
ocmmand prompt, but being able to generate gui screens on the fly would 
be nice).  I know Delphi can do this, but the last time I asked them 
about pricing, they told me it'd cost $1000 for just delphi 7, and that 
only costed $995 when it first came out, nearly 20 years ago.  I refuse 
to support that kind of price gouging, even if I could afford it.


But, as I said, if you're willing to foot the bill, I'd happily use it, 
as it does indeed have (some) advantages.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Formatting Question

2021-04-03 Thread Travis Siegel via fpc-pascal
You can always convert the number to a string, then format it 
accordingly.  It's probably not the solution you want, but it will do 
the trick.


On 4/3/2021 11:43 AM, James Richters via fpc-pascal wrote:

I'm looking for a way to format numerical data in a string so that everything 
ends up aligned by the decimal point.
I've been trying to use the Format() function but I don't see how to do what I 
am looking for...
then again I don't really understand the format() function, and most of the 
examples show exponents, which I do not want.

My input variables are all Doubles and I want the result to be padded with 
spaces before the decimal point if needed and
trailing zeros to be replaced with spaces so that it always is the same total 
width and the decimal point is always in the same position.
The string will later be either output to the console or saved into a file.  It 
will only ever be viewed with a fixed width font.

Does anyone have any idea if this can be done with any function included with 
FPC or am I going to write my own function to do this?

James


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Windows Defender considers fp.exe a malicious program

2021-02-12 Thread Travis Siegel via fpc-pascal
How it's done in FPC I don't know, but in other language tools I use, it 
requires a resource file with spefic information in it.  I can never 
remember all the details, so I have to keep a template resource file 
around with the required information in it, and change it for each 
program  work on.


In general I don't bother with the resource file during testing, but 
when I release a full version, I apply the resource file to the 
executable, and that usually takes care of the issue.


I've also noticed that if you have any timing routines in your code, it 
tends to get flagged by virus scanners.  No clue why, but I've run afoul 
of that issue more than once.


On 2/12/2021 4:49 PM, James Richters via fpc-pascal wrote:


How does one sign an executable?

*From:*fpc-pascal  *On Behalf 
Of *Dmitry Boyarintsev via fpc-pascal

*Sent:* Friday, February 12, 2021 4:28 PM
*To:* FPC-Pascal users discussions 
*Cc:* Dmitry Boyarintsev 
*Subject:* Re: [fpc-pascal] Windows Defender considers fp.exe a 
malicious program


Are signed executables subject to anti-virus inspection?


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TurboVision is reborn as FOSS (again)

2020-12-23 Thread Travis Siegel via fpc-pascal


On 12/22/2020 11:43 AM, Markus Greim via fpc-pascal wrote:

Wow..

Programming languages I worked with in the last 40 years:

12. SPIN


When you say spin, I'm assuming you're talking about the parallax 
propeller boards programming language.  The propeller 2 is coming out 
shortly (already out for early adopters), and I am anxiously awaiting 
the day I can get my hands on one.  I've built all kinds of projects 
with the propeller 1 board, the first of which was an FM radio.


But, to put this (somewhat) on topic, I've been wondering how 
complicated it would be to port FPC to the propeller 2 board, since they 
now have GCC ported, I would absolutely love to be able to program the 
propeller boards in pascal.  I do have a couple of their java stamps, 
those are interesting, and they do have a micro python that can be run 
on the propeller 2 boards, so adding pascal should be doable, I'm just 
not sure how much work it would take, but it would be nice to have 
another language to add to the mix.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TurboVision is reborn as FOSS (again)

2020-12-21 Thread Travis Siegel via fpc-pascal
I don't know what non native english speakers are taught, nor can I 
address the folks across the pond, but here in the Us at least, has 
denotes currently exists, while had indicates past tense, I.E. no longer 
exists.  Combining the two is where it gets dicy, and is generally 
avoided for syntactical reasons.


On 12/21/2020 4:17 AM, Nikolay Nikolov via fpc-pascal wrote:



On 12/21/20 10:42 AM, Markus Greim wrote:

FPC has had a Turbo Pascal-like console IDE for many years...

"has had" ?

AKAIK "has"

I still used it yesterday.


English is not my native language, but I think "has had" means it 
still has it. If I had said "had" instead of "has had", it would mean 
it had it in the past, but no longer has it. Please correct me if I'm 
wrong.


Nikolay



Grüße

Markus
Sent from Front
On December 20, 2020, 7:33 PM GMT+1 fpc-pascal@lists.freepascal.org 
 wrote:



On 12/19/20 6:35 PM, Liam Proven via fpc-pascal wrote:


> https://github.com/magiblot/tvision 


>
> Someone enterprising could make a TurboPascal clone out of FPC. :-)
>
Meh. FPC has had a Turbo Pascal-like console IDE for many years. It 
uses Free Vision, which is a pascal port of the C++ version of 
Turbo Vision (because Borland didn't release their Pascal version 
under a free/open source license).


https://wiki.freepascal.org/Free_Vision#Turbo_Vision 



Nikolay

___
fpc-pascal maillist - fpc-pascal@lists.freepascal.org 

https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Thread problem

2020-09-06 Thread Travis Siegel via fpc-pascal

I'm not sure it works properly on windows.

When I modify this to start two threads, and print out messages based on 
their start/stop times, as well as a message inside the thread, I get 
both ending messages before I get only a single printout from within the 
threaded function.  This seems to indicate windows isn't starting two 
threads, though I don't have a clue how to verify this.


Just thought I'd add fuel to the fire here. :)


On 9/6/2020 1:00 PM, Paul Renaud via fpc-pascal wrote:

I
Hello,

I'm having a problem with the OS/2 version of the compiler.

This simplified version of my program keeps generating an exception
when compiled and run in EComStation 1.2, OS/2 versions 4.5 and 4
but runs fine when compiled for Windows.

Program Test1( Input, Output );

{$S+}

  Const
    StackSize = 100;

    Max_Array = 5000;

  Type
    Data_Array = packed array[ 0 .. Max_Array ] of LongInt;

  Function MyThread( P: Pointer ): PtrInt;
    Var
  Data: Data_Array;
  Indexer: LongInt;
    Begin
  MyThread := 0;
  For Indexer := 1 to Max_Array do
    Data[ Indexer ] := 0;
    End;

  Var
    Handle: LongWord;
    My_Result: LongInt;
  Begin
    WriteLn( 'Test1 starting' );
    My_Result := BeginThread( @MyThread, Nil, Handle, StackSize );

    My_Result := WaitForThreadTerminate( Handle, 0 );
    WriteLn( 'Test1 finished' );
  End.

The error generated is...

SYS1808:
The process has stopped.  The sofware diagnostic
code (exception code) is  0005.

the command I used to compile it is:

fpc Test1.pas -Se -gl

This exception appears to be generated before my thread gets control,
so I can't install my own exception handlers to intercept it.

Any help would be appreciated.
Thanks,
Paul.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Archive libraries

2020-08-20 Thread Travis Siegel via fpc-pascal
There's also bzip2 and chm (though I don't really consider that an 
archive format).  I don't see anything for arj or rar though, both of 
which I use extensively.  Perhaps I'll see what I can do about those 
two.  arj should be easy enough, since unarj source is available, it 
should be convertable.  Having not worked on such a project though, I 
haven't a clue how much work it will be, but what the heck.


On 8/20/2020 11:10 AM, Darius Blaszyk via fpc-pascal wrote:

Hi all,

To my delight I found out that FPC actually provides quite a few 
archive handling libraries out of the box. Thanks to all that have 
contributed to that! So far I found:


* tar
* tar.gz
* zip

Are there any other formats out there that I could use like out of the 
box?


TIA!

Darius

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal