issue-#196 StdCoder Separator

Merged to the master branch

issue-#196 StdCoder Separator

Postby luowy » Fri Dec 21, 2018 7:59 am

I don't know if this error has been fixed in the center copy. In my copy it has been fixed:
StdCoder
Code: Select all
   ....
      Separator = "/";
      Separator2="\";(*add*)


StdCoder.GetFile
Code: Select all
   PROCEDURE GetFile(VAR path: ARRAY OF CHAR; VAR loc: Files.Locator; VAR name: Files.Name);
      VAR i, j: INTEGER; ch: CHAR;
   BEGIN
      i := 0; ch := path[0]; loc := Files.dir.This(""); name := "";
      WHILE (ch # 0X) & (loc.res = 0) DO
         j := 0;
         WHILE (ch # 0X) & (ch # Separator)&(ch # Separator2) DO name[j] := ch; INC(j); INC(i); ch := path[i] END;
         name[j] := 0X;
         IF (ch = Separator) OR (ch = Separator2) THEN loc := loc.This(name); INC(i); ch := path[i] END;
      END;
      IF loc.res # 0 THEN loc := NIL END;
      path[i] := 0X
   END GetFile;

the test file is here https://blackbox.obertone.ru/download/Flash.txt

luowy
luowy
 
Posts: 190
Joined: Mon Oct 20, 2014 12:52 pm

Re: StdCoder Separator

Postby Josef Templ » Wed Dec 26, 2018 8:35 pm

As far as I know this has not been reported and it certainly has not been fixed.

- Josef
User avatar
Josef Templ
 
Posts: 1957
Joined: Tue Sep 17, 2013 6:50 am

Re: StdCoder Separator

Postby Josef Templ » Fri Dec 28, 2018 9:22 am

The docu of StdCoder.EncodeFileList says that "/" should be used as separator.
It does not mention "\". Using "\" as separator makes implicit use of
the fact that under Windows (HostFiles) "\" can be used as a file separator.

Supporting "\" in StdCoder.EncodeFileList is tempting but has the disadvantage of
making StdCoder dependent on a particular HostFiles implementation without
showing this dependency in the import list.

- Josef
User avatar
Josef Templ
 
Posts: 1957
Joined: Tue Sep 17, 2013 6:50 am

Re: StdCoder Separator

Postby luowy » Fri Dec 28, 2018 11:58 am

that means it's not a bug...
But how was the example file created? Under which release?
Can our center distribution create such a file?
Maybe Ivan can get the answer form its author.
luowy
 
Posts: 190
Joined: Mon Oct 20, 2014 12:52 pm

Re: StdCoder Separator

Postby Josef Templ » Sat Dec 29, 2018 10:55 am

The center version can create such a file and the center version can even decode such a file
but only if all directories already exist. It fails when creation of a directory is required because
it skips the separator that marks the directory name needed for creating a new directory.
Creating a file and creating a directory are separated under Windows and are also separated
in the BlackBox Files module.

- Josef
User avatar
Josef Templ
 
Posts: 1957
Joined: Tue Sep 17, 2013 6:50 am

Re: StdCoder Separator

Postby Zinn » Mon Dec 31, 2018 2:12 pm

Josef Templ wrote:The center version can create such a file and the center version can even decode such a file
but only if all directories already exist.

But with Luowy's patches the directory is created during decode automatically.
- Helmut
Zinn
 
Posts: 464
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main

Re: StdCoder Separator

Postby Josef Templ » Mon Dec 31, 2018 2:54 pm

Well, there are other modules as well that use "\" as alternative separator, for example StdApi.
It seems that this violation of abstraction is unavoidable unless there is some
additional (Files) function that checks for valid file names.

Given that observation I tend to agree with luowy's proposal.

- Josef
User avatar
Josef Templ
 
Posts: 1957
Joined: Tue Sep 17, 2013 6:50 am

Re: StdCoder Separator

Postby Robert » Wed Jan 23, 2019 9:56 pm

I have just looked at HostFiles.Diff & HostFiles.NewLocator, both chosen rather at random.
In each case there is explicit code to allow either "/" or "\" as the separator.

So it seems to be the case that BlackBox generally allows the choice, and to be consistent we should also allow it in StdCoder (and update the documentation to reflect this change).

This change also makes things a little more convenient for the user.
User avatar
Robert
 
Posts: 968
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: StdCoder Separator

Postby Josef Templ » Mon Feb 11, 2019 5:05 pm

It is clear that the separators are hard-coded in HostFiles.
This is where they belong to. Hard coding them outside HostFiles is not very clean
but as I mentioned before, it seems to be unavoidable and it should be done in
StdCoder as luowy pointed out.

- Josef
User avatar
Josef Templ
 
Posts: 1957
Joined: Tue Sep 17, 2013 6:50 am

Re: StdCoder Separator

Postby Josef Templ » Mon Feb 11, 2019 8:40 pm

I have created a branch for that and put luowy's proposal into it.

For the changes see https://redmine.blackboxframework.org/projects/blackbox/repository/revisions/bef5b623ba2ef810398518fb9c889d2dd8017b90/diff/.

- Josef
User avatar
Josef Templ
 
Posts: 1957
Joined: Tue Sep 17, 2013 6:50 am

Next

Return to Resolved (Features)

Who is online

Users browsing this forum: No registered users and 0 guests

cron