Skip to content

Commit 04840ca

Browse files
Improve version number output formats
FossilOrigin-Name: ede1f9f8005070e2e8faa4b69a474c8af5343161edbb32726e4774a678cfee28
1 parent 9dbcb83 commit 04840ca

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

make/version_number.fs

+46-24
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
\ This file is part of Solo Forth
44
\ http://programandala.net/en.program.solo_forth.html
55

6-
\ Last modified 202010012056
6+
\ Last modified 202010021653
77
\ See change log at the end of the file
88

99
\ ==============================================================
1010
\ Description
1111

1212
\ This program extracts the version number of Solo Forth from the
1313
\ labels defined in the Z80 source and prints it in certain format.
14-
\
1514

1615
\ This program is written in Forth (http://forth-standard.org)
1716
\ with Gforth (http://gnu.org/software/gforth/).
@@ -21,15 +20,19 @@
2120

2221
\ Invocation:
2322

24-
\ gforth -e 's" PATH-TO/version.z80s" flag' version_number.fs
23+
\ gforth -e 's" PATH-TO/version.z80s" FORMAT' version_number.fs
2524

26-
\ Where "flag" is either `true` (complete version number) or `false`
27-
\ (simplified format used as a file name for the background images).
25+
\ Where FORMAT is 0..3 with the following meaning:
26+
\
27+
\ 0 = XX.YY.ZZ (two digits per element, with padding zeros)
28+
\ 1 = X.Y.Z
29+
\ 2 = X.Y.Z-prerelease
30+
\ 3 = X.Y.Z-prerelease+build
2831

2932
\ ==============================================================
3033
\ Author
3134

32-
\ Marcos Cruz (programandala.net), 2016, 2017.
35+
\ Marcos Cruz (programandala.net), 2016, 2017, 2020.
3336

3437
\ ==============================================================
3538
\ License
@@ -44,7 +47,7 @@ only forth definitions decimal
4447

4548
\ ==============================================================
4649

47-
variable real-format \ flag
50+
variable format \ version output format ID (0..2)
4851

4952
variable version-major
5053
variable version-minor
@@ -54,36 +57,52 @@ variable version-prerelease
5457
variable version-build-high
5558
variable version-build-low
5659

57-
: .version-part ( n -- ) s>d <# #S #> type ;
60+
defer .version-part
61+
62+
: .full-version-part ( n -- ) s>d <# #S #> type ;
5863
\ Print one part of the version number.
64+
\ Default action of `.version-part`.
65+
66+
: .version-part-00 ( n -- ) s>d <# # # #> type ;
67+
\ Print one part of the version number, with two digits,
68+
\ padded with zeros.
69+
\ Alternative action of `.version-part`.
70+
71+
' .full-version-part is .version-part
5972

6073
: build-date ( -- u )
6174
version-build-low @ version-build-high @ $10000 * + ;
6275

63-
: .real-version ( -- )
76+
: .version-x.y.z ( -- )
6477
version-major @ .version-part '.' emit
6578
version-minor @ .version-part '.' emit
66-
version-patch @ .version-part
79+
version-patch @ .version-part ;
80+
\ Print the version number using format "X.Y.Z".
81+
82+
: .version-0x.0y.0z ( -- )
83+
['] .version-part-00 is .version-part
84+
.version-x.y.z ;
85+
86+
: .version-x.y.z-prerelease ( -- )
87+
.version-x.y.z
6788
version-prerelease @ ?dup if
6889
version-prerelease-id @ case
69-
'd' of ." -dev." .version-part endof
70-
'p' of ." -pre." .version-part endof
90+
'd' of ." -dev." endof
91+
'p' of ." -pre." endof
7192
'r' of ." -rc." endof
7293
endcase .version-part
73-
then '+' emit build-date 0 .r ;
94+
then ;
7495

75-
: .version-part-00 ( n -- ) s>d <# # # #> type ;
76-
\ Print one part of the version number, with two digits,
77-
\ padded with zeros.
78-
79-
: .simple-version ( -- )
80-
version-major @ .version-part-00 '.' emit
81-
version-minor @ .version-part-00 '.' emit
82-
version-patch @ .version-part-00 ;
83-
\ Print the version number using format "MM.mm.pp".
96+
: .version-x.y.z-prerelease+build ( -- )
97+
.version-x.y.z-prerelease '+' emit build-date 0 .r ;
8498

8599
: .version ( -- )
86-
real-format @ if .real-version else .simple-version then ;
100+
format @ case
101+
0 of .version-0x.0y.0z endof
102+
1 of .version-x.y.z endof
103+
2 of .version-x.y.z-prerelease endof
104+
3 of .version-x.y.z-prerelease+build endof
105+
endcase ;
87106

88107
\ ==============================================================
89108
\ Parser
@@ -115,7 +134,7 @@ forth-wordlist set-current
115134
\ ==============================================================
116135
\ Main
117136

118-
real-format ! parser-wordlist >order included .version bye
137+
format ! parser-wordlist >order included .version bye
119138

120139
\ ==============================================================
121140
\ Change log
@@ -132,4 +151,7 @@ real-format ! parser-wordlist >order included .version bye
132151
\ 2017-07-26: Update to the new internal format of the version number.
133152
\
134153
\ 2020-10-01: Update to support dev/pre/rc prereleases.
154+
\
155+
\ 2020-10-02: Improve format selection from true/false to 0..3.
135156

157+
\ vim: filetype=gforth

0 commit comments

Comments
 (0)