### Basic Installation with Prefix Source: https://github.com/gavinhoward/bc/blob/master/manuals/build.md Configure the build with a specified installation prefix, then build and install. ```bash ./configure.sh --prefix=/usr make make install ``` -------------------------------- ### BCL Setup Functions Source: https://github.com/gavinhoward/bc/blob/master/manuals/bcl.3.md Functions for initializing, starting, and cleaning up the BCL library, as well as configuring its behavior regarding fatal errors, leading zeroes, and digit clamping. ```APIDOC ## Setup Functions These items allow clients to set up bcl(3). ### `bcl_start` **BclError bcl_start(void);** Starts the BCL library. ### `bcl_end` **void bcl_end(void);** Ends the BCL library. ### `bcl_init` **BclError bcl_init(void);** Initializes the BCL library. ### `bcl_free` **void bcl_free(void);** Frees resources used by the BCL library. ### `bcl_abortOnFatalError` **bool bcl_abortOnFatalError(void);** Checks if the BCL library is set to abort on fatal errors. ### `bcl_setAbortOnFatalError` **void bcl_setAbortOnFatalError(bool abrt);** Sets whether the BCL library should abort on fatal errors. ### `bcl_leadingZeroes` **bool bcl_leadingZeroes(void);** Checks if the BCL library is set to preserve leading zeroes. ### `bcl_setLeadingZeroes` **void bcl_setLeadingZeroes(bool leadingZeroes);** Sets whether the BCL library should preserve leading zeroes. ### `bcl_gc` **void bcl_gc(void);** Performs garbage collection for the BCL library. ### `bcl_digitClamp` **bool bcl_digitClamp(void);** Checks if digit clamping is enabled in the BCL library. ### `bcl_setDigitClamp` **void bcl_setDigitClamp(bool digitClamp);** Sets whether digit clamping is enabled in the BCL library. ``` -------------------------------- ### Out-of-Source Build Example Source: https://github.com/gavinhoward/bc/blob/master/README.md Example for performing an out-of-source build. Ensure the path to configure.sh does not contain spaces. ```shell ../bc/configure.sh make ``` -------------------------------- ### Configure, Build, and Install bc Source: https://github.com/gavinhoward/bc/blob/master/manuals/build.md Standard procedure for configuring, building, and installing bc on POSIX-compliant systems. Environment variables can be set to customize the build. ```bash [ENVIRONMENT_VARIABLE=...] ./configure.sh [build_options...] make make install ``` -------------------------------- ### Install bc and dc Source: https://github.com/gavinhoward/bc/blob/master/README.md Use this command to install the built bc and dc executables. ```shell make install ``` -------------------------------- ### Prepare and start fuzzing bc Source: https://github.com/gavinhoward/bc/blob/master/manuals/development.md This sequence of commands first prepares the build for fuzzing and then loads the tmuxp configuration to start the fuzzing process. It assumes afl-clang-lto is in the PATH. ```bash ./scripts/fuzz_prep.sh tmuxp load tests/fuzzing/bc_afl.yaml ``` -------------------------------- ### Install All Locales Source: https://github.com/gavinhoward/bc/blob/master/manuals/build.md Use the -l flag or --install-all-locales to install all available locales for bc and dc. Both commands are equivalent. ```bash ./configure.sh -l ``` ```bash ./configure.sh --install-all-locales ``` -------------------------------- ### Example of output function with global stacks enabled Source: https://github.com/gavinhoward/bc/blob/master/manuals/bc/EN.1.md This example demonstrates how to write a function that prints a number in a specified base when the -g option is used to make ibase, obase, and scale global stacks. This allows functions to modify these globals without affecting other parts of the program. ```bc define output(x,b) { auto ia, oa, s; ia = ibase; oa = obase; s = scale; ibase = b; obase = b; scale = 0; print x; ibase = ia; obase = oa; scale = s; } ``` -------------------------------- ### Return Statement Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt A simple return statement example. ```bc return (0) ``` -------------------------------- ### Configure bc with all locales Source: https://github.com/gavinhoward/bc/blob/master/NEWS.md For package maintainers, pass the -l flag to configure.sh to install all locales. ```bash ./configure.sh -l ``` -------------------------------- ### Divmod and Modexp Function Calls Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Examples of calling divmod and modexp functions with various argument combinations. ```bc divmod 24 modexp 23 divmod(if modexp(if divmod(24) modexp(24) divmod(24 24) modexp(24 24) divmod(24,) modexp(24,) divmod(24, modexp(24, divmod(24,5 modexp(24,5 divmod(24,5) modexp(24,5) divmod(24,5,) modexp(24,5,) divmod(24,5, modexp(24,5, divmod(24,5,4 modexp(24,5,4 divmod(24,5,a modexp(24,5,a divmod(24,5,a[]) divmod(24,5,a[ divmod(24,5,a[2 divmod(24,5,a[2] divmod(24,5,a[]; modexp(24,5,a; divmod(24,5,a[];) modexp(24,5,a;) divmod(24,5,4) scale(4.5) modexp(25,5,5) scale(.2093 a2(0,0) ``` -------------------------------- ### BC Library Addition Example Source: https://github.com/gavinhoward/bc/blob/master/manuals/development.md Demonstrates how to add two numbers using the bcl library. Operands are consumed by the function. ```c n = bcl_add(bcl_mul(a, b), bcl_div(c, d)); ``` -------------------------------- ### BC Library Addition with Duplication Example Source: https://github.com/gavinhoward/bc/blob/master/manuals/development.md Shows how to add two numbers using the bcl library while preserving the original operands using bcl_dup(). ```c n = bcl_add(bcl_mul(bcl_dup(a), bc_dup(b)), bcl_div(bcl_dup(c), bcl_dup(d))); ``` -------------------------------- ### Load tmuxp configuration for fuzzing Source: https://github.com/gavinhoward/bc/blob/master/manuals/development.md Use this command to load the tmuxp configuration for starting fuzzing sessions. Ensure the path to the YAML file is correct. ```bash tmuxp load tests/fuzzing/bc_afl.yaml ``` -------------------------------- ### Infinite Loop Example Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors/03.txt This snippet demonstrates a potentially infinite loop structure. Use with caution. ```c for (i = 0; ; ) ``` -------------------------------- ### Run Test Suite with GCC Coverage Source: https://github.com/gavinhoward/bc/blob/master/manuals/development.md Execute the test suite with GCC for coverage information. This requires gcc, gcov, and gcovr to be installed. ```bash rig --compiler=gcc -Ddebug=1 -Doptimization=3 -Dcoverage=1 rig coverage ``` -------------------------------- ### bc Array Length Example Source: https://github.com/gavinhoward/bc/blob/master/gen/bc_help.txt Demonstrates how to get the number of elements in a bc array using the length() function. This feature differs from GNU bc. ```bc a[0] = 0 length(a[]) ``` -------------------------------- ### BC Array Length and Modification Example Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/length0.txt Demonstrates the usage of `length`, `len1`, `len2`, `change_len1`, and `change_len2` functions in BC. It shows how to get the initial length, modify the array, and then check the length again. ```bc length(temp[]) len1(temp[]) len2(temp[]) change_len1(temp[]) length(temp[]) len1(temp[]) len2(temp[]) change_len2(temp[]) length(temp[]) len1(temp[]) len2(temp[]) ``` -------------------------------- ### BC Length Function with Array Elements Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/length.txt Illustrates how the `length` function can be used with array elements. Note that array indexing in BC starts from 0. The `length(a[])` syntax is used to get the length of the array itself, not an element. ```bc a[0] = 0 a[5] = 0 length(a[]) ``` -------------------------------- ### Get Help for configure.sh Source: https://github.com/gavinhoward/bc/blob/master/manuals/build.md Displays available options and environment variables for the configure.sh script. Use either short or long options, but not both simultaneously. ```bash ./configure.sh -h ``` ```bash ./configure.sh --help ``` -------------------------------- ### Configure Math Library Build Source: https://github.com/gavinhoward/bc/blob/master/manuals/build.md Use the -a or --library option to build the math library for bc and dc. ```bash ./configure.sh -a ./configure.sh --library ``` -------------------------------- ### Disable Manpages Installation Source: https://github.com/gavinhoward/bc/blob/master/manuals/build.md Use either the -M flag or --disable-man-pages to prevent manpages from being installed. Both commands are equivalent. ```bash ./configure.sh -M ``` ```bash ./configure.sh --disable-man-pages ``` -------------------------------- ### Default Build with Optimization Source: https://github.com/gavinhoward/bc/blob/master/README.md Use this command for the default build with optimization level 3. ```shell ./configure.sh -O3 make ``` -------------------------------- ### While Loop Syntax Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Demonstrates different syntaxes for while loops. ```bc while e!=0 { i+=1 } while (e!=0) { i+=1 } ``` -------------------------------- ### Build bc with MSBuild on Windows Source: https://github.com/gavinhoward/bc/blob/master/README.md Use MSBuild to build the bc calculator on Windows. Replace with Debug or Release. ```bash msbuild -property:Configuration= vs/bc.sln ``` -------------------------------- ### Array Assignment Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Example of assigning a value to an array element. ```bc a[] = 4 ``` -------------------------------- ### Build bcl Library with MSBuild on Windows Source: https://github.com/gavinhoward/bc/blob/master/README.md Use MSBuild to build the bcl library on Windows. Replace with Debug, ReleaseMD, or ReleaseMT. ```bash msbuild -property:Configuration= vs/bcl.sln ``` -------------------------------- ### Run Default Test Suite Source: https://github.com/gavinhoward/bc/blob/master/manuals/build.md Execute the standard test suite for the project. Ensure the project is built before running tests. ```bash make test ``` -------------------------------- ### Invalid Unary Operations Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Examples of incorrect usage of unary operators. ```bc + 4 * 3 + 4 + 3 * 3 + 2 ``` -------------------------------- ### Get Array Length Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors/32.txt Assigns the length of an array 'a' to the variable 'l'. ```bc l = length(a[]) ``` -------------------------------- ### String Concatenation and Arithmetic Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Examples of string concatenation and arithmetic operations on strings. ```bc v = "stuff" + "other" v = "stuff"; v + v v = "stuff"; v * 3 v = "stuff"; v - 3 v = "stuff"; v / 3 ``` -------------------------------- ### Conditional Expression Syntax Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt An example of a conditional expression with potential syntax issues. ```bc x$if(x) x else x ``` -------------------------------- ### BC Array Initialization and Function Call Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors/38.txt Illustrates initializing an array and calling a function that processes it. Note the syntax for array passing and variable assignment. ```bc len = 16 a1((b[]) + ++ase^= , len) ``` -------------------------------- ### Invalid Random Number Generation Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Examples of invalid inputs for the irand function. ```bc irand(-4) irand(3289.10827340) ``` -------------------------------- ### Invalid Function Parameter Definitions Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Examples of incorrect function parameter syntax. ```bc define x(3) { return q(e); } define x([]e) { return q(e); } define x([]) { return q(e); } define x(e,[]) { return q(e); } define x(a[]) { return a[]; } define x(*a) { return a; } define x(a) return a; ``` -------------------------------- ### Define and Call Simple Functions in BC Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/misc2.txt Demonstrates defining functions that return a constant value and calling them. ```bc define w() { auto z; return 1; } w() ``` ```bc define x() { "x" return (1) } x() ``` ```bc define y() { "y" return (2) } y() ``` ```bc define z() { "z" return (3) } z() ``` -------------------------------- ### Invalid Array Access and Operations Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Examples of incorrect array indexing and operations. ```bc pll[zx=] j[s !>5d a(1..) a(1;) 1.. 1..0 ``` -------------------------------- ### List make Targets Source: https://github.com/gavinhoward/bc/blob/master/manuals/build.md Shows all available targets for the make command after the configure.sh script has been executed. ```bash make help ``` -------------------------------- ### Invalid Arithmetic Operations Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Shows examples of invalid arithmetic operations and syntax. ```bc 3 $ 7 4 @^ 5 3 + 3 - - 233*+ 32 233*+ 32 869356734856 293 * += 38297 293 * += 38297 2839 293 - %= 38297 a * += 38297 2839 a += * 38297 a += * 38297 2839 a %= % 38297 a %= / 38297 2839 ``` -------------------------------- ### Read Function Variations Source: https://github.com/gavinhoward/bc/blob/master/tests/bc/errors.txt Examples of using the read function with different argument patterns. ```bc read read( read() read() read() ```