comments length increased, multiline comments are also now possible.

This commit is contained in:
Norayr Chilingarian 2025-07-19 05:48:27 +04:00
parent 50b5a1438e
commit a517a42357
4 changed files with 48 additions and 31 deletions

View file

@ -8,7 +8,7 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *)
CONST
OptionChar* = "-";
MaxCommentLen* = 256;
MaxCommentLen* = 1024;
(* compiler option flag bits; don't change the encoding *)
inxchk* = 0; (* index check on *)

View file

@ -4,7 +4,7 @@ MODULE OPS; (* NW, RC 6.3.89 / 18.10.92 *) (* object model 3.6.92 *)
IMPORT OPM, SYSTEM;
CONST
MaxStrLen* = 256;
MaxStrLen* = 1024;
MaxIdLen = 256;
@ -196,7 +196,7 @@ MODULE OPS; (* NW, RC 6.3.89 / 18.10.92 *) (* object model 3.6.92 *)
commentText: ARRAY OPM.MaxCommentLen OF CHAR;
i: INTEGER;
nestLevel: INTEGER;
prevCh, nextCh: CHAR;
prevCh: CHAR;
BEGIN
FOR i := 0 TO LEN(commentText) - 1 DO
commentText[i] := 0X
@ -224,45 +224,53 @@ MODULE OPS; (* NW, RC 6.3.89 / 18.10.92 *) (* object model 3.6.92 *)
WHILE (nestLevel > 0) & (ch # OPM.Eot) DO
IF (prevCh = "(") & (ch = "*") THEN
INC(nestLevel);
prevCh := 0X
prevCh := ch; (* Don't set to 0X - keep the '*' *)
OPM.Get(ch)
ELSIF (prevCh = "*") & (ch = ")") THEN
DEC(nestLevel);
IF nestLevel = 0 THEN
OPM.Get(ch); (* move past ')' *)
ELSE
prevCh := 0X
prevCh := ch; (* Keep the ')' *)
OPM.Get(ch)
END
ELSE
IF isExported & (nestLevel = 1) & (prevCh # 0X) THEN
IF isExported & (nestLevel = 1) THEN
IF i < OPM.MaxCommentLen - 1 THEN
commentText[i] := prevCh; INC(i)
(* Handle all characters including newlines *)
IF (ch = 0DX) OR (ch = 0AX) THEN
(* Add newline if buffer is empty or last char isn't already a newline *)
IF (i = 0) OR (commentText[i-1] # 0AX) THEN
commentText[i] := 0AX; INC(i)
END;
(* Handle CRLF by skipping the LF if we just saw CR *)
IF (ch = 0DX) THEN
prevCh := ch; OPM.Get(ch);
IF ch = 0AX THEN
prevCh := ch; OPM.Get(ch)
END
ELSE
prevCh := ch; OPM.Get(ch)
END
ELSIF ch >= " " THEN
commentText[i] := ch; INC(i);
prevCh := ch; OPM.Get(ch)
ELSE
(* Skip control characters *)
prevCh := ch; OPM.Get(ch)
END
ELSE
prevCh := ch; OPM.Get(ch)
END
END;
prevCh := ch
END;
IF nestLevel > 0 THEN OPM.Get(ch) END
ELSE
prevCh := ch; OPM.Get(ch)
END
END
END;
IF ch = OPM.Eot THEN
err(5)
END;
(*
IF isExported & (nestLevel = 0) & (prevCh # 0X) & (prevCh # "*") & (i < OPM.MaxCommentLen - 2) THEN
commentText[i] := prevCh;
INC(i)
END;
*)
IF isExported & (nestLevel = 0) & (prevCh # 0X) & (prevCh # "*") THEN
IF i < OPM.MaxCommentLen - 1 THEN
commentText[i] := prevCh;
INC(i)
ELSE
OPM.LogWStr("Truncating final comment character"); OPM.LogWLn
END
END;
IF isExported THEN
IF i >= OPM.MaxCommentLen THEN
@ -272,7 +280,6 @@ MODULE OPS; (* NW, RC 6.3.89 / 18.10.92 *) (* object model 3.6.92 *)
commentText[i] := 0X;
OPM.StoreComment(commentText)
END;
END Comment;

View file

@ -1019,7 +1019,7 @@ END InStruct;
PROCEDURE InObj(mno: SHORTINT): Object; (* first number in impCtxt.nextTag *)
VAR i, s: INTEGER; ch: CHAR; obj, old: Object; typ: Struct;
tag: LONGINT; ext: ConstExt;
commentText: OPS.Name;
commentText: ARRAY OPM.MaxCommentLen OF CHAR;
hasComment : BOOLEAN;
j: INTEGER;
len: LONGINT;

View file

@ -67,7 +67,17 @@ MODULE BrowserCmd; (* RC 29.10.93 *) (* object model 4.12.93, command line ver
IF obj^.comment # NIL THEN
Indent(1);
Ws("(** ");
Ws(obj^.comment^);
(* Handle multi-line comments *)
i := 0;
WHILE obj^.comment^[i] # 0X DO
IF obj^.comment^[i] = 0AX THEN
Ws(" *)"); Wln;
Indent(1); Ws(" ");
ELSE
Wc(obj^.comment^[i])
END;
INC(i)
END;
Ws(" *)");
Wln
END;