[fpc-pascal] [oldlinux]: STAT_IRWXG get chmod number
hello Is there anybody has worked with STAT_IRWXG ? http://www.freepascal.org/docs-html/rtl/oldlinux/index-2.html I need infos in order to get a function that get file permissions on linux system (like 0777, 0755...) best regards -- David Touzeau -- Linux Ubuntu Dapper 6.0.6 FreePascal-Lazarus,perl,delphi,php icq:160018849 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] representation of a number
Hi all I'm having some fun solving some programming problems in SPOJ (www.spoj.pl, very very cool, check it out). The thing is that is need to calculate some big fatorials (~100!). With FPC and the standard integer types I was unable to perform the correct calculations because 100! is bigger than the largest number which can be represented with those types. So I moved to the extended type and it worked quite well, performing correct calculations and giving correct results. I started wondering is this was a smart decision or if it is completely stupid (i'm new to programming competitions and stuff like that). The problem is that I'm unable to write the complete number on stdout. Using extended I could only use scientific notation, which the judge software does not seems to like. Question: what would be the correct way to write the number on screen without using scientific notation e.g.: 5! = 120 and not 5! = 1.2E+2? -- Daniel Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do. (Donald Knuth) Yes, technogeeks can be funny, even if only to each other. (http://www.boogieonline.com/revolution/science/humor/) Man is driven to create; I know I really love to create things. And while I'm not good at painting, drawing, or music, I can write software. (Yukihiro Matsumoto, a.k.a. ``Matz'') ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] [oldlinux]: STAT_IRWXG get chmod number
Is there anybody has worked with STAT_IRWXG ? http://www.freepascal.org/docs-html/rtl/oldlinux/index-2.html That is a legacy api. Better use Baseunix: I need infos in order to get a function that get file permissions on linux system (like 0777, 0755...) http://www.freepascal.org/docs-html/rtl/baseunix/fpaccess.html or via stat: http://www.freepascal.org/docs-html/rtl/baseunix/fpstat.html Note that you can make octal values using the notation. E.g. var i : integer; begin i:=770; writeln(i); end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] representation of a number
I'm having some fun solving some programming problems in SPOJ (www.spoj.pl, very very cool, check it out). The thing is that is need to calculate some big fatorials (~100!). With FPC and the standard integer types I was unable to perform the correct calculations because 100! is bigger than the largest number which can be represented with those types. So I moved to the extended type and it worked quite well, performing correct calculations and giving correct results. I started wondering is this was a smart decision or if it is completely stupid (i'm new to programming competitions and stuff like that). Keep in mind that the extended type has limited precision. It can contain large values, but does so by only remembering the upper +/- 18 digits, sign and exponent. If it is a content, I think they want you to calculate a number larger than the size of normal types is to force you to deal with it, and define your own arithmetic for very large numbers. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Pipe buffering, accessing C-style stdin/stdout
Dear list, I have been struggling for quite a while (that is weeks) to get proper pipe communication with a sublaunched program, using TProcess or straight pipe/fork/exec calls. This is under Mac OSX, but the problem should be similar under any Unix. The problem is the buffering. Using stdio, the data is stalled until the stdio buffers are full. This is a big problem. Two-way communication is impossible, and the user feedback is delayed. After a lot of googling and experimenting, I think I have managed to make it work, but only in C code, and I want it to run in Pascal. The key to make it work in C was to call setvbuf at the right time, to set the buffering mode for stdin/stdout. The problem with FPC is that I can't find any straightforward way to either get PFile-style stdin/stdout from the Text-style input/output (surely there is a connection?), or get the C globals. I have searched through the fpc and Lazarus sources after the definitions and possible solutions, tried all ways I can find, but have not succeeded yet. But surely someone else has ran into this problem? Shouldn't simply TProcess have unbuffered or line-buffering as default? /Ingemar ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pipe buffering, accessing C-style stdin/stdout
After a lot of googling and experimenting, I think I have managed to make it work, but only in C code, and I want it to run in Pascal. The key to make it work in C was to call setvbuf at the right time, to set the buffering mode for stdin/stdout. The problem with FPC is that I can't find any straightforward way to either get PFile-style stdin/stdout from the Text-style input/output (surely there is a connection?) Yes. PFile _IS_ Text style. PFile is the C wrapper implementing buffer, Text the analogue Pascal buffering. I assume that settextbuf to 0 didn't work? ( http://www.freepascal.org/docs-html/rtl/system/settextbuf.html ) If that doesn't work, you need to go back to the raw unbuffered IO, do a IOCTL if necessary. FPOpen, FPClose, FPWrite, FPRead Moreover, how does lazarus deal with this? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Pipe buffering, accessing C-style stdin/stdout
Marco van de Voort schreef: After a lot of googling and experimenting, I think I have managed to make it work, but only in C code, and I want it to run in Pascal. The key to make it work in C was to call setvbuf at the right time, to set the buffering mode for stdin/stdout. The problem with FPC is that I can't find any straightforward way to either get PFile-style stdin/stdout from the Text-style input/output (surely there is a connection?) Yes. PFile _IS_ Text style. PFile is the C wrapper implementing buffer, Text the analogue Pascal buffering. I assume that settextbuf to 0 didn't work? ( http://www.freepascal.org/docs-html/rtl/system/settextbuf.html ) If that doesn't work, you need to go back to the raw unbuffered IO, do a IOCTL if necessary. FPOpen, FPClose, FPWrite, FPRead Moreover, how does lazarus deal with this? I guess Lazarus doesn't care, as long as it gets all the information at the end. There is no bidirectional communication between Lazarus and the compiler. Vincent ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] [oldlinux]: STAT_IRWXG get chmod number
Thanks marco for the way i have copy the example , but how can i convert info.st_mode in human readable mask (0777, 0755...) For example, a file in 0755 mask is 16877 value in info.st_mode. best regards unit base_unix; {$mode objfpc}{$H+} interface uses Classes, SysUtils,variants, Linux,BaseUnix,IniFiles,strutils; type Tunix=class private public procedure Free; constructor Create; function get_file_permission(path:string):string; END; implementation constructor Tunix.Create; begin end; //## procedure Tunix.Free; begin end; function Tunix.get_file_permission(path:string):string; var s:string; info : stat; i:Integer; begin fpstat (path,info); writeln; writeln ('Result of fstat on file'); writeln ('Inode : ',info.st_ino); writeln ('Mode: ',info.st_mode); writeln ('nlink : ',info.st_nlink); writeln ('uid : ',info.st_uid); writeln ('gid : ',info.st_gid); writeln ('rdev: ',info.st_rdev); writeln ('Size: ',info.st_size); writeln ('Blksize : ',info.st_blksize); writeln ('Blocks : ',info.st_blocks); writeln ('atime : ',info.st_atime); writeln ('mtime : ',info.st_mtime); writeln ('ctime : ',info.st_ctime); end; //## end. Marco van de Voort a écrit : Is there anybody has worked with STAT_IRWXG ? http://www.freepascal.org/docs-html/rtl/oldlinux/index-2.html That is a legacy api. Better use Baseunix: I need infos in order to get a function that get file permissions on linux system (like 0777, 0755...) http://www.freepascal.org/docs-html/rtl/baseunix/fpaccess.html or via stat: http://www.freepascal.org/docs-html/rtl/baseunix/fpstat.html Note that you can make octal values using the notation. E.g. var i : integer; begin i:=770; writeln(i); end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal -- David Touzeau -- Linux Ubuntu Dapper 6.0.6 FreePascal-Lazarus,perl,delphi,php icq:160018849 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal