Views.Old doesn't impement documentation specs
Posted: Thu Jul 09, 2020 9:04 pm
Colleagues,
However de-facto the implementation (in StdDialog.OldView) calls Converters.Import, passing conv to it witout change. Well,
How to fix:
It seems to me that something was left in confusion in StdDialog.OldView: it declares a local c: Converters.Converter, performs some manipulations with it and then never uses the result. The local c needs to be removed, and formal conv used everywhere in it's place:
I move to fix it.
Besides, the docu for Views.Old needs to be fixed, too, IMHO. There needs to be a mention of the case when conversion is impossible, and NIL is returned in that case. The postcondition
result = NIL
loc.res # 0
seems to be inaccurate.
Even under current implementation, a NIL may be returned if no fitting converter is found. This is low chance, since the default Blackbox has a number of 'catch all' converteres installed by default. It is one of these converters that produces the character mess - pretty useless, I would turn off their Converters.importAll flag. However, if they are not installed (in Config), a NIL may well be returned by Views.Old.
Thus, if you pass conv = NIL, then no conversion should occur. So, if you try to open a .png file with Views.Old passing conv = NIL, you should receive a NIL, because there is no Documents.Document in a png file, and thus no view can be extracted from a png file with the standard document converter.Views Documentation wrote: PROCEDURE Old (ask: BOOLEAN; VAR loc: Files.Locator; VAR name: Files.Name;
VAR conv: Converters.Converter): View
conv determines the converter which is used for reading the document. conv = NIL means that no conversion is necessary, i.e., the file format already has the standard BlackBox format.
However de-facto the implementation (in StdDialog.OldView) calls Converters.Import, passing conv to it witout change. Well,
Thus, Views.Old, upon receiving conv = NIL, looks for the first fitting converters and uses it to read the file. And returns a mess of characters, because png cannot be converted into a View.PROCEDURE Converters.Import (loc: Files.Locator; name: Files.Name; VAR conv: Converter; OUT s: Stores.Store) wrote: If conv = NIL, the first suitable converter in list is used and returned in the VAR parameter.
How to fix:
It seems to me that something was left in confusion in StdDialog.OldView: it declares a local c: Converters.Converter, performs some manipulations with it and then never uses the result. The local c needs to be removed, and formal conv used everywhere in it's place:
Code: Select all
c := conv; (* remove *)
IF c = NIL THEN c := Converters.list END; (* use document converter *)
(* IF conv = NIL THEN conv := Converters.list END; *)
w := Windows.GetBySpec(loc, name, c (* -> conv *), {});
IF w # NIL THEN s := w.doc.ThisView() END;
IF s = NIL THEN
Converters.Import(loc, name, conv, s);
Besides, the docu for Views.Old needs to be fixed, too, IMHO. There needs to be a mention of the case when conversion is impossible, and NIL is returned in that case. The postcondition
result = NIL
loc.res # 0
seems to be inaccurate.
Even under current implementation, a NIL may be returned if no fitting converter is found. This is low chance, since the default Blackbox has a number of 'catch all' converteres installed by default. It is one of these converters that produces the character mess - pretty useless, I would turn off their Converters.importAll flag. However, if they are not installed (in Config), a NIL may well be returned by Views.Old.