Compare commits

...

99 Commits

Author SHA1 Message Date
Gavin Howard eb0cd870b9
Make bc work without -Wdeclaration-after-statement warnings 5 days ago
Gavin Howard 51ce0e0352
Fix a problem in the algorithms manual 1 week ago
Gavin Howard ca53adf83b
Fix bugs and style in filter_text 1 week ago
Gavin Howard 712d79c03e
Do not use uniq for blank lines in filter_text 1 week ago
Gavin Howard 319d597f9e
Increment the version and update the NEWS 2 weeks ago
Gavin Howard 34e31ad80f
Fix a build problem in FreeBSD 2 weeks ago
Gavin Howard 82f85e9d90
Make editline more efficient with no prompt 2 weeks ago
Gavin Howard 36ebd30e2b
Increment the version and update the NEWS 2 weeks ago
Gavin Howard 45df56dd2e
Make editline and readline respect BC_PROMPT 2 weeks ago
Gavin Howard 408f9090c1
Make EOF with the line libs more like the built-in history 3 weeks ago
Gavin Howard 4317afa2fa
Increment the version and update the NEWS 3 weeks ago
Gavin Howard bb4431262d
Fix a problem with the en_US locale file 3 weeks ago
Gavin Howard c58e2be43f
Fix a build problem on FreeBSD 3 weeks ago
Gavin Howard 37068c161d
Fix formatting 3 weeks ago
Gavin Howard bd5f5fdb79
Make bc history use tabs 3 weeks ago
Gavin Howard 83878f1c2f
Make gen/strgen.c work with Windows again 3 weeks ago
Gavin Howard a698a33503
Adjust the Windows build for the strgen changes 3 weeks ago
Gavin Howard d30762f5c0
Fix a problem in the builtin arg tests 3 weeks ago
Gavin Howard 74d8eb2891
Try yet again to fix all of the compiler warnings 3 weeks ago
Gavin Howard 49adcc7af5
Try again to fix the signals problem 3 weeks ago
Gavin Howard 4a07fb1580
Try to fix a problem with signals 3 weeks ago
Gavin Howard 25fe85591a
Fix another compiler warning 3 weeks ago
Gavin Howard 0ff0f67d60
Fix compiler warnings 3 weeks ago
Gavin Howard 78ba445e83
Add the new command-line options to the help texts 3 weeks ago
Gavin Howard db540c29e3
Fix a typo in the bc manual 3 weeks ago
Gavin Howard a6519f8593
Update the NEWS 3 weeks ago
Gavin Howard 4beb55fbd8
Update the manuals 3 weeks ago
Gavin Howard 44983b5d2a
Add an error test for command-line builtin variables 3 weeks ago
Gavin Howard 2db127113b
Add tests for the builtin var command-line arguments 3 weeks ago
Gavin Howard 488d48c87c
Implement command-line args to set the four builtin variables 3 weeks ago
Gavin Howard 4c34391266
Add some directives to the manpages for better style 3 weeks ago
Gavin Howard 0d8bffdb64
Fix FreeBSD issues and typos in the manuals 3 weeks ago
Gavin Howard ec41af4679
Simplify the history tests in configure.sh 3 weeks ago
Gavin Howard c36b91b024
Attempt to fix build failures on the FreeBSD port 4 weeks ago
Gavin Howard b5812f05c5
Add a note to the README about spam 4 weeks ago
Gavin Howard 7cb4597574
Remove an extra newline output 1 month ago
Gavin Howard 6b4ea3432d
Add editline and readline testing to the release script 1 month ago
Gavin Howard 95a9c99f13
Update the release checklist 1 month ago
Gavin Howard f147e34c8e
Format all C code 1 month ago
Gavin Howard 4e5556e260
Add code formatting infrastructure 1 month ago
Gavin Howard 27441fc0c2
Fix style 1 month ago
Gavin Howard 27b59e0aed
Fix lint warnings 1 month ago
Gavin Howard 495e2d7358
Add lint infrastructure 1 month ago
Gavin Howard fd2ea461e4
Increment the version and update the NEWS 1 month ago
Gavin Howard 289da0e76a
Update documentation 1 month ago
Gavin Howard 4a10f9c786
Add the line library configure options to the build manual 1 month ago
Gavin Howard debc6cd31a
Do not initialize history with a bad terminal 1 month ago
Gavin Howard a1ef58d12f
Add comments 1 month ago
Gavin Howard 82eb41312e
Fix a typo in the manuals 1 month ago
Gavin Howard 467b54c78e
Add an explanatory comment 1 month ago
Gavin Howard ecf128aaa0
Make sure there's no UB from changing const strings 1 month ago
Gavin Howard dddc69be47
Get history working on Windows 1 month ago
Gavin Howard 4eb4b699f6
Fix style 1 month ago
Gavin Howard 99eb8bbbb3
Merge branch 'master' into line_libs 1 month ago
Gavin Howard 411e1a8b16
Fix the README folder list 1 month ago
Gavin Howard 75d300d74d
Merge branch 'master' into line_libs 1 month ago
Gavin Howard 1b77c55148
Fix the README file list 1 month ago
Gavin Howard 0549afca5c
Add a missing #include 1 month ago
Gavin Howard 8896082204
Rename two globals 1 month ago
Gavin Howard 0632f1d60d
Make sure ^C is printed without sigint reset for editline 1 month ago
Gavin Howard 6ff6592fd2
Make SIGINT work with editline as well 1 month ago
Gavin Howard 30f96cd088
Make readline handle SIGINT correctly 1 month ago
Gavin Howard 3efc3b9f42
Clean up a lot of the line lib code and consolidate 1 month ago
Gavin Howard dda04344dd
Attempt to fix no newline on EOF 1 month ago
Gavin Howard 9d4a878f66
Fix the version output 1 month ago
Gavin Howard c74c2a56d4
Make history work under editline 1 month ago
Gavin Howard 7bbf1eec59
Make SIGWINCH work on FreeBSD 1 month ago
Gavin Howard 7701612501
Switch static_assert to _Static_assert 1 month ago
Gavin Howard 88e2894e25
Attempt to make bc build in FreeBSD base 1 month ago
Gavin Howard 7112520efe
Make sure to error if the new configure arguments are wrong 1 month ago
Gavin Howard 73a1a62f59
Merge branch 'master' into line_libs 1 month ago
Gavin Howard 54a7ca1a8d
Fix a compile error that I did not catch 1 month ago
Gavin Howard f8b5ab0dfd
Make the build work on FreeBSD 1 month ago
Gavin Howard 38e85d7ea3
Implement support for editline and readline 1 month ago
Gavin Howard e1bd08f895
Fix style 1 month ago
Gavin Howard 04ef32e888
Fix a bug 1 month ago
Gavin Howard c96de7c0f6
Add gzip to the package script 2 months ago
Gavin Howard d24ea601aa
Tweak the release notes 2 months ago
Gavin Howard 7fa5dce636
Increment the version and update the NEWS 2 months ago
Gavin Howard cef94931a4
Change the history EOF test for the recent change two commits ago 2 months ago
Gavin Howard 5e0a30e2a9
Fix style 2 months ago
Warner Losh f8fa6febf7 Emacs delete-next-character 2 months ago
Gavin Howard cad172d8f0
Increment the version and update the NEWS 3 months ago
Piotr P. Stefaniak cb7bde2181
Make Home and End keys work in tmux in history 3 months ago
Gavin Howard 8ec0c24751
Add a comment warning of the bug that was found 3 months ago
Gavin Howard 24be19250c
Quiet a useless clang warning 3 months ago
Piotr P. Stefaniak e0fb717308
Fix a bug in history refresh 3 months ago
Gavin Howard 3d6c2e4645
Update copyright for the bc banner 3 months ago
Gavin Howard b5c7f6942b
Add a comment 3 months ago
Gavin Howard 5ba4e300a7
Make sure to not run a generated test if not able to generate 3 months ago
Gavin Howard fd1e659aa6
Increment the version and update the NEWS 4 months ago
Gavin Howard 621adbd71d
Workaround a clang bug 4 months ago
Gavin Howard 6d26f2ac3e
Fix another gcc warning 4 months ago
Gavin Howard ca6dd9ecf6
Fix style 4 months ago
Gavin Howard de4fa1bd4a
Fix a compile warning from GCC 4 months ago
Gavin Howard 5fc73c7443
Add more tests for multiline comments and strings in expression files 4 months ago
Gavin Howard dbc4dc4c4e
Fix a problem found with the fix in last commit 4 months ago
Gavin Howard d778d0b917
Fix the bug mentioned in the last commit 4 months ago
Gavin Howard 824859ba47
Add a test for a bug found by a user 4 months ago
  1. 152
      .clang-format
  2. 43
      .clang-tidy
  3. 15
      Makefile.in
  4. 57
      NEWS.md
  5. 34
      README.md
  6. 87
      configure.sh
  7. 26
      gen/bc_help.txt
  8. 26
      gen/dc_help.txt
  9. 308
      gen/strgen.c
  10. 31
      gen/strgen.sh
  11. 4
      include/args.h
  12. 65
      include/bc.h
  13. 258
      include/bcl.h
  14. 15
      include/dc.h
  15. 80
      include/file.h
  16. 177
      include/history.h
  17. 96
      include/lang.h
  18. 58
      include/lex.h
  19. 104
      include/library.h
  20. 161
      include/num.h
  21. 24
      include/opt.h
  22. 49
      include/parse.h
  23. 1065
      include/program.h
  24. 48
      include/rand.h
  25. 12
      include/read.h
  26. 117
      include/status.h
  27. 106
      include/vector.h
  28. 2
      include/version.h
  29. 162
      include/vm.h
  30. 4
      locales/en_US.msg
  31. 2
      manuals/algorithms.md
  32. 146
      manuals/bc.1.md.in
  33. 128
      manuals/bc/A.1
  34. 141
      manuals/bc/A.1.md
  35. 100
      manuals/bc/E.1
  36. 121
      manuals/bc/E.1.md
  37. 100
      manuals/bc/EH.1
  38. 121
      manuals/bc/EH.1.md
  39. 100
      manuals/bc/EHN.1
  40. 121
      manuals/bc/EHN.1.md
  41. 100
      manuals/bc/EN.1
  42. 121
      manuals/bc/EN.1.md
  43. 128
      manuals/bc/H.1
  44. 141
      manuals/bc/H.1.md
  45. 128
      manuals/bc/HN.1
  46. 141
      manuals/bc/HN.1.md
  47. 128
      manuals/bc/N.1
  48. 141
      manuals/bc/N.1.md
  49. 16
      manuals/bcl.3
  50. 10
      manuals/bcl.3.md
  51. 39
      manuals/build.md
  52. 64
      manuals/dc.1.md.in
  53. 77
      manuals/dc/A.1
  54. 59
      manuals/dc/A.1.md
  55. 60
      manuals/dc/E.1
  56. 48
      manuals/dc/E.1.md
  57. 60
      manuals/dc/EH.1
  58. 48
      manuals/dc/EH.1.md
  59. 60
      manuals/dc/EHN.1
  60. 48
      manuals/dc/EHN.1.md
  61. 60
      manuals/dc/EN.1
  62. 48
      manuals/dc/EN.1.md
  63. 77
      manuals/dc/H.1
  64. 59
      manuals/dc/H.1.md
  65. 77
      manuals/dc/HN.1
  66. 59
      manuals/dc/HN.1.md
  67. 77
      manuals/dc/N.1
  68. 59
      manuals/dc/N.1.md
  69. 10
      manuals/development.md
  70. 4
      manuals/header_bc.txt
  71. 4
      manuals/header_bcl.txt
  72. 4
      manuals/header_dc.txt
  73. 36
      manuals/release.md
  74. 40
      scripts/bitfuncgen.c
  75. 49
      scripts/format.sh
  76. 91
      scripts/functions.sh
  77. 63
      scripts/lint.sh
  78. 73
      scripts/manpage.sh
  79. 13
      scripts/package.sh
  80. 13
      scripts/release.sh
  81. 157
      src/args.c
  82. 5
      src/bc.c
  83. 92
      src/bc_lex.c
  84. 692
      src/bc_parse.c
  85. 872
      src/data.c
  86. 5
      src/dc.c
  87. 73
      src/dc_lex.c
  88. 66
      src/dc_parse.c
  89. 312
      src/file.c
  90. 871
      src/history.c
  91. 124
      src/lang.c
  92. 158
      src/lex.c
  93. 387
      src/library.c
  94. 11
      src/main.c
  95. 1188
      src/num.c
  96. 141
      src/opt.c
  97. 87
      src/parse.c
  98. 1117
      src/program.c
  99. 196
      src/rand.c
  100. 85
      src/read.c
  101. Some files were not shown because too many files have changed in this diff Show More

