Recent

Author Topic: Weird behavior opening a text file in FV editor  (Read 1581 times)

HotShoe

  • New Member
  • *
  • Posts: 33
Weird behavior opening a text file in FV editor
« on: November 07, 2024, 06:39:33 am »
I am playing around with the idea of replacing an Ncurses editor that has been around for many years (since 1986). I haven't really messed with Borlands TV or fpc's FV packages, so I grabbed the demo and started modifying it.

It looks much better than the old Ncurses one so I started putting in the features that I wanted while doing tests along the way. I am doing this on a Rysen 7 laptop with 32G of memory running KDE Neon (based on ubuntu Linux) and the latest 3.6 lazarus/fpc packages from this site.

When I tried to open a file in /etc to make sure that paths were being passed correctly, I got an error reading file (error 5- IO error). The file was /etc/fpc.cfg which has permissions of 644 (rw-r-r) I can open this file with any other text editor but not with this one. I dug into the editors module source to see if it was wanting my user as the file owner, but that isn't the case (the file is owned by root).

The error happens as soon as the Reset command is executed. It uses the System units reset command which just calls opentext with FMInput, which is correct and what I want. I know reset works fine, so why can't I load this file? I created a new junk text file as root, then did a chmod 644 on it in the projects directory with the same results. I can chmod the file to 666 and it loads just fine. I need an editor to load any text file that the user has permissions to read.

I don't see where or why this is happening and it doesn't happen if I open a file in a straight console program or my old ncurses editor. What am I missing here?

Thanks,
--- Jem

cdbc

  • Hero Member
  • *****
  • Posts: 1644
    • http://www.cdbc.dk
Re: Weird behavior opening a text file in FV editor
« Reply #1 on: November 07, 2024, 06:47:19 am »
Hi
It might be that FV-editor start by creating a ~working-copy in the same directory, like e.g.: 'gedit' does?!? I dunno...
Just my guess.
Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

HotShoe

  • New Member
  • *
  • Posts: 33
Re: Weird behavior opening a text file in FV editor
« Reply #2 on: November 07, 2024, 06:51:30 am »
That would certainly cause an error. I'll see if it is trying to create a "work" file, but the junk file I created was in the editors project dir which I have full access to.

Thanks,
--- Jem

Thaddy

  • Hero Member
  • *****
  • Posts: 16139
  • Censorship about opinions does not belong here.
Re: Weird behavior opening a text file in FV editor
« Reply #3 on: November 07, 2024, 07:44:28 am »
Can you open it readonly? (meaning Filemode:=0, default is 2, rw) With filemode = 0 reset should succeed. It is a simple global variable.
It seems that something goes wrong in the default file mode, because that tries rw on a r only file.
« Last Edit: November 07, 2024, 07:47:48 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

TRon

  • Hero Member
  • *****
  • Posts: 3619
Re: Weird behavior opening a text file in FV editor
« Reply #4 on: November 07, 2024, 01:17:17 pm »
@HotShoe:
In case you require such finer detailed access rights it might perhaps not be a good idea to use the oldschool file-handling approach but instead switch to something that allows for these details to be controlled.

Thaddy is right in that you can manipulate things... a little but, it is up to a certain point.

If all else fail you could even fall back to using *nix api to access files (usually not required though).
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

HotShoe

  • New Member
  • *
  • Posts: 33
Re: Weird behavior opening a text file in FV editor
« Reply #5 on: November 07, 2024, 07:30:32 pm »
Can you open it readonly? (meaning Filemode:=0, default is 2, rw) With filemode = 0 reset should succeed. It is a simple global variable.
It seems that something goes wrong in the default file mode, because that tries rw on a r only file.

Sorry Thaddy, I forgot to mention that I have filemode:= 0 in the program just before the file is assigned. It's just strange that my other editor doesn't care as long as you have read permission, and neither does nano, jed, ted, etc hehe.

--- Jem

Thaddy

  • Hero Member
  • *****
  • Posts: 16139
  • Censorship about opinions does not belong here.
Re: Weird behavior opening a text file in FV editor
« Reply #6 on: November 08, 2024, 07:57:01 am »
Assign() on its own does not perform any file IO, it just assigns a filename to a handle. Rewrite and reselt() do perform the IO and on nixes map directly to the OS filedescriptor. (fpopen()) So it is already quite low level except you can not directly use all modifiers that are possible on unix.
If I create a text file as root and chmod it to 644 I can open it readonly as user.

BTW fpopen is simply an alias for fopen, nothing more.
What occurred to me that perhaps the file system itself is the cause.
« Last Edit: November 08, 2024, 10:55:13 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

HotShoe

  • New Member
  • *
  • Posts: 33
Re: Weird behavior opening a text file in FV editor
« Reply #7 on: November 08, 2024, 06:22:30 pm »
I don't understand it. I have written 4 routines now that all work, but the FV example does not so I will now rewrite the FileEditor.loadfile routine in FV and see what that does. In the mean time I have gone back to updating the Ncurses editor.

Just another example of my haunted systems.

Thanks,
--- Jem

mika

  • Full Member
  • ***
  • Posts: 111
Re: Weird behavior opening a text file in FV editor
« Reply #8 on: November 11, 2024, 02:55:39 pm »
HotShoe, if you are about to use Editor from FV, check latest bug fixes in Gitlab. Editors unit have been broken since very beginning. There are some other recent fixes that might be interesting.
I guess Reset might open file in read-write mode.

Thaddy

  • Hero Member
  • *****
  • Posts: 16139
  • Censorship about opinions does not belong here.
Re: Weird behavior opening a text file in FV editor
« Reply #9 on: November 12, 2024, 01:46:39 pm »
I guess Reset might open file in read-write mode.
Yes, that was the case as already mentioned. It is fixed since two days in trunk. filemode := 0; default := 2;
If I smell bad code it usually is bad code and that includes my own code.

mika

  • Full Member
  • ***
  • Posts: 111
Re: Weird behavior opening a text file in FV editor
« Reply #10 on: November 13, 2024, 12:01:21 pm »
... It is fixed since two days in trunk. filemode := 0; default := 2;
Is it? I don't see relevant commits 2-3 days back.

Thaddy

  • Hero Member
  • *****
  • Posts: 16139
  • Censorship about opinions does not belong here.
Re: Weird behavior opening a text file in FV editor
« Reply #11 on: November 13, 2024, 07:57:02 pm »
All fixes by Margers are accepted and applied.  Check your eyes.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018