[fpc-pascal] Repeat result in random

2016-11-27 Thread Tony
Here is a short program to print 10 random numbers:

program testrandom;

var
  i: Integer;

begin
  Randomize;

  for i := 1 to 10 do
WriteLn(Random);
end.
  

If I compile and run this program using FPC 3.0.0 on Ubuntu 16.04
x86_64 I get the following:

$ /usr/lib/fpc/3.0.0/ppcx64 testrandom
Free Pascal Compiler version 3.0.0+dfsg-2 [2016/01/28] for x86_64
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling testrandom.pp
Linking testrandom
/usr/bin/ld.bfd: warning: link.res contains output sections; did you
forget -T? 14 lines compiled, 0.1 sec
$ ./testrandom
 9.34558931970968842506E-0001
 7.37956080120056867599E-0001
 9.57959748106077313423E-0001
 8.50854847114533185959E-0001
 1.81509985821321606636E-0001
 6.14049500785768032074E-0001
 9.82306003570556640625E-0002
 3.28659117221832275391E-0001
 3.45761539181694388390E-0001
 6.87781326007097959518E-0001

All well and good.  However, if I compile using FPC 3.1.1 from svn I
get the following:

$ /usr/local/lib/fpc/3.1.1/ppcx64 testrandom
Free Pascal Compiler version 3.1.1 [2016/11/26] for x86_64
Copyright (c) 1993-2016 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling testrandom.pp
Linking testrandom
14 lines compiled, 0.1 sec
$ ./testrandom
 3.31493919249624013901E-0001
 3.31493919249624013901E-0001
 5.16012400388717651367E-0001
 2.02815276337787508965E-0001
 5.62052882276475429535E-0001
 9.15243660099804401398E-0001
 7.51263931626453995705E-0001
 9.20306718209758400917E-0001
 9.01774314232170581818E-0001
 7.98331435071304440498E-0001

The first two random numbers are always equal.

Am I missing something or is this a bug in 3.1.1?

Tony

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


[fpc-pascal] Readln a password

2016-11-27 Thread Adriaan van Os
I wonder what the recommended way is to readln a password from console, as a standard Readln echoes 
the password.


1. SetConsoleMode seems to be Windows-specific

2. On Mac OS X, a loop with a Crt.ReadKey until char(13) works in Terminal.app, but behaves strange 
in the Xcode Console window (more precise, uses Crt doesn't seem to be compatible with the Xcode 
Console)


3. On Mac OS X, executing '/bin/stty -echo' gives an error message 'stty: stdin isn't a terminal' 
(both in Terminal.appand in the Xcode Console window)


4. I experimented with '/usr/bin/read -s -p Password:' but couldn't get it 
working from FPC.

Regards,

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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread James Richters
Here is how I read passwords... it generates a random character and displays
that so someone looking over your shoulder things those characters are the
password
It uses readkey which does not display on the screen, one character at a
time

Function Readpw:String;
Var
   Pwstring : String;
   pwchar   :Char;
Begin
   Randomize;
   Pwstring:='';
   Repeat
  Pwchar:=readkey;
  If PwChar<>#13 Then
 Begin
pwstring:=pwstring+Pwchar;
Write(chr(Random(77)+33))
 End;
   until pwchar=#13;
   Readpw:=pwstring;
end;

-Original Message-
From: fpc-pascal-boun...@lists.freepascal.org
[mailto:fpc-pascal-boun...@lists.freepascal.org] On Behalf Of Adriaan van Os
Sent: Sunday, November 27, 2016 8:24 AM
To: FPC-Pascal users discussions 
Subject: [fpc-pascal] Readln a password

I wonder what the recommended way is to readln a password from console, as a
standard Readln echoes the password.

1. SetConsoleMode seems to be Windows-specific

2. On Mac OS X, a loop with a Crt.ReadKey until char(13) works in
Terminal.app, but behaves strange in the Xcode Console window (more precise,
uses Crt doesn't seem to be compatible with the Xcode
Console)

3. On Mac OS X, executing '/bin/stty -echo' gives an error message 'stty:
stdin isn't a terminal' 
(both in Terminal.appand in the Xcode Console window)

4. I experimented with '/usr/bin/read -s -p Password:' but couldn't get it
working from FPC.

Regards,

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

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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread James Richters
I would like to mention that if you store your password in a constant like
this:
const
   password='mypassword' 

then if someone edits your exe file with any text editor, your password will
be in there as text and easy to find.