152
.clang-format

@ -0,0 +1,152 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: 1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: All
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
#AttributeMacros: []
BinPackArguments: true
BinPackParameters: true
#BitFieldColonSpacing: Both
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakAfterJavaFieldAnnotations: true
BreakBeforeBinaryOperators: None
#BreakBeforeConceptDeclarations: true
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DeriveLineEnding: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<(sys|arpa|net|netinet)/.*\.h>'
Priority: 2
- Regex: '^<(args|bc|bcl|dc|file|history|lang|lex|library|num|opt|parse|program|rand|read|status|vector|version|vm)\.h>'
Priority: 3
- Regex: '^<.*\.h>'
Priority: 0
- Regex: '^<.*>'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentExternBlock: NoIndent
IndentGotoLabels: false
IndentPPDirectives: None
#IndentPragmas: false
#IndentRequires: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaImportGroups: []
JavaScriptQuotes: Double
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
NamespaceMacros: []
ObjCBinPackProtocolList: Always
ObjCBlockIndentWidth: 4
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 1000
PenaltyBreakBeforeFirstCallParameter: 429496720
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 42949672
PenaltyBreakString: 10000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 42949672
PenaltyIndentedWhitespace: 1
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
#RawStringFormats:
# This is used to get spaces around a bitwise and operator.
ReferenceAlignment: Middle
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
#SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 4
TypenameMacros: []
UseCRLF: false
UseTab: ForIndentation
WhitespaceSensitiveMacros: []
...

