From 25c73fbcd04d973272e0f8939a9de956fa9afbeb Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 24 Feb 2020 20:02:10 +0300 Subject: [PATCH] cpmake: print errors through procedure Error --- src/generic/Dsw/Mod/MakeMain.cp | 110 +++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 37 deletions(-) diff --git a/src/generic/Dsw/Mod/MakeMain.cp b/src/generic/Dsw/Mod/MakeMain.cp index 989b8bc..04388d2 100644 --- a/src/generic/Dsw/Mod/MakeMain.cp +++ b/src/generic/Dsw/Mod/MakeMain.cp @@ -78,6 +78,44 @@ MODULE DswMakeMain; jobs: INTEGER; exe: String; + PROCEDURE Error (e: INTEGER; IN p0, p1: ARRAY OF CHAR; i2: INTEGER); + VAR msg, p2: ARRAY 128 OF CHAR; + BEGIN + CASE e OF + | 0: msg := "option -D expect + or - after identifier" + | 1: msg := "option -D expect identifier" + | 2: msg := "option -U expect identifier" + | 3: msg := "module name must be identifier" + | 4: msg := "expected integer" (* p0 = in str *) + | 5: msg := "unterminated string" + | 6: msg := "unknown processor ^0" + | 7: msg := "unknown os ^0" + | 8: msg := "unknown compiler ^0" + | 9: msg := "unknown linker ^0" + | 10: msg := "missing argument for option ^0" + | 11: msg := "unknown option ^0" + | 12: msg := "compiler not selected" + | 13: msg := "processor not selected" + | 14: msg := "processor not supported by native compiler" + | 15: msg := "internal linker not required for cpfront" + | 16: msg := "cpfront can't out executable file" + | 17: msg := "linker not selected" + | 18: msg := "os not selected" + | 19: msg := "output file name can't be empty" + | 20: msg := "recursive import of ^0 in ^1" + | 21: msg := "unable to open module ^1" + | 22: msg := "linker terminated with code ^2" + | 23: msg := "unable to execute linker" + | 24: msg := "trap occured" + ELSE + Strings.IntToString(err, msg) + END; + Strings.IntToString(i2, p2); + Log.String(Kernel.argv[0]$); Log.String(": "); + Log.ParamMsg(msg, p0, p1, p2); Log.Ln; + INC(err) + END Error; + (* --------- options --------- *) PROCEDURE IdentLen (IN s: ARRAY OF CHAR): INTEGER; @@ -96,7 +134,7 @@ MODULE DswMakeMain; i := IdentLen(n); IF i # 0 THEN IF ~((n[i] = 0X) OR (((n[i] = "+") OR (n[i] = "-")) & (n[i + 1] = 0X))) THEN - Log.String("option -D expect + or - after identifier"); Log.Ln; INC(err) + Error(0, "", "", 0) END; v := n[i] # "-"; n[i] := 0X; s := def; WHILE (s.next # NIL) & (s.next.name$ # n$) DO s := s.next END; @@ -107,7 +145,7 @@ MODULE DswMakeMain; END; s.next.value := v ELSE - Log.String("option -D expect identifier"); Log.Ln; INC(err) + Error(1, "", "", 0) END END Define; @@ -120,7 +158,7 @@ MODULE DswMakeMain; WHILE (s.next # NIL) & (s.next.name$ # n$) DO s := s.next END; IF s.next # NIL THEN s.next := s.next.next END ELSE - Log.String("option -U expect identifier"); Log.Ln; INC(err) + Error(2, "", "", 0) END END Undefine; @@ -153,7 +191,7 @@ MODULE DswMakeMain; INC(mno) END ELSE - Log.String("module name must be identifier"); Log.Ln; INC(err) + Error(3, "", "", 0) END END AddModule; @@ -162,7 +200,7 @@ MODULE DswMakeMain; BEGIN Strings.StringToInt(s, x, res); IF res # 0 THEN - Log.String("expected integer"); Log.Ln; INC(err); + Error(4, s, "", 0); x := def END; RETURN x @@ -222,7 +260,7 @@ MODULE DswMakeMain; AddChar(ch); ch := s[i]; INC(i) END; IF ch # 0X THEN ch := s[i]; INC(i) - ELSE Log.String("unterminated string"); Log.Ln; INC(err) + ELSE Error(5, "", "", 0) END | " ": REPEAT ch := s[i]; INC(i) UNTIL ch # " "; @@ -283,7 +321,7 @@ MODULE DswMakeMain; IF s$ = "none" THEN processor := anymach ELSIF s$ = "486" THEN processor := mach386 ELSIF s$ = "68k" THEN processor := mach68k - ELSE Log.String("unknwon processor "); Log.String(s); Log.Ln; INC(err) + ELSE Error(6, s, "", 0) END | "s": s := DswOpts.str; @@ -295,24 +333,24 @@ MODULE DswMakeMain; ELSIF s$ = "win32" THEN os := win32 ELSIF s$ = "cygwin" THEN os := cygwin ELSIF s$ = "darwin" THEN os := darwin - ELSE Log.String("unknwon os "); Log.String(s); Log.Ln; INC(err) + ELSE Error(7, s, "", 0) END | "g": s := DswOpts.str; Strings.ToLower(s, s); IF s$ = "native" THEN compiler := cpnative ELSIF s$ = "cpfront" THEN compiler := cpfront - ELSE Log.String("unknwon compiler "); Log.String(s); Log.Ln; INC(err) + ELSE Error(8, s, "", 0) END | "i": s := DswOpts.str; Strings.ToLower(s, s); IF s$ = "dev2" THEN linker := dev2 - ELSE Log.String("unknwon linker "); Log.String(s); Log.Ln; INC(err) + ELSE Error(9, s, "", 0) END - | ":": Log.String("missing argument for option -T"); Log.String(DswOpts.str); Log.Ln; INC(err) - | "?": Log.String("unknown option -T"); Log.String(DswOpts.str); Log.Ln; INC(err) - | 0X: Log.String("unknown option -T"); Log.Ln; INC(err) + | ":": Error(10, "-T" + DswOpts.str, "", 0) + | "?": Error(11, "-T" + DswOpts.str, "", 0) + | 0X: Error(11, "-T", "", 0) END END ParseTargetOpts; @@ -321,9 +359,9 @@ MODULE DswMakeMain; CASE DswOpts.GetOpt("g:i:") OF | "g": cpcArgs := ToStringList(DswOpts.str); | "i": cplArgs := ToStringList(DswOpts.str); - | ":": Log.String("missing argument for option -C"); Log.String(DswOpts.str); Log.Ln; INC(err) - | "?": Log.String("unknown option -C"); Log.String(DswOpts.str); Log.Ln; INC(err) - | 0X: Log.String("unknown option -C"); Log.Ln; INC(err) + | ":": Error(10, "-C" + DswOpts.str, "", 0) + | "?": Error(11, "-C" + DswOpts.str, "", 0) + | 0X: Error(11, "-C", "", 0) END END ParseCommandOpts; @@ -332,9 +370,9 @@ MODULE DswMakeMain; CASE DswOpts.GetOpt("g:i:") OF | "g": cpcExe := DswOpts.str; | "i": cplExe := DswOpts.str; - | ":": Log.String("missing argument for option -X"); Log.String(DswOpts.str); Log.Ln; INC(err) - | "?": Log.String("unknown option -X"); Log.String(DswOpts.str); Log.Ln; INC(err) - | 0X: Log.String("unknown option -X"); Log.Ln; INC(err) + | ":": Error(10, "-X" + DswOpts.str, "", 0) + | "?": Error(11, "-X" + DswOpts.str, "", 0) + | 0X: Error(11, "-X", "", 0) END END ParseExternalOpts; @@ -354,8 +392,8 @@ MODULE DswMakeMain; | "T": ParseTargetOpts | "C": ParseCommandOpts | "X": ParseExternalOpts - | ":": Log.String("missing argument for option -"); Log.String(DswOpts.str); Log.Ln; INC(err) - | "?": Log.String("unknown option -"); Log.String(DswOpts.str); Log.Ln; INC(err) + | ":": Error(10, "-" + DswOpts.str, "", 0) + | "?": Error(11, "-" + DswOpts.str, "", 0) | "$": AddModule(DswOpts.str, def) | 0X: EXIT END @@ -365,28 +403,28 @@ MODULE DswMakeMain; PROCEDURE CheckParams; BEGIN IF compiler = anycp THEN - Log.String("compiler not selected"); Log.Ln; INC(err) + Error(12, "", "", 0) ELSIF compiler = cpnative THEN IF processor = anymach THEN - Log.String("processor not selected"); Log.Ln; INC(err) + Error(13, "", "", 0) ELSIF processor # mach386 THEN - Log.String("processor not supported by native compiler"); Log.Ln; INC(err) + Error(14, "", "", 0) END END; IF (compiler = cpfront) & (linker # anyint) THEN - Log.String("internal linker not required for cpfront"); Log.Ln; INC(err) + Error(15, "", "", 0) END; IF (compiler = cpfront) & (exe # NIL) THEN - Log.String("cpfront can't out executable file"); Log.Ln; INC(err) + Error(16, "", "", 0) END; IF (exe # NIL) & (compiler = cpnative) & (linker = anyint) THEN - Log.String("linker not selected"); Log.Ln; INC(err) + Error(17, "", "", 0) END; IF (linker = dev2) & (os = anyos) THEN - Log.String("os not selected"); Log.Ln; INC(err) + Error(18, "", "", 0) END; IF (exe # NIL) & (exe^ = "") THEN - Log.String("output file name can't be empty"); Log.Ln; INC(err) + Error(19, "", "", 0) END; IF cpcExe = NIL THEN IF compiler = cpnative THEN cpcExe := NewStr("cpc486") @@ -600,7 +638,7 @@ MODULE DswMakeMain; END; EXCL(m.flags, trace) ELSE - Log.String("recursive import of " + m.name + " in " + parent.name); Log.Ln; INC(err) + Error(20, m.name$, parent.name$, 0) END END Trace; @@ -633,7 +671,7 @@ MODULE DswMakeMain; CheckModule(m, s, ok); IF ~ok THEN INC(err) END ELSE - Log.String("unable to open module " + m.name); Log.Ln; INC(err) + Error(21, m.name$, "", 0) END; INC(i) END; @@ -885,12 +923,10 @@ MODULE DswMakeMain; Log.String("Link "); Log.String(exe); Log.Ln; res := p.Result(); IF res # 0 THEN - Log.String("linker terminated with error"); Log.Int(res); Log.Ln; - INC(err) + Error(22, "", "", res) END ELSE - Log.String("unable to execute linker"); Log.Int(i); Log.Ln; - INC(err) + Error(23, "", "", 0) END END LinkDev2; @@ -920,8 +956,8 @@ MODULE DswMakeMain; END END END - END - ELSE INC(err) + END + ELSE Error(24, "", "", 0) END; IF err = 0 THEN Kernel.Quit(0) ELSE Kernel.Quit(1) -- 2.29.2