1 // This is an open source non-commercial project. Dear PVS-Studio, please check
2 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3 
4 /// @file version.c
5 ///
6 /// Nvim was forked from Vim 7.4.160.
7 /// Vim originated from Stevie version 3.6 (Fish disk 217) by GRWalter (Fred).
8 
9 #include <assert.h>
10 #include <inttypes.h>
11 #include <limits.h>
12 
13 #include "nvim/api/private/helpers.h"
14 #include "nvim/ascii.h"
15 #include "nvim/buffer.h"
16 #include "nvim/charset.h"
17 #include "nvim/iconv.h"
18 #include "nvim/lua/executor.h"
19 #include "nvim/memline.h"
20 #include "nvim/memory.h"
21 #include "nvim/message.h"
22 #include "nvim/screen.h"
23 #include "nvim/strings.h"
24 #include "nvim/version.h"
25 #include "nvim/vim.h"
26 
27 // version info generated by the build system
28 #include "auto/versiondef.h"
29 
30 // for ":version", ":intro", and "nvim --version"
31 #ifndef NVIM_VERSION_MEDIUM
32 # define NVIM_VERSION_MEDIUM "v" STR(NVIM_VERSION_MAJOR) \
33   "." STR(NVIM_VERSION_MINOR) "." STR(NVIM_VERSION_PATCH) \
34   NVIM_VERSION_PRERELEASE
35 #endif
36 #define NVIM_VERSION_LONG "NVIM " NVIM_VERSION_MEDIUM
37 
38 
39 char *Version = VIM_VERSION_SHORT;
40 char *longVersion = NVIM_VERSION_LONG;
41 char *version_buildtype = "Build type: " NVIM_VERSION_BUILD_TYPE;
42 // Reproducible builds: omit compile info in Release builds. #15424
43 #ifndef NDEBUG
44 char *version_cflags = "Compilation: " NVIM_VERSION_CFLAGS;
45 #endif
46 
47 #ifdef INCLUDE_GENERATED_DECLARATIONS
48 # include "version.c.generated.h"
49 #endif
50 
51 static char *features[] = {
52 #ifdef HAVE_ACL
53   "+acl",
54 #else
55   "-acl",
56 #endif
57 
58 #if defined(HAVE_ICONV)
59   "+iconv",
60 #else
61   "-iconv",
62 #endif
63 
64 #ifdef FEAT_TUI
65   "+tui",
66 #else
67   "-tui",
68 #endif
69   NULL
70 };
71 
72 // clang-format off
73 static const int included_patches[] = {
74   1850,
75   1849,
76   1848,
77   1847,
78   1846,
79   1845,
80   1844,
81   1843,
82   1842,
83   1841,
84   1840,
85   1839,
86   1838,
87   1837,
88   1836,
89   1835,
90   1834,
91   1833,
92   1832,
93   1831,
94   1830,
95   1829,
96   1828,
97   1827,
98   1826,
99   1825,
100   1824,
101   1823,
102   1822,
103   1821,
104   1820,
105   1819,
106   1818,
107   1817,
108   1816,
109   1815,
110   1814,
111   1813,
112   1812,
113   1811,
114   1810,
115   1809,
116   1808,
117   1807,
118   1806,
119   1805,
120   // 1804,
121   1803,
122   1802,
123   1801,
124   1800,
125   1799,
126   1798,
127   1797,
128   1796,
129   1795,
130   // 1794,
131   1793,
132   1792,
133   1791,
134   1790,
135   1789,
136   1788,
137   1787,
138   1786,
139   1785,
140   1784,
141   1783,
142   1782,
143   1781,
144   1780,
145   1779,
146   1778,
147   1777,
148   1776,
149   1775,
150   1774,
151   1773,
152   1772,
153   1771,
154   1770,
155   1769,
156   1768,
157   1767,
158   1766,
159   1765,
160   1764,
161   1763,
162   1762,
163   1761,
164   1760,
165   1759,
166   1758,
167   1757,
168   1756,
169   1755,
170   1754,
171   1753,
172   1752,
173   1751,
174   1750,
175   1749,
176   1748,
177   1747,
178   1746,
179   1745,
180   // 1744,
181   // 1743,
182   1742,
183   1741,
184   1740,
185   1739,
186   1738,
187   1737,
188   1736,
189   1735,
190   1734,
191   1733,
192   // 1732,
193   1731,
194   1730,
195   1729,
196   1728,
197   1727,
198   1726,
199   1725,
200   1724,
201   1723,
202   1722,
203   1721,
204   1720,
205   1719,
206   1718,
207   1717,
208   1716,
209   1715,
210   1714,
211   1713,
212   1712,
213   1711,
214   1710,
215   1709,
216   1708,
217   1707,
218   // 1706,
219   1705,
220   1704,
221   1703,
222   1702,
223   1701,
224   1700,
225   1699,
226   1698,
227   1697,
228   1696,
229   1695,
230   1694,
231   1693,
232   1692,
233   1691,
234   1690,
235   1689,
236   1688,
237   1687,
238   1686,
239   1685,
240   1684,
241   1683,
242   1682,
243   1681,
244   1680,
245   1679,
246   1678,
247   1677,
248   1676,
249   1675,
250   1674,
251   1673,
252   1672,
253   1671,
254   1670,
255   1669,
256   1668,
257   1667,
258   1666,
259   1665,
260   1664,
261   1663,
262   1662,
263   1661,
264   1660,
265   1659,
266   1658,
267   1657,
268   1656,
269   1655,
270   1654,
271   1653,
272   1652,
273   1651,
274   1650,
275   1649,
276   1648,
277   1647,
278   1646,
279   1645,
280   1644,
281   1643,
282   1642,
283   1641,
284   1640,
285   1639,
286   1638,
287   1637,
288   1636,
289   1635,
290   1634,
291   1633,
292   1632,
293   1631,
294   1630,
295   1629,
296   1628,
297   1627,
298   1626,
299   1625,
300   1624,
301   1623,
302   1622,
303   1621,
304   1620,
305   1619,
306   1618,
307   1617,
308   // 1616,
309   1615,
310   1614,
311   1613,
312   1612,
313   1611,
314   1610,
315   // 1609,
316   1608,
317   1607,
318   1606,
319   1605,
320   1604,
321   1603,
322   1602,
323   1601,
324   1600,
325   1599,
326   1598,
327   1597,
328   1596,
329   1595,
330   1594,
331   1593,
332   // 1592,
333   1591,
334   1590,
335   1589,
336   // 1588,
337   1587,
338   1586,
339   1585,
340   1584,
341   1583,
342   1582,
343   1581,
344   1580,
345   1579,
346   1578,
347   1577,
348   1576,
349   1575,
350   // 1574,
351   1573,
352   1572,
353   1571,
354   // 1570,
355   1569,
356   1568,
357   1567,
358   1566,
359   1565,
360   1564,
361   1563,
362   // 1562,
363   1561,
364   1560,
365   1559,
366   // 1558,
367   1557,
368   1556,
369   1555,
370   1554,
371   1553,
372   1552,
373   1551,
374   1550,
375   1549,
376   1548,
377   1547,
378   1546,
379   1545,
380   1544,
381   1543,
382   1542,
383   1541,
384   1540,
385   1539,
386   1538,
387   1537,
388   1536,
389   1535,
390   1534,
391   1533,
392   1532,
393   1531,
394   1530,
395   1529,
396   1528,
397   1527,
398   1526,
399   1525,
400   1524,
401   1523,
402   1522,
403   1521,
404   1520,
405   1519,
406   1518,
407   1517,
408   1516,
409   1515,
410   1514,
411   1513,
412   1512,
413   1511,
414   1510,
415   1509,
416   1508,
417   1507,
418   1506,
419   1505,
420   1504,
421   1503,
422   1502,
423   1501,
424   1500,
425   1499,
426   1498,
427   1497,
428   1496,
429   1495,
430   1494,
431   1493,
432   1492,
433   1491,
434   1490,
435   1489,
436   1488,
437   1487,
438   1486,
439   1485,
440   1484,
441   1483,
442   1482,
443   1481,
444   1480,
445   1479,
446   1478,
447   1477,
448   1476,
449   1475,
450   1474,
451   1473,
452   1472,
453   1471,
454   1470,
455   1469,
456   1468,
457   1467,
458   1466,
459   1465,
460   1464,
461   1463,
462   1462,
463   1461,
464   1460,
465   1459,
466   1458,
467   1457,
468   1456,
469   1455,
470   1454,
471   1453,
472   1452,
473   1451,
474   1450,
475   1449,
476   1448,
477   1447,
478   1446,
479   1445,
480   1444,
481   1443,
482   1442,
483   1441,
484   1440,
485   1439,
486   1438,
487   1437,
488   1436,
489   1435,
490   1434,
491   1433,
492   1432,
493   1431,
494   1430,
495   1429,
496   1428,
497   1427,
498   1426,
499   1425,
500   1424,
501   1423,
502   1422,
503   1421,
504   1420,
505   1419,
506   1418,
507   1417,
508   1416,
509   1415,
510   1414,
511   1413,
512   1412,
513   1411,
514   1410,
515   1409,
516   1408,
517   1407,
518   1406,
519   1405,
520   1404,
521   1403,
522   1402,
523   1401,
524   1400,
525   1399,
526   1398,
527   1397,
528   1396,
529   1395,
530   1394,
531   1393,
532   1392,
533   1391,
534   1390,
535   1389,
536   1388,
537   1387,
538   1386,
539   1385,
540   1384,
541   1383,
542   1382,
543   1381,
544   1380,
545   1379,
546   1378,
547   1377,
548   1376,
549   1375,
550   1374,
551   1373,
552   1372,
553   1371,
554   1370,
555   1369,
556   1368,
557   // 1367,
558   1366,
559   1365,
560   1364,
561   1363,
562   1362,
563   1361,
564   1360,
565   1359,
566   1358,
567   1357,
568   1356,
569   1355,
570   1354,
571   1353,
572   1352,
573   1351,
574   1350,
575   1349,
576   1348,
577   1347,
578   1346,
579   1345,
580   1344,
581   1343,
582   1342,
583   1341,
584   1340,
585   // 1339,
586   1338,
587   1337,
588   1336,
589   // 1335,
590   1334,
591   1333,
592   1332,
593   1331,
594   1330,
595   1329,
596   1328,
597   1327,
598   1326,
599   1325,
600   1324,
601   1323,
602   1322,
603   1321,
604   1320,
605   1319,
606   1318,
607   1317,
608   1316,
609   1315,
610   1314,
611   1313,
612   1312,
613   1311,
614   1310,
615   1309,
616   1308,
617   // 1307,
618   1306,
619   1305,
620   1304,
621   1303,
622   1302,
623   1301,
624   // 1300,
625   1299,
626   1298,
627   1297,
628   1296,
629   1295,
630   1294,
631   1293,
632   1292,
633   1291,
634   1290,
635   1289,
636   1288,
637   1287,
638   1286,
639   1285,
640   1284,
641   1283,
642   1282,
643   1281,
644   1280,
645   1279,
646   1278,
647   1277,
648   1276,
649   1275,
650   1274,
651   1273,
652   1272,
653   1271,
654   1270,
655   1269,
656   1268,
657   1267,
658   1266,
659   1265,
660   1264,
661   1263,
662   1262,
663   1261,
664   1260,
665   1259,
666   1258,
667   1257,
668   1256,
669   1255,
670   1254,
671   1253,
672   1252,
673   1251,
674   1250,
675   1249,
676   1248,
677   1247,
678   1246,
679   1245,
680   1244,
681   1243,
682   1242,
683   1241,
684   1240,
685   1239,
686   1238,
687   1237,
688   1236,
689   1235,
690   1234,
691   1233,
692   1232,
693   1231,
694   1230,
695   1229,
696   1228,
697   1227,
698   1226,
699   1225,
700   1224,
701   1223,
702   1222,
703   1221,
704   1220,
705   1219,
706   1218,
707   1217,
708   1216,
709   1215,
710   1214,
711   1213,
712   1212,
713   1211,
714   1210,
715   1209,
716   1208,
717   1207,
718   1206,
719   1205,
720   1204,
721   1203,
722   1202,
723   1201,
724   1200,
725   1199,
726   1198,
727   1197,
728   1196,
729   1195,
730   1194,
731   1193,
732   1192,
733   1191,
734   1190,
735   1189,
736   1188,
737   1187,
738   1186,
739   1185,
740   1184,
741   1183,
742   1182,
743   1181,
744   1180,
745   1179,
746   1178,
747   1177,
748   1176,
749   1175,
750   1174,
751   1173,
752   1172,
753   1171,
754   1170,
755   1169,
756   1168,
757   1167,
758   1166,
759   1165,
760   1164,
761   1163,
762   1162,
763   1161,
764   1160,
765   1159,
766   1158,
767   1157,
768   1156,
769   1155,
770   1154,
771   1153,
772   1152,
773   1151,
774   1150,
775   1149,
776   1148,
777   1147,
778   1146,
779   1145,
780   1144,
781   1143,
782   1142,
783   1141,
784   1140,
785   1139,
786   1138,
787   1137,
788   1136,
789   1135,
790   1134,
791   1133,
792   1132,
793   1131,
794   1130,
795   1129,
796   1128,
797   1127,
798   1126,
799   1125,
800   1124,
801   1123,
802   1122,
803   1121,
804   1120,
805   // 1119,
806   1118,
807   1117,
808   1116,
809   1115,
810   1114,
811   1113,
812   1112,
813   1111,
814   1110,
815   1109,
816   1108,
817   1107,
818   1106,
819   1105,
820   1104,
821   1103,
822   1102,
823   1101,
824   1100,
825   1099,
826   1098,
827   1097,
828   1096,
829   1095,
830   1094,
831   1093,
832   1092,
833   1091,
834   1090,
835   1089,
836   1088,
837   1087,
838   1086,
839   1085,
840   1084,
841   1083,
842   1082,
843   1081,
844   1080,
845   1079,
846   1078,
847   1077,
848   1076,
849   1075,
850   1074,
851   1073,
852   1072,
853   1071,
854   1070,
855   1069,
856   1068,
857   1067,
858   1066,
859   1065,
860   1064,
861   1063,
862   1062,
863   1061,
864   1060,
865   1059,
866   1058,
867   1057,
868   1056,
869   1055,
870   1054,
871   1053,
872   1052,
873   1051,
874   1050,
875   1049,
876   1048,
877   1047,
878   1046,
879   1045,
880   1044,
881   1043,
882   1042,
883   1041,
884   1040,
885   1039,
886   1038,
887   1037,
888   1036,
889   1035,
890   1034,
891   1033,
892   1032,
893   1031,
894   1030,
895   1029,
896   1028,
897   1027,
898   1026,
899   1025,
900   1024,
901   1023,
902   1022,
903   1021,
904   1020,
905   1019,
906   1018,
907   1017,
908   1016,
909   1015,
910   1014,
911   1013,
912   1012,
913   1011,
914   1010,
915   1009,
916   1008,
917   1007,
918   1006,
919   1005,
920   1004,
921   1003,
922   1002,
923   1001,
924   1000,
925   999,
926   998,
927   997,
928   996,
929   995,
930   994,
931   993,
932   992,
933   991,
934   990,
935   989,
936   988,
937   987,
938   986,
939   985,
940   984,
941   983,
942   982,
943   981,
944   980,
945   979,
946   978,
947   977,
948   976,
949   975,
950   974,
951   973,
952   972,
953   971,
954   970,
955   969,
956   968,
957   967,
958   966,
959   965,
960   964,
961   963,
962   962,
963   961,
964   960,
965   959,
966   958,
967   957,
968   956,
969   955,
970   954,
971   953,
972   952,
973   951,
974   950,
975   949,
976   948,
977   947,
978   946,
979   945,
980   944,
981   943,
982   942,
983   941,
984   940,
985   939,
986   938,
987   937,
988   936,
989   935,
990   934,
991   933,
992   932,
993   931,
994   930,
995   929,
996   928,
997   927,
998   926,
999   925,
1000   924,
1001   923,
1002   922,
1003   921,
1004   920,
1005   919,
1006   918,
1007   917,
1008   916,
1009   915,
1010   914,
1011   913,
1012   912,
1013   911,
1014   910,
1015   909,
1016   908,
1017   907,
1018   906,
1019   905,
1020   904,
1021   903,
1022   902,
1023   901,
1024   900,
1025   899,
1026   898,
1027   897,
1028   896,
1029   895,
1030   894,
1031   893,
1032   892,
1033   891,
1034   890,
1035   889,
1036   888,
1037   887,
1038   886,
1039   885,
1040   884,
1041   883,
1042   882,
1043   881,
1044   880,
1045   879,
1046   878,
1047   877,
1048   876,
1049   875,
1050   874,
1051   873,
1052   872,
1053   871,
1054   870,
1055   869,
1056   868,
1057   867,
1058   866,
1059   865,
1060   864,
1061   863,
1062   862,
1063   861,
1064   860,
1065   859,
1066   858,
1067   857,
1068   856,
1069   855,
1070   854,
1071   853,
1072   852,
1073   851,
1074   850,
1075   849,
1076   848,
1077   847,
1078   846,
1079   845,
1080   844,
1081   843,
1082   842,
1083   841,
1084   840,
1085   839,
1086   838,
1087   837,
1088   836,
1089   835,
1090   834,
1091   833,
1092   832,
1093   831,
1094   830,
1095   829,
1096   828,
1097   827,
1098   826,
1099   825,
1100   824,
1101   823,
1102   822,
1103   821,
1104   820,
1105   819,
1106   818,
1107   817,
1108   816,
1109   815,
1110   814,
1111   813,
1112   812,
1113   811,
1114   810,
1115   809,
1116   808,
1117   807,
1118   806,
1119   805,
1120   804,
1121   803,
1122   802,
1123   801,
1124   800,
1125   799,
1126   798,
1127   797,
1128   796,
1129   795,
1130   794,
1131   793,
1132   792,
1133   791,
1134   790,
1135   789,
1136   788,
1137   787,
1138   786,
1139   785,
1140   784,
1141   783,
1142   782,
1143   781,
1144   780,
1145   779,
1146   778,
1147   777,
1148   776,
1149   775,
1150   774,
1151   773,
1152   772,
1153   771,
1154   770,
1155   769,
1156   768,
1157   767,
1158   766,
1159   765,
1160   764,
1161   763,
1162   762,
1163   761,
1164   760,
1165   759,
1166   758,
1167   757,
1168   756,
1169   755,
1170   754,
1171   753,
1172   752,
1173   751,
1174   750,
1175   749,
1176   748,
1177   747,
1178   746,
1179   745,
1180   744,
1181   743,
1182   742,
1183   741,
1184   740,
1185   739,
1186   738,
1187   737,
1188   736,
1189   735,
1190   734,
1191   733,
1192   732,
1193   731,
1194   730,
1195   729,
1196   728,
1197   727,
1198   726,
1199   725,
1200   724,
1201   723,
1202   722,
1203   721,
1204   720,
1205   719,
1206   718,
1207   717,
1208   716,
1209   715,
1210   714,
1211   713,
1212   712,
1213   711,
1214   710,
1215   709,
1216   708,
1217   707,
1218   706,
1219   705,
1220   704,
1221   703,
1222   702,
1223   701,
1224   700,
1225   699,
1226   698,
1227   697,
1228   696,
1229   695,
1230   694,
1231   693,
1232   692,
1233   691,
1234   690,
1235   689,
1236   688,
1237   687,
1238   686,
1239   685,
1240   684,
1241   683,
1242   682,
1243   681,
1244   680,
1245   679,
1246   678,
1247   677,
1248   676,
1249   675,
1250   674,
1251   673,
1252   672,
1253   671,
1254   670,
1255   669,
1256   668,
1257   667,
1258   666,
1259   665,
1260   664,
1261   663,
1262   662,
1263   661,
1264   660,
1265   659,
1266   658,
1267   657,
1268   656,
1269   655,
1270   654,
1271   653,
1272   652,
1273   651,
1274   650,
1275   649,
1276   648,
1277   647,
1278   646,
1279   645,
1280   644,
1281   643,
1282   642,
1283   641,
1284   640,
1285   639,
1286   638,
1287   637,
1288   636,
1289   635,
1290   634,
1291   633,
1292   632,
1293   631,
1294   630,
1295   629,
1296   628,
1297   627,
1298   626,
1299   625,
1300   624,
1301   623,
1302   622,
1303   621,
1304   620,
1305   619,
1306   618,
1307   617,
1308   616,
1309   615,
1310   614,
1311   613,
1312   612,
1313   611,
1314   610,
1315   609,
1316   608,
1317   607,
1318   606,
1319   605,
1320   604,
1321   603,
1322   602,
1323   601,
1324   600,
1325   599,
1326   598,
1327   597,
1328   596,
1329   595,
1330   594,
1331   593,
1332   592,
1333   591,
1334   590,
1335   589,
1336   588,
1337   587,
1338   586,
1339   585,
1340   584,
1341   583,
1342   582,
1343   581,
1344   580,
1345   579,
1346   578,
1347   577,
1348   576,
1349   575,
1350   574,
1351   573,
1352   572,
1353   571,
1354   570,
1355   569,
1356   568,
1357   567,
1358   566,
1359   565,
1360   564,
1361   563,
1362   562,
1363   561,
1364   560,
1365   559,
1366   558,
1367   557,
1368   556,
1369   555,
1370   554,
1371   553,
1372   552,
1373   551,
1374   550,
1375   549,
1376   548,
1377   547,
1378   546,
1379   545,
1380   544,
1381   543,
1382   542,
1383   541,
1384   540,
1385   539,
1386   538,
1387   537,
1388   536,
1389   535,
1390   534,
1391   533,
1392   532,
1393   531,
1394   530,
1395   529,
1396   528,
1397   527,
1398   526,
1399   525,
1400   524,
1401   523,
1402   522,
1403   521,
1404   520,
1405   519,
1406   518,
1407   517,
1408   516,
1409   515,
1410   514,
1411   513,
1412   512,
1413   511,
1414   510,
1415   509,
1416   508,
1417   507,
1418   506,
1419   505,
1420   504,
1421   503,
1422   502,
1423   501,
1424   500,
1425   499,
1426   498,
1427   497,
1428   496,
1429   495,
1430   494,
1431   493,
1432   492,
1433   491,
1434   490,
1435   489,
1436   488,
1437   487,
1438   486,
1439   485,
1440   484,
1441   483,
1442   482,
1443   481,
1444   480,
1445   479,
1446   478,
1447   477,
1448   476,
1449   475,
1450   474,
1451   473,
1452   472,
1453   471,
1454   470,
1455   469,
1456   468,
1457   467,
1458   466,
1459   465,
1460   464,
1461   463,
1462   462,
1463   461,
1464   460,
1465   459,
1466   458,
1467   457,
1468   456,
1469   455,
1470   454,
1471   453,
1472   452,
1473   451,
1474   450,
1475   449,
1476   448,
1477   447,
1478   446,
1479   445,
1480   444,
1481   443,
1482   442,
1483   441,
1484   440,
1485   439,
1486   438,
1487   437,
1488   436,
1489   435,
1490   434,
1491   433,
1492   432,
1493   431,
1494   430,
1495   429,
1496   428,
1497   427,
1498   426,
1499   425,
1500   424,
1501   423,
1502   422,
1503   421,
1504   420,
1505   419,
1506   418,
1507   417,
1508   416,
1509   415,
1510   414,
1511   413,
1512   412,
1513   411,
1514   410,
1515   409,
1516   408,
1517   407,
1518   406,
1519   405,
1520   404,
1521   403,
1522   402,
1523   401,
1524   400,
1525   399,
1526   398,
1527   397,
1528   396,
1529   395,
1530   394,
1531   393,
1532   392,
1533   391,
1534   390,
1535   389,
1536   388,
1537   387,
1538   386,
1539   385,
1540   384,
1541   383,
1542   382,
1543   381,
1544   380,
1545   379,
1546   378,
1547   377,
1548   376,
1549   375,
1550   374,
1551   373,
1552   372,
1553   371,
1554   370,
1555   369,
1556   368,
1557   367,
1558   366,
1559   365,
1560   364,
1561   363,
1562   362,
1563   361,
1564   360,
1565   359,
1566   358,
1567   357,
1568   356,
1569   355,
1570   354,
1571   353,
1572   352,
1573   351,
1574   350,
1575   349,
1576   348,
1577   347,
1578   346,
1579   345,
1580   344,
1581   343,
1582   342,
1583   341,
1584   340,
1585   339,
1586   338,
1587   337,
1588   336,
1589   335,
1590   334,
1591   333,
1592   332,
1593   331,
1594   330,
1595   329,
1596   328,
1597   327,
1598   326,
1599   325,
1600   324,
1601   323,
1602   322,
1603   321,
1604   320,
1605   319,
1606   318,
1607   317,
1608   316,
1609   315,
1610   314,
1611   313,
1612   312,
1613   311,
1614   310,
1615   309,
1616   308,
1617   307,
1618   306,
1619   305,
1620   304,
1621   303,
1622   302,
1623   301,
1624   300,
1625   299,
1626   298,
1627   297,
1628   296,
1629   295,
1630   294,
1631   293,
1632   292,
1633   291,
1634   290,
1635   289,
1636   288,
1637   287,
1638   286,
1639   285,
1640   284,
1641   283,
1642   282,
1643   281,
1644   280,
1645   279,
1646   278,
1647   277,
1648   276,
1649   275,
1650   274,
1651   273,
1652   272,
1653   271,
1654   270,
1655   269,
1656   268,
1657   267,
1658   266,
1659   265,
1660   264,
1661   263,
1662   262,
1663   261,
1664   260,
1665   259,
1666   258,
1667   257,
1668   256,
1669   255,
1670   254,
1671   253,
1672   252,
1673   251,
1674   250,
1675   249,
1676   248,
1677   247,
1678   246,
1679   245,
1680   244,
1681   243,
1682   242,
1683   241,
1684   240,
1685   239,
1686   238,
1687   237,
1688   236,
1689   235,
1690   234,
1691   233,
1692   232,
1693   231,
1694   230,
1695   229,
1696   228,
1697   227,
1698   226,
1699   225,
1700   224,
1701   223,
1702   222,
1703   221,
1704   220,
1705   219,
1706   218,
1707   217,
1708   216,
1709   215,
1710   214,
1711   213,
1712   212,
1713   211,
1714   210,
1715   209,
1716   208,
1717   207,
1718   206,
1719   205,
1720   204,
1721   203,
1722   202,
1723   201,
1724   200,
1725   199,
1726   198,
1727   197,
1728   196,
1729   195,
1730   194,
1731   193,
1732   192,
1733   191,
1734   190,
1735   189,
1736   188,
1737   187,
1738   186,
1739   185,
1740   184,
1741   183,
1742   182,
1743   181,
1744   180,
1745   179,
1746   178,
1747   177,
1748   176,
1749   175,
1750   174,
1751   173,
1752   172,
1753   171,
1754   170,
1755   169,
1756   168,
1757   167,
1758   166,
1759   165,
1760   164,
1761   163,
1762   162,
1763   161,
1764   160,
1765   159,
1766   158,
1767   157,
1768   156,
1769   155,
1770   154,
1771   153,
1772   152,
1773   151,
1774   150,
1775   149,
1776   148,
1777   147,
1778   146,
1779   145,
1780   144,
1781   143,
1782   142,
1783   141,
1784   140,
1785   139,
1786   138,
1787   137,
1788   136,
1789   135,
1790   134,
1791   133,
1792   132,
1793   131,
1794   130,
1795   129,
1796   128,
1797   127,
1798   126,
1799   125,
1800   124,
1801   123,
1802   122,
1803   121,
1804   120,
1805   119,
1806   118,
1807   117,
1808   116,
1809   115,
1810   114,
1811   113,
1812   112,
1813   111,
1814   110,
1815   109,
1816   108,
1817   107,
1818   106,
1819   105,
1820   104,
1821   103,
1822   102,
1823   101,
1824   100,
1825   99,
1826   98,
1827   97,
1828   96,
1829   95,
1830   94,
1831   93,
1832   92,
1833   91,
1834   90,
1835   89,
1836   88,
1837   87,
1838   86,
1839   85,
1840   84,
1841   83,
1842   82,
1843   81,
1844   80,
1845   79,
1846   78,
1847   77,
1848   76,
1849   75,
1850   74,
1851   73,
1852   72,
1853   71,
1854   70,
1855   69,
1856   68,
1857   67,
1858   66,
1859   65,
1860   64,
1861   63,
1862   62,
1863   61,
1864   60,
1865   59,
1866   58,
1867   57,
1868   56,
1869   55,
1870   54,
1871   53,
1872   52,
1873   51,
1874   50,
1875   49,
1876   48,
1877   47,
1878   46,
1879   45,
1880   44,
1881   43,
1882   42,
1883   41,
1884   40,
1885   39,
1886   38,
1887   37,
1888   36,
1889   35,
1890   34,
1891   33,
1892   32,
1893   31,
1894   30,
1895   29,
1896   28,
1897   27,
1898   26,
1899   25,
1900   24,
1901   23,
1902   22,
1903   21,
1904   20,
1905   19,
1906   18,
1907   17,
1908   16,
1909   15,
1910   14,
1911   13,
1912   12,
1913   11,
1914   10,
1915   9,
1916   8,
1917   7,
1918   6,
1919   5,
1920   4,
1921   3,
1922   2,
1923   1,
1924   0,
1925 };
1926 // clang-format on
1927 
1928 /// Compares a version string to the current Nvim version.
1929 ///
1930 /// @param version Version string like "1.3.42"
1931 ///
1932 /// @return true if Nvim is at or above the version.
has_nvim_version(const char * const version_str)1933 bool has_nvim_version(const char *const version_str)
1934   FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
1935 {
1936   const char *p = version_str;
1937   int major = 0;
1938   int minor = 0;
1939   int patch = 0;
1940 
1941   if (!ascii_isdigit(*p)) {
1942     return false;
1943   }
1944   major = atoi(p);
1945   p = strchr(p, '.');  // Find the next dot.
1946 
1947   if (p) {
1948     p++;  // Advance past the dot.
1949     if (!ascii_isdigit(*p)) {
1950       return false;
1951     }
1952     minor = atoi(p);
1953     p = strchr(p, '.');
1954     if (p) {
1955       p++;
1956       if (!ascii_isdigit(*p)) {
1957         return false;
1958       }
1959       patch = atoi(p);
1960     }
1961   }
1962 
1963   return (major < NVIM_VERSION_MAJOR
1964           || (major == NVIM_VERSION_MAJOR
1965               && (minor < NVIM_VERSION_MINOR
1966                   || (minor == NVIM_VERSION_MINOR
1967                       && patch <= NVIM_VERSION_PATCH))));
1968 }
1969 
1970 /// Checks whether a Vim patch has been included.
1971 ///
1972 /// @param n Patch number.
1973 ///
1974 /// @return true if patch `n` has been included.
has_vim_patch(int n)1975 bool has_vim_patch(int n)
1976   FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
1977 {
1978   // Perform a binary search.
1979   int l = 0;
1980   int h = (int)(ARRAY_SIZE(included_patches)) - 1;
1981   while (l < h) {
1982     const int m = (l + h) / 2;
1983     if (included_patches[m] == n) {
1984       return true;
1985     }
1986     if (included_patches[m] < n) {
1987       h = m;
1988     } else {
1989       l = m + 1;
1990     }
1991   }
1992   return false;
1993 }
1994 
version_dict(void)1995 Dictionary version_dict(void)
1996 {
1997   Dictionary d = ARRAY_DICT_INIT;
1998   PUT(d, "major", INTEGER_OBJ(NVIM_VERSION_MAJOR));
1999   PUT(d, "minor", INTEGER_OBJ(NVIM_VERSION_MINOR));
2000   PUT(d, "patch", INTEGER_OBJ(NVIM_VERSION_PATCH));
2001   PUT(d, "api_level", INTEGER_OBJ(NVIM_API_LEVEL));
2002   PUT(d, "api_compatible", INTEGER_OBJ(NVIM_API_LEVEL_COMPAT));
2003   PUT(d, "api_prerelease", BOOLEAN_OBJ(NVIM_API_PRERELEASE));
2004   return d;
2005 }
2006 
ex_version(exarg_T * eap)2007 void ex_version(exarg_T *eap)
2008 {
2009   // Ignore a ":version 9.99" command.
2010   if (*eap->arg == NUL) {
2011     msg_putchar('\n');
2012     list_version();
2013   }
2014 }
2015 
2016 /// Output a string for the version message.  If it's going to wrap, output a
2017 /// newline, unless the message is too long to fit on the screen anyway.
2018 /// When "wrap" is TRUE wrap the string in [].
2019 /// @param s
2020 /// @param wrap
version_msg_wrap(char * s,int wrap)2021 static void version_msg_wrap(char *s, int wrap)
2022 {
2023   int len = vim_strsize((char_u *)s) + (wrap ? 2 : 0);
2024 
2025   if (!got_int
2026       && (len < Columns)
2027       && (msg_col + len >= Columns)
2028       && (*s != '\n')) {
2029     msg_putchar('\n');
2030   }
2031 
2032   if (!got_int) {
2033     if (wrap) {
2034       msg_puts("[");
2035     }
2036     msg_puts(s);
2037     if (wrap) {
2038       msg_puts("]");
2039     }
2040   }
2041 }
2042 
version_msg(char * s)2043 static void version_msg(char *s)
2044 {
2045   version_msg_wrap(s, false);
2046 }
2047 
2048 /// List all features.
2049 /// This does not use list_in_columns (as in Vim), because there are only a
2050 /// few, and we do not start at a new line.
list_features(void)2051 static void list_features(void)
2052 {
2053   version_msg(_("\n\nFeatures: "));
2054   for (int i = 0; features[i] != NULL; i++) {
2055     version_msg(features[i]);
2056     if (features[i+1] != NULL) {
2057       version_msg(" ");
2058     }
2059   }
2060   version_msg("\nSee \":help feature-compile\"\n\n");
2061 }
2062 
2063 /// List string items nicely aligned in columns.
2064 /// When "size" is < 0 then the last entry is marked with NULL.
2065 /// The entry with index "current" is inclosed in [].
list_in_columns(char_u ** items,int size,int current)2066 void list_in_columns(char_u **items, int size, int current)
2067 {
2068   int item_count = 0;
2069   int width = 0;
2070 
2071   // Find the length of the longest item, use that + 1 as the column width.
2072   int i;
2073   for (i = 0; size < 0 ? items[i] != NULL : i < size; i++) {
2074     int l = vim_strsize(items[i]) + (i == current ? 2 : 0);
2075 
2076     if (l > width) {
2077       width = l;
2078     }
2079     item_count++;
2080   }
2081   width += 1;
2082 
2083   if (Columns < width) {
2084     // Not enough screen columns - show one per line
2085     for (i = 0; i < item_count; i++) {
2086       version_msg_wrap((char *)items[i], i == current);
2087       if (msg_col > 0 && i < item_count - 1) {
2088         msg_putchar('\n');
2089       }
2090     }
2091     return;
2092   }
2093 
2094   // The rightmost column doesn't need a separator.
2095   // Sacrifice it to fit in one more column if possible.
2096   int ncol = (int)(Columns + 1) / width;
2097   int nrow = item_count / ncol + (item_count % ncol ? 1 : 0);
2098   int cur_row = 1;
2099 
2100   // "i" counts columns then rows.  "idx" counts rows then columns.
2101   for (i = 0; !got_int && i < nrow * ncol; i++) {
2102     int idx = (i / ncol) + (i % ncol) * nrow;
2103     if (idx < item_count) {
2104       int last_col = (i + 1) % ncol == 0;
2105       if (idx == current) {
2106         msg_putchar('[');
2107       }
2108       msg_puts((char *)items[idx]);
2109       if (idx == current) {
2110         msg_putchar(']');
2111       }
2112       if (last_col) {
2113         if (msg_col > 0 && cur_row < nrow) {
2114           msg_putchar('\n');
2115         }
2116         cur_row++;
2117       } else {
2118         while (msg_col % width) {
2119           msg_putchar(' ');
2120         }
2121       }
2122     } else {
2123       // this row is out of items, thus at the end of the row
2124       if (msg_col > 0) {
2125         if (cur_row < nrow) {
2126           msg_putchar('\n');
2127         }
2128         cur_row++;
2129       }
2130     }
2131   }
2132 }
2133 
list_lua_version(void)2134 void list_lua_version(void)
2135 {
2136   char *code = "return ((jit and jit.version) and jit.version or _VERSION)";
2137   Error err = ERROR_INIT;
2138   Object ret = nlua_exec(cstr_as_string(code), (Array)ARRAY_DICT_INIT, &err);
2139   assert(!ERROR_SET(&err));
2140   assert(ret.type == kObjectTypeString);
2141   msg(ret.data.string.data);
2142   api_free_object(ret);
2143 }
2144 
list_version(void)2145 void list_version(void)
2146 {
2147   msg(longVersion);
2148   msg(version_buildtype);
2149   list_lua_version();
2150 #ifndef NDEBUG
2151   msg(version_cflags);
2152 #endif
2153 
2154 #ifdef HAVE_PATHDEF
2155 
2156   if ((*compiled_user != NUL) || (*compiled_sys != NUL)) {
2157     msg_puts(_("\nCompiled "));
2158 
2159     if (*compiled_user != NUL) {
2160       msg_puts(_("by "));
2161       msg_puts((const char *)compiled_user);
2162     }
2163 
2164     if (*compiled_sys != NUL) {
2165       msg_puts("@");
2166       msg_puts((const char *)compiled_sys);
2167     }
2168   }
2169 #endif  // ifdef HAVE_PATHDEF
2170 
2171   list_features();
2172 
2173 #ifdef SYS_VIMRC_FILE
2174   version_msg(_("   system vimrc file: \""));
2175   version_msg(SYS_VIMRC_FILE);
2176   version_msg("\"\n");
2177 #endif  // ifdef SYS_VIMRC_FILE
2178 #ifdef HAVE_PATHDEF
2179 
2180   if (*default_vim_dir != NUL) {
2181     version_msg(_("  fall-back for $VIM: \""));
2182     version_msg(default_vim_dir);
2183     version_msg("\"\n");
2184   }
2185 
2186   if (*default_vimruntime_dir != NUL) {
2187     version_msg(_(" f-b for $VIMRUNTIME: \""));
2188     version_msg(default_vimruntime_dir);
2189     version_msg("\"\n");
2190   }
2191 #endif  // ifdef HAVE_PATHDEF
2192 
2193   version_msg("\nRun :checkhealth for more info");
2194 }
2195 
2196 
2197 /// Show the intro message when not editing a file.
maybe_intro_message(void)2198 void maybe_intro_message(void)
2199 {
2200   if (buf_is_empty(curbuf)
2201       && (curbuf->b_fname == NULL)
2202       && (firstwin->w_next == NULL)
2203       && (vim_strchr(p_shm, SHM_INTRO) == NULL)) {
2204     intro_message(FALSE);
2205   }
2206 }
2207 
2208 /// Give an introductory message about Vim.
2209 /// Only used when starting Vim on an empty file, without a file name.
2210 /// Or with the ":intro" command (for Sven :-).
2211 ///
2212 /// @param colon TRUE for ":intro"
intro_message(int colon)2213 void intro_message(int colon)
2214 {
2215   int i;
2216   long row;
2217   long blanklines;
2218   int sponsor;
2219   char *p;
2220   static char *(lines[]) = {
2221     N_(NVIM_VERSION_LONG),
2222     "",
2223     N_("Nvim is open source and freely distributable"),
2224     N_("https://neovim.io/#chat"),
2225     "",
2226     N_("type  :help nvim<Enter>       if you are new! "),
2227     N_("type  :checkhealth<Enter>     to optimize Nvim"),
2228     N_("type  :q<Enter>               to exit         "),
2229     N_("type  :help<Enter>            for help        "),
2230     "",
2231     N_("Help poor children in Uganda!"),
2232     N_("type  :help iccf<Enter>       for information "),
2233   };
2234 
2235   // blanklines = screen height - # message lines
2236   size_t lines_size = ARRAY_SIZE(lines);
2237   assert(lines_size <= LONG_MAX);
2238 
2239   blanklines = Rows - ((long)lines_size - 1l);
2240 
2241   // Don't overwrite a statusline.  Depends on 'cmdheight'.
2242   if (p_ls > 1) {
2243     blanklines -= Rows - topframe->fr_height;
2244   }
2245 
2246   if (blanklines < 0) {
2247     blanklines = 0;
2248   }
2249 
2250   // Show the sponsor and register message one out of four times, the Uganda
2251   // message two out of four times.
2252   sponsor = (int)time(NULL);
2253   sponsor = ((sponsor & 2) == 0) - ((sponsor & 4) == 0);
2254 
2255   // start displaying the message lines after half of the blank lines
2256   row = blanklines / 2;
2257 
2258   if (((row >= 2) && (Columns >= 50)) || colon) {
2259     for (i = 0; i < (int)ARRAY_SIZE(lines); ++i) {
2260       p = lines[i];
2261 
2262       if (sponsor != 0) {
2263         if (strstr(p, "children") != NULL) {
2264           p = sponsor < 0
2265               ? N_("Sponsor Vim development!")
2266               : N_("Become a registered Vim user!");
2267         } else if (strstr(p, "iccf") != NULL) {
2268           p = sponsor < 0
2269               ? N_("type  :help sponsor<Enter>    for information ")
2270               : N_("type  :help register<Enter>   for information ");
2271         } else if (strstr(p, "Orphans") != NULL) {
2272           p = N_("menu  Help->Sponsor/Register  for information    ");
2273         }
2274       }
2275 
2276       if (*p != NUL) {
2277         do_intro_line(row, (char_u *)_(p), 0);
2278       }
2279       row++;
2280     }
2281   }
2282 
2283   // Make the wait-return message appear just below the text.
2284   if (colon) {
2285     assert(row <= INT_MAX);
2286     msg_row = (int)row;
2287   }
2288 }
2289 
do_intro_line(long row,char_u * mesg,int attr)2290 static void do_intro_line(long row, char_u *mesg, int attr)
2291 {
2292   long col;
2293   char_u *p;
2294   int l;
2295   int clen;
2296 
2297   // Center the message horizontally.
2298   col = vim_strsize(mesg);
2299 
2300   col = (Columns - col) / 2;
2301 
2302   if (col < 0) {
2303     col = 0;
2304   }
2305 
2306   // Split up in parts to highlight <> items differently.
2307   for (p = mesg; *p != NUL; p += l) {
2308     clen = 0;
2309 
2310     for (l = 0;
2311          p[l] != NUL && (l == 0 || (p[l] != '<' && p[l - 1] != '>'));
2312          l++) {
2313       clen += ptr2cells(p + l);
2314       l += utfc_ptr2len(p + l) - 1;
2315     }
2316     assert(row <= INT_MAX && col <= INT_MAX);
2317     grid_puts_len(&default_grid, p, l, (int)row, (int)col,
2318                   *p == '<' ? HL_ATTR(HLF_8) : attr);
2319     col += clen;
2320   }
2321 }
2322 
2323 /// ":intro": clear screen, display intro screen and wait for return.
2324 ///
2325 /// @param eap
ex_intro(exarg_T * eap)2326 void ex_intro(exarg_T *eap)
2327 {
2328   screenclear();
2329   intro_message(TRUE);
2330   wait_return(TRUE);
2331 }
2332 
2333