43
.clang-tidy

@ -0,0 +1,43 @@
Checks: 'clang-diagnostic-*,clang-analyzer-*'
WarningsAsErrors: 'clang-diagnostic-*,clang-analyzer-*'
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: file
CheckOptions:
- key: llvm-else-after-return.WarnOnConditionVariables
value: 'false'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons
value: 'false'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: 'false'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 'true'
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: 'true'
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: llvm-qualified-auto.AddConstToQualified
value: 'false'
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: llvm-else-after-return.WarnOnUnfixable
value: 'false'
- key: google-readability-function-size.StatementThreshold
value: '800'
...

15
Makefile.in

@ -147,6 +147,7 @@ BC_ENABLE_EXTRA_MATH_NAME = BC_ENABLE_EXTRA_MATH
BC_ENABLE_EXTRA_MATH = %%EXTRA_MATH%%
BC_ENABLE_NLS = %%NLS%%
BC_LONG_BIT = %%LONG_BIT%%
BC_EXCLUDE_EXTRA_MATH = %%EXCLUDE_EXTRA_MATH%%
BC_ENABLE_AFL = %%FUZZ%%
BC_ENABLE_MEMCHECK = %%MEMCHECK%%
@ -201,14 +202,14 @@ DC_DEFS = $(DC_DEFS1) $(DC_DEFS2) $(DC_DEFS3) $(DC_DEFS4)
CPPFLAGS1 = -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
CPPFLAGS2 = $(CPPFLAGS1) -I$(INCDIR)/ -DBUILD_TYPE=$(BC_BUILD_TYPE) %%LONG_BIT_DEFINE%%
CPPFLAGS3 = $(CPPFLAGS2) -DEXECPREFIX=$(EXEC_PREFIX) -DMAINEXEC=$(MAIN_EXEC)
CPPFLAGS4 = $(CPPFLAGS3) -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 %%BSD%%
CPPFLAGS4 = $(CPPFLAGS3) %%BSD%%
CPPFLAGS5 = $(CPPFLAGS4) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
CPPFLAGS6 = $(CPPFLAGS5) -DBC_ENABLE_NLS=$(BC_ENABLE_NLS)
CPPFLAGS7 = $(CPPFLAGS6) -D$(BC_ENABLE_EXTRA_MATH_NAME)=$(BC_ENABLE_EXTRA_MATH)
CPPFLAGS8 = $(CPPFLAGS7) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY) -DBC_ENABLE_LIBRARY=$(BC_ENABLE_LIBRARY)
CPPFLAGS = $(CPPFLAGS8) -DBC_ENABLE_MEMCHECK=$(BC_ENABLE_MEMCHECK) -DBC_ENABLE_AFL=$(BC_ENABLE_AFL)
CFLAGS = $(CPPFLAGS) $(BC_DEFS) $(DC_DEFS) %%CPPFLAGS%% %%CFLAGS%%
LDFLAGS = %%LDFLAGS%%
CFLAGS = $(CPPFLAGS) $(BC_DEFS) $(DC_DEFS) %%CPPFLAGS%% %%CFLAGS%% -I$(INCLUDEDIR)
LDFLAGS = %%LDFLAGS%% -L$(LIBDIR)
HOSTCFLAGS = %%HOSTCFLAGS%%
@ -235,25 +236,25 @@ $(GEN_EXEC): $(GEN_DIR)
%%GEN_EXEC_TARGET%%
$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
$(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) $(BC_LIB_C_ARGS)
$(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) $(BC_EXCLUDE_EXTRA_MATH) $(BC_LIB_C_ARGS)
$(BC_LIB_O): $(BC_LIB_C)
$(CC) $(CFLAGS) -o $@ -c $<
$(BC_LIB2_C): $(GEN_EXEC) $(BC_LIB2)
$(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) $(BC_LIB2_C_ARGS)
$(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) $(BC_EXCLUDE_EXTRA_MATH) $(BC_LIB2_C_ARGS)
$(BC_LIB2_O): $(BC_LIB2_C)
$(CC) $(CFLAGS) -o $@ -c $<
$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP)
$(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help "" $(BC_ENABLED_NAME)
$(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) $(BC_EXCLUDE_EXTRA_MATH) bc_help "" $(BC_ENABLED_NAME)
$(BC_HELP_O): $(BC_HELP_C)
$(CC) $(CFLAGS) -o $@ -c $<
$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP)
$(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help "" $(DC_ENABLED_NAME)
$(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) $(BC_EXCLUDE_EXTRA_MATH) dc_help "" $(DC_ENABLED_NAME)
$(DC_HELP_O): $(DC_HELP_C)
$(CC) $(CFLAGS) -o $@ -c $<

57
NEWS.md

@ -1,5 +1,62 @@
# News
## 5.3.3
This is a production release that fixes a build problem in the FreeBSD base
system.
All other users do **NOT** need to upgrade.
## 5.3.2
This is a production release that fixes prompt bugs with editline and readline
where the `BC_PROMPT` environment variable was not being respected.
This also fixes editline and readline output on `EOF`.
## 5.3.1
This is a production release that fixes a build problem in the FreeBSD base
system, as well as a problem in the `en_US` locale. If you don't have problems
with either, you do not need to upgrade.
## 5.3.0
This is a production release that adds features and has a few bug fixes.
First, support for editline and readline history has been added. To use
editline, pass `-e` to `configure.sh`, and to use readline, pass `-r`.
Second, history support for Windows has been fixed and re-enabled.
Third, command-line options to set `scale`, `ibase`, `obase`, and `seed` were
added. This was requested long ago, and I originally disagreed with the idea.
Fourth, the manuals had typos and were missing information. That has been fixed.
Fifth, the manuals received different formatting to be more readable as
manpages.
## 5.2.5
This is a production release that fixes this `bc`'s behavior on `^D` to match
GNU `bc`.
## 5.2.4
This is a production release that fixes two bugs in history:
* Without prompt, the cursor could not be placed on the first character in a
line.
* Home and End key handling in `tmux` was fixed.
Any users that do not care about these improvements do not need to upgrade.
## 5.2.3
This is a production release that fixes one bug, a parse error when passing a
file to `bc` using `-f` if that file had a multiline comment or string in it.
## 5.2.2
This is a production release that fixes one bug, a segmentation fault if

34
README.md

@ -1,5 +1,10 @@
# `bc`
***WARNING: New user registration for https://git.yzena.com/ is disabled because
of spam. If you need to report a bug with `bc`, email gavin at this site minus
the `git.` part for an account, and I will create one for you. Or you can report
an issue at [GitHub][29].***
***WARNING: This project has moved to [https://git.yzena.com/][20] for [these
reasons][21], though GitHub will remain a mirror.***
@ -71,8 +76,8 @@ Also, if building with MSBuild, the MSBuild bundled with Visual Studio is
required.
**Note**: Unlike the POSIX-compatible platforms, only one build configuration is
supported on Windows: extra math and prompt enabled, history and NLS (locale
support) disabled, with both calculators built.
supported on Windows: extra math and history enabled, NLS (locale support)
disabled, with both calculators built.
#### `bc`
@ -179,9 +184,6 @@ see the [build manual][5].
The library API can be found in [`manuals/bcl.3.md`][26] or `man bcl` once the
library is installed.
The library is built as `bin/libbcl.a` on POSIX-compatible systems or as
`Release/bcl/bcl.lib` on Windows.
#### Package and Distro Maintainers
This section is for package and distro maintainers.
@ -289,8 +291,7 @@ with POSIX `bc`. The math has been tested with 40+ million random problems, so
it is as correct as I can make it.
This `bc` can be used as a drop-in replacement for any existing `bc`. This `bc`
is also compatible with MinGW toolchains, though history is not supported on
Windows.
is also compatible with MinGW toolchains.
In addition, this `bc` is considered complete; i.e., there will be no more
releases with additional features. However, it *is* actively maintained, so if
@ -405,18 +406,18 @@ Files:
Makefile.in The Makefile template.
NEWS.md The changelog.
NOTICE.md List of contributors and copyright owners.
RELEASE.md A checklist for making a release (maintainer use only).
Folders:
gen The bc math library, help texts, and code to generate C source.
include All header files.
locales Locale files, in .msg format. Patches welcome for translations.
manuals Manuals for both programs.
src All source code.
scripts A bunch of shell scripts to help with development and building.
tests All tests.
vs Files needed for the build on Windows.
benchmarks A folder of benchmarks for various aspects of bc performance.
gen The bc math library, help texts, and code to generate C source.
include All header files.
locales Locale files, in .msg format. Patches welcome for translations.
manuals Manuals for both programs.
src All source code.
scripts A bunch of shell scripts to help with development and building.
tests All tests.
vs Files needed for the build on Windows.
[1]: https://www.gnu.org/software/bc/
[4]: ./LICENSE.md
@ -439,3 +440,4 @@ Folders:
[26]: ./manuals/bcl.3.md
[27]: https://en.wikipedia.org/wiki/Bus_factor
[28]: ./manuals/development.md
[29]: https://github.com/gavinhoward/bc

87
configure.sh

@ -52,12 +52,13 @@ usage() {
printf 'usage:\n'
printf ' %s -h\n' "$script"
printf ' %s --help\n' "$script"
printf ' %s [-a|-bD|-dB|-c] [-CEfgGHlmMNtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\\\n' "$script"
printf ' %s [-a|-bD|-dB|-c] [-CeEfgGHlmMNrtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\\\n' "$script"
printf ' [-s SETTING] [-S SETTING]\n'
printf ' %s \\\n' "$script"
printf ' [--library|--bc-only --disable-dc|--dc-only --disable-bc|--coverage] \\\n'
printf ' [--force --debug --disable-extra-math --disable-generated-tests] \\\n'
printf ' [--disable-history --disable-man-pages --disable-nls --disable-strip] \\\n'
printf ' [--enable-editline] [--enable-readline] \\\n'
printf ' [--install-all-locales] [--opt=OPT_LEVEL] \\\n'
printf ' [--karatsuba-len=KARATSUBA_LEN] \\\n'
printf ' [--set-default-on=SETTING] [--set-default-off=SETTING] \\\n'
@ -87,6 +88,11 @@ usage() {
printf ' -D, --disable-dc\n'
printf ' Disable dc. It is an error if "-d", "--dc-only", "-B", or "--disable-bc"\n'
printf ' are specified too.\n'
printf ' -e, --enable-editline\n'
printf ' Enable the use of libedit/editline. This is meant for those users that\n'
printf ' want vi-like or Emacs-like behavior in history.This option is ignored if\n'
printf ' history is disabled. It is an error if this option is enabled when the\n'
printf ' -r/--enable-readline option is enabled.\n'
printf ' -E, --disable-extra-math\n'
printf ' Disable extra math. This includes: "$" operator (truncate to integer),\n'
printf ' "@" operator (set number of decimal places), and r(x, p) (rounding\n'
@ -125,6 +131,11 @@ usage() {
printf ' Set the optimization level. This can also be included in the CFLAGS,\n'
printf ' but it is provided, so maintainers can build optimized debug builds.\n'
printf ' This is passed through to the compiler, so it must be supported.\n'
printf ' -r, --enable-readline\n'
printf ' Enable the use of libreadline/readline. This is meant for those users\n'
printf ' that want vi-like or Emacs-like behavior in history.This option is\n'
printf ' ignored if history is disabled. It is an error if this option is\n'
printf ' enabled when the -e/--enable-editline option is enabled.\n'
printf ' -s SETTING, --set-default-on SETTING\n'
printf ' Set the default named by SETTING to on. See below for possible values\n'
printf ' for SETTING. For multiple instances of the -s or -S for the the same\n'
@ -233,11 +244,10 @@ usage() {
printf ' "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`\n'
printf ' removes the need to compile and run an executable on the host\n'
printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n'
printf ' `gen/lib2.bc` is perilously close to 4095 characters, the max\n'
printf ' supported length of a string literal in C99 (and it could be\n'
printf ' added to in the future), and `gen/strgen.sh` generates a string\n'
printf ' literal instead of an array, as `gen/strgen.c` does. For most\n'
printf ' production-ready compilers, this limit probably is not\n'
printf ' `gen/lib2.bc` is over 4095 characters, the max supported length\n'
printf ' of a string literal in C99, and `gen/strgen.sh` generates a\n'
printf ' string literal instead of an array, as `gen/strgen.c` does. For\n'
printf ' most production-ready compilers, this limit probably is not\n'
printf ' enforced, but it could be. Both options are still available for\n'
printf ' this reason. If you are sure your compiler does not have the\n'
printf ' limit and do not want to compile and run a binary on the host\n'
@ -667,6 +677,8 @@ coverage=0
karatsuba_len=32
debug=0
hist=1
editline=0
readline=0
extra_math=1
optimization=""
generate_tests=1
@ -697,7 +709,7 @@ dc_default_expr_exit=1
# getopts is a POSIX utility, but it cannot handle long options. Thus, the
# handling of long options is done by hand, and that's the reason that short and
# long options cannot be mixed.
while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
while getopts "abBcdDeEfgGhHk:lMmNO:rS:s:tTvz-" opt; do
case "$opt" in
a) library=1 ;;
@ -707,6 +719,7 @@ while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
C) clean=0 ;;
d) dc_only=1 ;;
D) bc_only=1 ;;
e) editline=1 ;;
E) extra_math=0 ;;
f) force=1 ;;
g) debug=1 ;;
@ -719,6 +732,7 @@ while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
M) install_manpages=0 ;;
N) nls=0 ;;
O) optimization="$OPTARG" ;;
r) readline=1 ;;
S) set_default 0 "$OPTARG" ;;
s) set_default 1 "$OPTARG" ;;
t) time_tests=1 ;;
@ -844,6 +858,8 @@ while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
disable-man-pages) install_manpages=0 ;;
disable-nls) nls=0 ;;
disable-strip) strip_bin=0 ;;
enable-editline) editline=1 ;;
enable-readline) readline=1 ;;
enable-test-timing) time_tests=1 ;;
enable-valgrind) vg=1 ;;
enable-fuzz-mode) fuzz=1 ;;
@ -863,6 +879,8 @@ while getopts "abBcdDEfgGhHk:lMmNO:S:s:tTvz-" opt; do
usage "No arg allowed for --$arg option" ;;
enable-memcheck* | install-all-locales*)
usage "No arg allowed for --$arg option" ;;
enable-editline* | enable-readline*)
usage "No arg allowed for --$arg option" ;;
'') break ;; # "--" terminates argument processing
* ) usage "Invalid option $LONG_OPTARG" ;;
esac
@ -1333,12 +1351,17 @@ fi
# Like the above tested locale support, this tests history.
if [ "$hist" -eq 1 ]; then
if [ "$editline" -ne 0 ] && [ "$readline" -ne 0 ]; then
usage "Must only enable one of readline or editline"
fi
set +e
printf 'Testing history...\n'
flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
flags="$flags -DBC_ENABLE_NLS=$nls -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
flags="$flags -DBC_ENABLE_EDITLINE=$editline -DBC_ENABLE_READLINE=$readline"
flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
@ -1366,13 +1389,56 @@ if [ "$hist" -eq 1 ]; then
fi
# We have to disable the history tests if it is disabled or valgrind is on.
# We have to disable the history tests if it is disabled or valgrind is on. Or
# if we are using editline or readline.
if [ "$hist" -eq 0 ] || [ "$vg" -ne 0 ]; then
test_bc_history_prereqs=" test_bc_history_skip"
test_dc_history_prereqs=" test_dc_history_skip"
history_tests="@printf 'Skipping history tests...\\\\n'"
CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0"
else
if [ "$editline" -eq 0 ] && [ "$readline" -eq 0 ]; then
history_tests="@printf '\$(TEST_STARS)\\\\n\\\\nRunning history tests...\\\\n\\\\n'"
history_tests="$history_tests \&\& \$(TESTSDIR)/history.sh bc -a \&\&"
history_tests="$history_tests \$(TESTSDIR)/history.sh dc -a \&\& printf"
history_tests="$history_tests '\\\\nAll history tests passed.\\\\n\\\\n\$(TEST_STARS)\\\\n'"
else
test_bc_history_prereqs=" test_bc_history_skip"
test_dc_history_prereqs=" test_dc_history_skip"
history_tests="@printf 'Skipping history tests...\\\\n'"
fi
# We are also setting the CFLAGS and LDFLAGS here.
if [ "$editline" -ne 0 ]; then
LDFLAGS="$LDFLAGS -ledit"
CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=1 -DBC_ENABLE_READLINE=0"
elif [ "$readline" -ne 0 ]; then
LDFLAGS="$LDFLAGS -lreadline"
CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=1"
else
CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0"
fi
fi
# Test FreeBSD. This is not in an if statement because regardless of whatever
# the user says, we need to know if we are on FreeBSD. If we are, we cannot set
# _POSIX_C_SOURCE and _XOPEN_SOURCE. The FreeBSD headers turn *off* stuff when
# that is done.
set +e
printf 'Testing for FreeBSD...\n'
flags="-DBC_TEST_FREEBSD -DBC_ENABLE_AFL=0"
"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/include/status.h" > /dev/null 2>&1
err="$?"
if [ "$err" -ne 0 ]; then
printf 'On FreeBSD. Not using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n'
else
history_tests="@printf '\$(TEST_STARS)\\\\n\\\\nRunning history tests...\\\\n\\\\n' \&\& \$(TESTSDIR)/history.sh bc -a \&\& \$(TESTSDIR)/history.sh dc -a \&\& printf '\\\\nAll history tests passed.\\\\n\\\\n\$(TEST_STARS)\\\\n'"
printf 'Not on FreeBSD. Using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n'
CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
fi
# Test OpenBSD. This is not in an if statement because regardless of whatever
@ -1431,9 +1497,11 @@ headers="\$(HEADERS)"
# This series of if statements figure out what source files are *not* needed.
if [ "$extra_math" -eq 0 ]; then
exclude_extra_math=1
manpage_args="E"
unneeded="$unneeded rand.c"
else
exclude_extra_math=0
headers="$headers \$(EXTRA_MATH_HEADERS)"
fi
@ -1645,6 +1713,7 @@ contents=$(replace "$contents" "DC_ERROR_TESTS" "$dc_err_tests")
contents=$(replace "$contents" "DC_TEST_EXEC" "$dc_test_exec")
contents=$(replace "$contents" "BUILD_TYPE" "$manpage_args")
contents=$(replace "$contents" "EXCLUDE_EXTRA_MATH" "$exclude_extra_math")
contents=$(replace "$contents" "LIBRARY" "$library")
contents=$(replace "$contents" "HISTORY" "$hist")