I have used this method to get around this...  I store a huge string like
this:
   Emailinfo1=
'êE1669>)d2LU`j=LBK;=]=2mWX3d]jei/m*HzY:`/74F8H0,0/,.*,-0+--*/*-,*+-++,-,/7(
L36dLUB/IS9(d537A:A1j:VbipIYNV=JfB3{[_>pjuPGa5SXX`ko7}sv]/M*m[KSjR[UP.^3mailto:fpc-pascal-boun...@lists.freepascal.org] On Behalf Of Adriaan van Os
Sent: Sunday, November 27, 2016 8:24 AM
To: FPC-Pascal users discussions 
Subject: [fpc-pascal] Readln a password

I wonder what the recommended way is to readln a password from console, as a
standard Readln echoes the password.

1. SetConsoleMode seems to be Windows-specific

2. On Mac OS X, a loop with a Crt.ReadKey until char(13) works in
Terminal.app, but behaves strange in the Xcode Console window (more precise,
uses Crt doesn't seem to be compatible with the Xcode
Console)

3. On Mac OS X, executing '/bin/stty -echo' gives an error message 'stty:
stdin isn't a terminal' 
(both in Terminal.appand in the Xcode Console window)

4. I experimented with '/usr/bin/read -s -p Password:' but couldn't get it
working from FPC.

Regards,

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

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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread Adriaan van Os

James Richters wrote:

Here is how I read passwords... it generates a random character and displays
that so someone looking over your shoulder things those characters are the
password
It uses readkey which does not display on the screen, one character at a
time


Thanks for your reply, but please see note 2. of my original message.

Regards,

Adriaan van Os

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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread Dmitry Boyarintsev
On Sun, Nov 27, 2016 at 8:24 AM, Adriaan van Os  wrote:

> I wonder what the recommended way is to readln a password from console, as
> a standard Readln echoes the password.
>
> 1. SetConsoleMode seems to be Windows-specific
>

I'd think you want something simlar on unix.
Take a look at man 4 termios
specifically at local flag named "ECHO".
you want to disable it via tcsetattr()  (TermIO unit)

thanks,
Dmitry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Readln a password

2016-11-27 Thread Tomas Hajny
On Sun, November 27, 2016 15:49, Adriaan van Os wrote:
> James Richters wrote:
>> Here is how I read passwords... it generates a random character and
>> displays
>> that so someone looking over your shoulder things those characters are
>> the
>> password
>> It uses readkey which does not display on the screen, one character at a
>> time
>
> Thanks for your reply, but please see note 2. of my original message.

Does the same limitation / issue apply for
Keyboard.GetKeyEvent/PollKeyEvent on Mac OS X?

Tomas


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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread Adriaan van Os

Dmitry Boyarintsev wrote:


I'd think you want something simlar on unix.
Take a look at man 4 termios
specifically at local flag named "ECHO".
you want to disable it via tcsetattr() Â (TermIO unit)


Thanks for the hint. I haven't yet tried it, but I would expect it to fail, as stty (see stty.c in 
GNU coreutils) calls tcsetattr and stty fails reporting 'stty: stdin isn't a terminal' .


Regards,

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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread Adriaan van Os

Tomas Hajny wrote:

Does the same limitation / issue apply for
Keyboard.GetKeyEvent/PollKeyEvent on Mac OS X?


To a lesser extent. It doesn't write "funny characters" to the Xcode Console window as "uses CRT" 
does, but still echoes typed characters. Like with "uses CRT", the problem doesn't occur in 
Terminal.app.


Regards,

Adriaan van Os

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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread Adriaan van Os

Dmitry Boyarintsev wrote:


I'd think you want something simlar on unix.
Take a look at man 4 termios
specifically at local flag named "ECHO".
you want to disable it via tcsetattr() Â (TermIO unit)


Thanks for the hint. I haven't yet tried it, but I would expect it to fail,as stty (see stty.c in 
GNU coreutils) calls tcsetattr and stty fails reporting 'stty: stdin isn't a terminal' .


No, it was my own fault. I were executing '/bin/stty -echo' with AssignStreams and then StdIn is 
indeed not a terminal, but a pipe. When I execute it normally, then stty does work, so I expect 
tcsetattr to work too.


So, we can now use Readln without echoing in Terminal.app. There is still echoing to the Xcode 
Console window, but let's assume that is a bug or limitation of Xcode.


Maybe something to add to the fpc runtime libs ?

Regards,

Adriaan van Os

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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread Michael Van Canneyt



On Sun, 27 Nov 2016, Adriaan van Os wrote:


Dmitry Boyarintsev wrote:


I'd think you want something simlar on unix.
Take a look at man 4 termios
specifically at local flag named "ECHO".
you want to disable it via tcsetattr() Â (TermIO unit)


Thanks for the hint. I haven't yet tried it, but I would expect it to 
fail,as stty (see stty.c in GNU coreutils) calls tcsetattr and stty fails 
reporting 'stty: stdin isn't a terminal' .


No, it was my own fault. I were executing '/bin/stty -echo' with 
AssignStreams and then StdIn is indeed not a terminal, but a pipe. When I 
execute it normally, then stty does work, so I expect tcsetattr to work too.


So, we can now use Readln without echoing in Terminal.app. There is still 
echoing to the Xcode Console window, but let's assume that is a bug or 
limitation of Xcode.


Maybe something to add to the fpc runtime libs ?


If you mean in a cross-platform way, I think we would welcome patches :)

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

Re: [fpc-pascal] Readln a password

2016-11-27 Thread James Richters
Shouldn't an extremely basic function like readkey be cross-platform?

-Original Message-
From: fpc-pascal-boun...@lists.freepascal.org
[mailto:fpc-pascal-boun...@lists.freepascal.org] On Behalf Of Michael Van
Canneyt
Sent: Sunday, November 27, 2016 12:07 PM
To: FPC-Pascal users discussions 
Subject: Re: [fpc-pascal] Readln a password



On Sun, 27 Nov 2016, Adriaan van Os wrote:

>> Dmitry Boyarintsev wrote:
>> 
>>> I'd think you want something simlar on unix.
>>> Take a look at man 4 termios
>>> specifically at local flag named "ECHO".
>>> you want to disable it via tcsetattr() Â (TermIO unit)
>> 
>> Thanks for the hint. I haven't yet tried it, but I would expect it to 
>> fail,as stty (see stty.c in GNU coreutils) calls tcsetattr and stty 
>> fails reporting 'stty: stdin isn't a terminal' .
>
> No, it was my own fault. I were executing '/bin/stty -echo' with 
> AssignStreams and then StdIn is indeed not a terminal, but a pipe. 
> When I execute it normally, then stty does work, so I expect tcsetattr to
work too.
>
> So, we can now use Readln without echoing in Terminal.app. There is 
> still echoing to the Xcode Console window, but let's assume that is a 
> bug or limitation of Xcode.
>
> Maybe something to add to the fpc runtime libs ?

If you mean in a cross-platform way, I think we would welcome patches :)

Michael.

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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread Jonas Maebe

On 27/11/16 18:54, James Richters wrote:

Shouldn't an extremely basic function like readkey be cross-platform?


It is, but the crt unit only works with (almost) fully functional 
terminal windows, and not with redirected or piped input/output (as used 
by Xcode).



Jonas

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


Re: [fpc-pascal] Readln a password

2016-11-27 Thread geneb

On Sun, 27 Nov 2016, Adriaan van Os wrote:

I wonder what the recommended way is to readln a password from console, as a 
standard Readln echoes the password.


Readln is wholly unsuited to the task.  You're better off writing a 
routine that gets input one character at a time.


g.

--
Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.
http://www.diy-cockpits.org/coll - Go Collimated or Go Home.
Some people collect things for a hobby.  Geeks collect hobbies.

ScarletDME - The red hot Data Management Environment
A Multi-Value database for the masses, not the classes.
http://scarlet.deltasoft.com - Get it _today_!
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] SysSetCtrlBreakHandler

2016-11-27 Thread Dmitry Boyarintsev
On Sun, Nov 27, 2016 at 12:07 PM, Michael Van Canneyt <
mich...@freepascal.org> wrote:
>
> If you mean in a cross-platform way, I think we would welcome patches :)
>
> On the subject of cross-platform console applications...

While working recently on converting libwebsockets header to FPC, I ran
into a need of adding Ctrl-Break handlers (used in sample apps).
I was actually surprised of the presence of SysSetCtrlBreakHandler function
in RTL.
But i was even more surprised it doesn't do anything useful (for console
application).

So here's the first patch for Windows
http://bugs.freepascal.org/view.php?id=31023

If this one is good (or made to the state, when it's good), I'm looking
into providing the same patches for linux and darwin.

thanks,
Dmitry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal