issue-#63 fixes in StdStamps

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

Re: issue-#63 fixes in StdStamps

Post by Josef Templ »

OK. Anything else?

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

Re: issue-#63 fixes in StdStamps

Post by Josef Templ »

the fixes have been merged into master.
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: issue-#63 fixes in StdStamps

Post by Robert »

Josef Templ wrote:OK. Anything else?
There is always something else ...

There was some discussion about more than one comment on a single date. I accepted your opinion that this could be relevant.

However it is possible to have both empty & used comments on the same date which I think is unintended. I think it would be better if the "new" option was not available if there
was already an empty comment with today's date.

But that said I now use StdStamps frequently, and think we have reached a very good (even if not perfect!) solution.

Regards

Robert
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#63 fixes in StdStamps

Post by Josef Templ »

I agree, the intention was to support multiple commented entries per day.
If you show me the required changes, I can look at them and it should be possible to
get them into master.

Note: in case of an existing uncommented entry, the default Seq. Nr. is set to 1 already.
This makes it unlikely that a commented entry is added in addition to an existing uncommented entry.
But it is possible as you pointed out correctly.

- Josef
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: issue-#63 fixes in StdStamps

Post by Robert »

Josef Templ wrote:This makes it unlikely ...
If fact I did it a few times accidently before I realised what was happening!

My first thought was to make it impossible to add a "new" comment when there was already an empty one.
I decide against this for several reason:
- It seemed difficult to code!
- It didn't repair the Stamps I have already "corrupted".
- There still remained the unlikely possibility of adding 2 actual comments, then later deleting one of them.

The proposal below is to alter the Internalize routine to purge these empty stamp entries.
I have currently left in my development / debug code; it is left justified, so is easy to remove.
To see the changes look for the variable "purge".

Code: Select all

	PROCEDURE (v: StdView) Internalize (VAR rd: Stores.Reader);
		VAR version: INTEGER; format: BYTE; k, purge, i, len,: INTEGER;
			d: Dates.Date; t: Dates.Time;
f: Fmtrs.Fmtr;
	BEGIN
		v.Internalize^(rd);
		IF ~rd.cancelled THEN
			rd.ReadVersion(minVersion, maxVersion, version);
			IF ~rd.cancelled THEN
				IF version = origStampVersion THEN (* deal with old StdStamp format *)
					(* would like to calculate fingerprint, but hosting model not available at this time *)
					NEW(v.history, maxHistoryEntries);
					v.history[0].fprint := 0;
					v.history[0].snr := 1; v.nentries := 1;
					rd.ReadXInt(d.year); rd.ReadXInt(d.month); rd.ReadXInt(d.day);
					rd.ReadXInt(t.hour); rd.ReadXInt(t.minute); rd.ReadXInt(t.second);
					rd.ReadByte(format); (* format not used anymore *)
					v.history[0].date := Dates.Day(d);
					v.history[0].time := t.minute + t.hour*64;
				ELSE
f := Fmtrs.Log({});
					IF version = noSnrVersion THEN NEW(v.history, maxHistoryEntries); rd.ReadInt(v.history[0].snr) END;
					rd.ReadXInt(v.nentries);
f.IntLn(v.nentries, 4);
					IF version > noSnrVersion THEN NEW(v.history, MAX(v.nentries, maxHistoryEntries)) END;
					purge := 0;
					FOR k := 0 TO v.nentries-1 DO
						i := k - purge;
						rd.ReadInt(v.history[i].fprint);
						IF version > noSnrVersion THEN rd.ReadInt(v.history[i].snr)
						ELSIF (* (version = noSnrVersion) & *) i > 0 THEN v.history[i].snr := v.history[i-1].snr - 1;
						END;
						rd.ReadInt(v.history[i].date);
						rd.ReadXInt(v.history[i].time);
						rd.ReadXInt(len);
						IF len > 0 THEN
							NEW(v.history[i].comment, len + 1);
							IF version >= wideCommentVersion THEN
								rd.ReadString(v.history[i].comment)
							ELSE
								rd.ReadXString(v.history[i].comment)
							END
						ELSE v.history[i].comment := NIL
						END;
f.Int(i, 4);
f.Int(v.history[i].date,8);
f.IntStr(v.history[i].snr,8, '   ');
f.SetAsHex(BITS(v.history[i].fprint));
IF  v.history[i].comment # NIL THEN  f.Str('   ' + v.history[i].comment) END;
						IF (i > 0) & (v.history[i].date = v.history[i-1].date) THEN
							IF  v.history[i-1].comment = NIL THEN
f.Str ('   Previous comment empty');
								 v.history[i-1].comment := v.history[i].comment; INC(purge)
							ELSIF  v.history[i].comment = NIL THEN
f.Str ('   This comment empty');
								INC(purge)
							END
						END;
f.Ln
					END;
					DEC(v.nentries, purge);
					IF version < wideCommentVersion THEN (* cleanup *)
						i := v.nentries - 1;
						WHILE (i > 0) & (v.history[i].date = 0) DO DEC(i); DEC(v.nentries) END
					END
				END
			END
		END
	END Internalize;
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#63 fixes in StdStamps

Post by Josef Templ »

Thanks, looks good to me. For the changes see

http://redmine.blackboxframework.org/pr ... 1ad9fa9b59

Let me know if everything is OK.

- Josef
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: issue-#63 fixes in StdStamps

Post by Robert »

Josef

Seems to be working fine - thanks.

Robert
Post Reply