26
gen/bc_help.txt

@ -62,6 +62,14 @@ This bc has three differences to the GNU bc:
This bc also implements the dot (.) extension of the BSD bc.
Options:
{{ A H N HN }}
-E seed --seed=seed
Sets the builtin variable seed to the given value assuming that the given
value is in base 10. It is a fatal error if the given value is not a valid
number.
{{ end }}
-e expr --expression=expr
@ -82,6 +90,12 @@ Options:
Print this usage message and exit.
-I ibase --ibase=ibase
Sets the builtin variable ibase to the given value assuming that the given
value is in base 10. It is a fatal error if the given value is not a valid
number.
-i --interactive
Force interactive mode.
@ -104,6 +118,12 @@ Options:
This bc may load more functions with these options. See the manpage or
online documentation for details.
-O obase --obase=obase
Sets the builtin variable obase to the given value assuming that the given
value is in base 10. It is a fatal error if the given value is not a valid
number.
-P --no-prompt
Disable the prompts in interactive mode.
@ -127,6 +147,12 @@ Options:
Don't print version and copyright.
-S scale --scale=scale
Sets the builtin variable scale to the given value assuming that the given
value is in base 10. It is a fatal error if the given value is not a valid
number.
-s --standard
Error if any non-POSIX extensions are used.

