directive-if.mk revision 1.6
11.6Srillig# $NetBSD: directive-if.mk,v 1.6 2020/11/12 19:46:36 rillig Exp $ 21.1Srillig# 31.2Srillig# Tests for the .if directive. 41.1Srillig 51.1Srillig# TODO: Implementation 61.1Srillig 71.3Srillig.if 0 81.3Srillig. error 91.3Srillig.else 101.3Srillig. info 0 evaluates to false. 111.3Srillig.endif 121.3Srillig 131.3Srillig.if 1 141.3Srillig. info 1 evaluates to true. 151.3Srillig.else 161.3Srillig. error 171.3Srillig.endif 181.3Srillig 191.3Srillig# There is no '.ifx'. 201.3Srillig# 211.3Srillig# The commit from 2005-05-01 intended to detect this situation, but it failed 221.4Srillig# to do this since the call to is_token had its arguments switched. They were 231.4Srillig# expected as (str, token, token_len) but were actually passed as (token, str, 241.3Srillig# token_len). This made is_token return true even if the directive was 251.4Srillig# directly followed by alphanumerical characters, which was wrong. The 261.4Srillig# typical cases produced an error message such as "Malformed conditional 271.4Srillig# (x 123)", while the intended error message was "Unknown directive". 281.3Srillig# 291.3Srillig# Back at that time, the commits only modified the main code but did not add 301.3Srillig# the corresponding unit tests. This allowed the bug to hide for more than 311.3Srillig# 15 years. 321.4Srillig# 331.4Srillig# Since 2020-11-10, the correct error message is produced. The '.ifx' is no 341.4Srillig# longer interpreted as a variant of '.if', therefore the '.error' and '.else' 351.4Srillig# are interpreted as ordinary directives, producing the error messages 361.4Srillig# "if-less else" and "if-less endif". 371.3Srillig.ifx 123 381.3Srillig. error 391.3Srillig.else 401.3Srillig. error 411.3Srillig.endif 421.3Srillig 431.3Srillig# Missing condition. 441.3Srillig.if 451.3Srillig. error 461.3Srillig.else 471.3Srillig. error 481.3Srillig.endif 491.3Srillig 501.5Srillig# A plain word must not start with a '"'. It may contain a embedded quotes 511.5Srillig# though, which are kept. The quotes need not be balanced. The next space 521.5Srillig# ends the word, and the remaining " || 1" is parsed as "or true". 531.5Srillig.if ${:Uplain"""""} == plain""""" || 1 541.5Srillig. info Quotes in plain words are probably a mistake. 551.5Srillig# XXX: Accepting quotes in plain words is probably a mistake as well. 561.5Srillig.else 571.5Srillig. error 581.5Srillig.endif 591.5Srillig 601.6Srillig.if0 611.6Srillig. error 621.6Srillig.else 631.6Srillig. info Don't do this, always put a space after a directive. 641.6Srillig.endif 651.6Srillig 661.6Srillig.if${:U-3} 671.6Srillig. info Don't do this, always put a space after a directive. 681.6Srillig.else 691.6Srillig. error 701.6Srillig.endif 711.6Srillig 721.6Srillig.if${:U-3}>-4 731.6Srillig. info Don't do this, always put a space around comparison operators. 741.6Srillig.else 751.6Srillig. error 761.6Srillig.endif 771.6Srillig 781.1Srilligall: 79