26
gen/dc_help.txt

@ -71,6 +71,14 @@ This dc has a few differences from the two above:
that requires a register name is taken as the register name.
Options:
{{ A H N HN }}
-E seed --seed=seed
Sets the builtin variable seed to the given value assuming that the given
value is in base 10. It is a fatal error if the given value is not a valid
number.
{{ end }}
-e expr --expression=expr
@ -85,6 +93,12 @@ Options:
Print this usage message and exit.
-I ibase --ibase=ibase
Sets the builtin variable ibase to the given value assuming that the given
value is in base 10. It is a fatal error if the given value is not a valid
number.
-i --interactive
Put dc into interactive mode. See the man page for more details.
@ -93,6 +107,12 @@ Options:
Disable line length checking.
-O obase --obase=obase
Sets the builtin variable obase to the given value assuming that the given
value is in base 10. It is a fatal error if the given value is not a valid
number.
-P --no-prompt
Disable the prompts in interactive mode.
@ -101,6 +121,12 @@ Options:
Disable the read prompt in interactive mode.
-S scale --scale=scale
Sets the builtin variable scale to the given value assuming that the given
value is in base 10. It is a fatal error if the given value is not a valid
number.
-V --version
Print version and copyright and exit.

308
gen/strgen.c

@ -33,6 +33,7 @@
*
*/
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@ -40,17 +41,39 @@
#include <errno.h>
// For some reason, Windows needs this header.
#include <fcntl.h>
#include <sys/stat.h>
#ifndef _WIN32
#include <unistd.h>
#endif // _WIN32
// For some reason, Windows can't have this header.
#ifndef _WIN32
#include <libgen.h>
#endif // _WIN32
// This pulls in cross-platform stuff.
#include "../include/bcl.h"
#define BC_ERR(v) (v)
// clang-format off
// The usage help.
static const char* const bc_gen_usage =
"usage: %s input output exclude name [label [define [remove_tabs]]]\n";
static const char* const bc_gen_ex_start = "{{ A H N HN }}";
static const char* const bc_gen_ex_end = "{{ end }}";
// This is exactly what it looks like. It just slaps a simple license header on
// the generated C source file.
static const char* const bc_gen_header =
"// Copyright (c) 2018-2021 Gavin D. Howard and contributors.\n"
"// Licensed under the 2-clause BSD license.\n"
"// *** AUTOMATICALLY GENERATED FROM %s. DO NOT MODIFY. ***\n\n";
// clang-format on
// These are just format strings used to generate the C source.
static const char* const bc_gen_label = "const char *%s = \"%s\";\n\n";
@ -77,8 +100,9 @@ static const char* const bc_gen_name_extern = "extern const char %s[];\n\n";
* @param filename The name of the file.
* @param mode The mode to open the file in.
*/
static void open_file(FILE** f, const char* filename, const char* mode) {
static void
open_file(FILE** f, const char* filename, const char* mode)
{
#ifndef _WIN32
*f = fopen(filename, mode);
@ -93,6 +117,108 @@ static void open_file(FILE** f, const char* filename, const char* mode) {
#endif // _WIN32
}
/**
* A portability file open function. This is copied from src/read.c. Make sure
* to update that if this changes.
* @param path The path to the file to open.
* @param mode The mode to open in.
*/
static int
bc_read_open(const char* path, int mode)
{
int fd;
#ifndef _WIN32
fd = open(path, mode);
#else // _WIN32
fd = -1;
open(&fd, path, mode);
#endif
return fd;
}
/**
* Reads a file and returns the file as a string. This has been copied from
* src/read.c. Make sure to change that if this changes.
* @param path The path to the file.
* @return The contents of the file as a string.
*/
static char*
bc_read_file(const char* path)
{
int e = IO_ERR;
size_t size, to_read;
struct stat pstat;
int fd;
char* buf;
char* buf2;
// This has been copied from src/read.c. Make sure to change that if this
// changes.
assert(path != NULL);
#ifndef NDEBUG
// Need this to quiet MSan.
// NOLINTNEXTLINE
memset(&pstat, 0, sizeof(struct stat));
#endif // NDEBUG
fd = bc_read_open(path, O_RDONLY);
// If we can't read a file, we just barf.
if (BC_ERR(fd < 0))
{
fprintf(stderr, "Could not open file: %s\n", path);
exit(INVALID_INPUT_FILE);
}
// The reason we call fstat is to eliminate TOCTOU race conditions. This
// way, we have an open file, so it's not going anywhere.
if (BC_ERR(fstat(fd, &pstat) == -1))
{
fprintf(stderr, "Could not stat file: %s\n", path);
exit(INVALID_INPUT_FILE);
}
// Make sure it's not a directory.
if (BC_ERR(S_ISDIR(pstat.st_mode)))
{
fprintf(stderr, "Path is directory: %s\n", path);
exit(INVALID_INPUT_FILE);
}
// Get the size of the file and allocate that much.
size = (size_t) pstat.st_size;
buf = (char*) malloc(size + 1);
if (buf == NULL)
{
fprintf(stderr, "Could not malloc\n");
exit(INVALID_INPUT_FILE);
}
buf2 = buf;
to_read = size;
do
{
// Read the file. We just bail if a signal interrupts. This is so that
// users can interrupt the reading of big files if they want.
ssize_t r = read(fd, buf2, to_read);
if (BC_ERR(r < 0)) exit(e);
to_read -= (size_t) r;
buf2 += (size_t) r;
}
while (to_read);
// Got to have a nul byte.
buf[size] = '\0';
close(fd);
return buf;
}
/**
* Outputs a label, which is a string literal that the code can use as a name
* for the file that is being turned into a string. This is important for the
@ -112,8 +238,9 @@ static void open_file(FILE** f, const char* filename, const char* mode) {
* @param name The actual label text, which is a filename.
* @return Positive if no error, negative on error, just like *printf().
*/
static int output_label(FILE* out, const char* label, const char* name) {
static int
output_label(FILE* out, const char* label, const char* name)
{
#ifndef _WIN32
return fprintf(out, bc_gen_label, label, name);
@ -125,7 +252,10 @@ static int output_label(FILE* out, const char* label, const char* name) {
int ret;
// This loop counts how many backslashes there are in the label.
for (i = 0; i < len; ++i) count += (name[i] == '\\');
for (i = 0; i < len; ++i)
{
count += (name[i] == '\\');
}
buf = (char*) malloc(len + 1 + count);
if (buf == NULL) return -1;
@ -136,11 +266,12 @@ static int output_label(FILE* out, const char* label, const char* name) {
// label byte-for-byte, unless it encounters a backslash, in which case, it
// copies the backslash twice to have it escaped properly in the string
// literal.
for (i = 0; i < len; ++i) {
for (i = 0; i < len; ++i)
{
buf[i + count] = name[i];
if (name[i] == '\\') {
if (name[i] == '\\')
{
count += 1;
buf[i + count] = name[i];
}