### Quick Start: Install and run DevDocs locally Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/devdocs_README.md Commands to clone the repository, install dependencies, download default documentation, and start the server. Requires Ruby 2.4.2, libcurl, and a JavaScript runtime supported by ExecJS. ```bash git clone https://github.com/Thibaut/devdocs.git && cd devdocs gem install bundler bundle install bundle exec thor docs:download --default bundle exec rackup ``` -------------------------------- ### libpng write setup examples Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/external/slic-tests/libpng-manual.txt These C code examples from the libpng manual show the essential steps for writing a PNG file: opening the output file, creating and initializing the write structures, setting up error handling with setjmp, optionally disabling invalid index checking, initializing I/O, skipping the signature, and setting a write status callback. They are presented as separate code blocks in the source, each illustrating a specific API call or setup. ```c FILE *fp = fopen(file_name, "wb"); if (!fp) return (ERROR); ``` ```c png_structp png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, user_error_fn, user_warning_fn); if (!png_ptr) return (ERROR); png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr, (png_infopp)NULL); return (ERROR); } ``` ```c png_structp png_ptr = png_create_write_struct_2 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, user_error_fn, user_warning_fn, (png_voidp) user_mem_ptr, user_malloc_fn, user_free_fn); ``` ```c if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); return (ERROR); } ... return; ``` ```c png_set_check_for_invalid_index(png_ptr, 0); ``` ```c png_init_io(png_ptr, fp); ``` ```c png_set_sig_bytes(png_ptr, 8); ``` ```c void write_row_callback(png_structp png_ptr, png_uint_32 row, int pass); { /* put your code here */ } ``` ```c png_set_write_status_fn(png_ptr, write_row_callback); ``` -------------------------------- ### Bottle example: basic routes and static file serving Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic3/mit_18.txt Example from the Bottle documentation showing how to define routes with the @route decorator, handle GET and POST requests, and serve static files. It uses the run() function to start the server on localhost:8080. ```python from bottle import route, run, request, response, static_file, abort @route('/') def hello_world(): return 'Hello World!' @route('/hello/:name') def hello_name(name): return 'Hello %s!' % name @route('/hello', method='POST') def hello_post(): name = request.POST['name'] return 'Hello %s!' % name @route('/static/:filename#.*#') def static(filename): return static_file(filename, root='/path/to/static/files/') run(host='localhost', port=8080) ``` -------------------------------- ### Installation and import: ES module and CommonJS Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/plugin_license/license_reference/scan/unknown-ref-to-key-file-root/README.md Shows how to install js-tokens via npm and import it using ES modules or CommonJS. The example provides both import styles. ```javascript import jsTokens from "js-tokens" // or: var jsTokens = require("js-tokens").default ``` -------------------------------- ### Clone repository and configure development environment Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/getting-started/contribute/contributing-docs.rst Setup commands to clone the repository and install dependencies in a virtual environment. Use `make dev` as an alternative to `./configure --dev`. On Windows, run `configure --dev`. ```default git clone https://github.com/aboutcode-org/scancode-toolkit.git ``` ```default cd scancode-toolkit ./configure --dev ``` -------------------------------- ### Setup arguments array and module parameter Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/gpl-2.0-plus_38.txt Defines the default setup arguments array and the module parameter for setup strings. ```c static char *setup_args[] = { "", "", "", "", "", "", "", "", "" }; /* filled in by 'insmod' */ static char *setup_strings; module_param(setup_strings, charp, 0); ``` -------------------------------- ### Install go-spew with go get Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/external/fossology-tests/ISC/go-spew.txt Install the go-spew package using the go get command. ```bash $ go get -u github.com/davecgh/go-spew/spew ``` -------------------------------- ### Sun Partition Setup Function Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic2/bsd-original-uc_and_gpl_and_gpl_and_gpl_and_other.txt Sets a Sun partition entry with given start, stop, and system ID. Converts start cylinder and number of sectors using SUN_SSWAP32 and marks the partition as changed. ```C static void set_sun_partition(int i, uint start, uint stop, int sysid) { sunlabel->infos[i].id = sysid; sunlabel->partitions[i].start_cylinder = SUN_SSWAP32(start / (heads * sectors)); sunlabel->partitions[i].num_sectors = SUN_SSWAP32(stop - start); set_changed(i); } ``` -------------------------------- ### Install pip using get-pip.py Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/pypi/source-package/pip-22.0.4/NEWS.rst Download and run the get-pip.py installer using curl and Python. This may need to be run as root. Ensure distribute is installed first. ```bash $ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py $ python get-pip.py ``` -------------------------------- ### Start a local etcd cluster with goreman Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/external/fossology-tests/Apache/etcd.txt Starts a local example cluster using goreman, which manages Procfile-based applications. This brings up 3 etcd members (infra1, infra2, infra3) and an etcd proxy (proxy) that compose a cluster locally. ```sh goreman start ``` -------------------------------- ### Clone and install urllib3 from source Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/pypi/unpacked_wheel/metadata-2.0/urllib3-1.26.4.dist-info/DESCRIPTION.rst Commands to clone the urllib3 repository from GitHub and install it using setup.py. ```bash $ git clone git://github.com/urllib3/urllib3.git $ python setup.py install ``` -------------------------------- ### Build and install pybox2d Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/license_detection/reference-to-package/physics/README.md Clone the pybox2d repository, build it with setup.py, and install it with pip. Requires swig to be installed beforehand. ```bash git clone https://github.com/pybox2d/pybox2d cd pybox2d # Make sure you have installed swig python3 setup.py build pip3 install . --system ``` -------------------------------- ### Create install and uninstall script files Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic3/no_license_76.txt Creates the install and uninstall script files by writing configuration lines. The uninstall target writes TARGET_DRIVE to the install script, not the uninstall script. ```makefile create_install_file: @cmd /C echo Creating install file $(INSTALL_SCRIPT).... -@del $(INSTALL_SCRIPT) @cmd /C echo [ANY_MODE] >> $(INSTALL_SCRIPT) @cmd /C echo [TARGET_DRIVE]=80 >> $(INSTALL_SCRIPT) @cmd /C echo [TGBKOLIUF_ID]=$(TGBKOLIUF_ID) >> $(INSTALL_SCRIPT) @cmd /C echo [WBGTF_MODE]=259 >> $(INSTALL_SCRIPT) @cmd /C echo [INSTALL] >> $(INSTALL_SCRIPT) ``` ```makefile create_uninstall_file: @cmd /C echo Creating un-install file $(UNINSTALL_SCRIPT).... -@del $(UNINSTALL_SCRIPT) @cmd /C echo [TARGET_DRIVE]=80 >> $(INSTALL_SCRIPT) @cmd /C echo [ANY_MODE] >> $(UNINSTALL_SCRIPT) @cmd /C echo [UNINSTALL_WER] >> $(UNINSTALL_SCRIPT) ``` -------------------------------- ### Install the DHCP distribution with make install Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic3/no_license_41.txt Install the built DHCP distribution. If an old version is installed, consider saving it before running this command. ```shell make install ``` -------------------------------- ### Connect to DHCP server and get lease expiration Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic3/no_license_66.txt Complete example program that connects to a local DHCP server, retrieves the lease for IP 10.0.0.101, and prints the lease expiration time. Most error checking is omitted for brevity. ```c #include #include #include #include #include #include #include int main (int argc, char **argv) { dhcpctl_data_string ipaddrstring = NULL; dhcpctl_data_string value = NULL; dhcpctl_handle connection = NULL; dhcpctl_handle lease = NULL; isc_result_t waitstatus; struct in_addr convaddr; time_t thetime; dhcpctl_initialize (); dhcpctl_connect (&connection, "127.0.0.1", 7911, 0); dhcpctl_new_object (&lease, connection, "lease"); memset (&ipaddrstring, 0, sizeof ipaddrstring); inet_pton(AF_INET, "10.0.0.101", &convaddr); omapi_data_string_new (&ipaddrstring, 4, MDL); memcpy(ipaddrstring->value, &convaddr.s_addr, 4); dhcpctl_set_value (lease, ipaddrstring, "ip-address"); dhcpctl_open_object (lease, connection, 0); dhcpctl_wait_for_completion (lease, &waitstatus); if (waitstatus != ISC_R_SUCCESS) { /* server not authoritative */ exit (0); } dhcpctl_data_string_dereference(&ipaddrstring, MDL); dhcpctl_get_value (&value, lease, "ends"); memcpy(&thetime, value->value, value->len); } ``` -------------------------------- ### Example custom template output Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/tutorials/configuring-scan-output-formats.rst Example output from the custom template, showing license and copyright data for a sample file. ```none [ location:"samples/JGroups/LICENSE", copyright:"Copyright (c) 1991, 1999 Free Software Foundation, Inc.", location:"samples/JGroups/LICENSE", copyright:"copyrighted by the Free Software Foundation", ] ``` -------------------------------- ### Build and install libmodbus Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/external/fossology-tests/LGPL/README.rst Shell commands to build and install the library from source. Run them in sequence in the project root directory. ```shell ./autogen.sh; ./configure; make; make install ``` -------------------------------- ### Install sugar-physics-activity on Debian/Ubuntu Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/license_detection/reference-to-package/physics/README.md Install the Physics activity on Debian and Ubuntu systems using the apt package manager. ```bash apt install sugar-physics-activity ``` -------------------------------- ### Install sugar-physics on Fedora Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/license_detection/reference-to-package/physics/README.md Install the Physics activity on Fedora systems using the dnf package manager. ```bash dnf install sugar-physics ``` -------------------------------- ### Install toml from PyPI Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/pypi/unpacked_wheel/metadata-2.0/toml-0.10.1.dist-info/DESCRIPTION.rst Install the latest release of the toml library from PyPI. ```bash pip install toml ``` -------------------------------- ### Install spdx-license-ids with npm Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/external/license_tools/spdx-license-ids/README.md Install the spdx-license-ids package via npm. ```shell npm install spdx-license-ids ``` -------------------------------- ### Install Python development tools on Fedora/RHEL Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/license_detection/reference-to-package/physics/README.md Install pip and setuptools on Fedora/RHEL systems for Python development. ```bash sudo dnf install python3-pip python3-setuptools ``` -------------------------------- ### Install toml development version from GitHub Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/pypi/unpacked_wheel/metadata-2.0/toml-0.10.1.dist-info/DESCRIPTION.rst Install the latest development version of toml by cloning the repository and running setup.py. ```bash git clone https://github.com/uiri/toml.git cd toml python setup.py install ``` -------------------------------- ### Install npm-consider globally Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic4/README_not_pd.md Install npm-consider globally via npm. ```bash npm install -g npm-consider ``` -------------------------------- ### Create examples with BeautyJ Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/gpl_and_gpl_and_gpl_and_lgpl-2.0_and_other.txt Defines the 'example' target that redefines the beautyj task, converts Java sources to XML, copies example Java files, and runs BeautyJ to generate beautified sources and an XML output. ```XML ``` -------------------------------- ### Display ScanCode examples with --examples Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/reference/scancode-cli/cli-help-text-options.rst Displays basic usage examples for ScanCode, covering scanning single files/directories, output formats, license/copyright scanning, ignoring files, glob patterns, and verbose mode. ```shell scancode --examples ``` -------------------------------- ### Output of mp_init_set example Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/external/fossology-tests/Public-domain/bn.tex Expected output of the example program that initializes and sets two mp_ints and prints them. ```text Number1, Number2 == 100, 1023 ``` -------------------------------- ### Install sanitized_anchor_name with go get Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/external/fossology-tests/MIT/MIT-ref_f.txt Install the sanitized_anchor_name package using the go get command. ```bash go get -u github.com/shurcooL/sanitized_anchor_name ``` -------------------------------- ### Run scancode -h to configure installation Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/getting-started/installation/install-scancode-from-release-archives.rst This command configures the ScanCode installation and displays the command help. It is the first command to run after changing to the ScanCode directory. ```default scancode -h ``` -------------------------------- ### setup.cfg for scancode-hello plugin Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/tutorials/adding-a-post-scan-plugin.rst setup.cfg for the plugin, setting the license file, universal wheel, and a release alias. ```default [metadata] license_file = NOTICE [bdist_wheel] universal = 1 [aliases] release = clean --all bdist_wheel ``` -------------------------------- ### Verify ScanCode installation with help Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/getting-started/installation/install-scancode-using-docker.rst Runs the ScanCode container and forwards the `--help` argument to the `scancode` command to verify the installation. ```shell docker run scancode-toolkit --help ``` -------------------------------- ### setup.py for scancode-hello plugin Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/tutorials/adding-a-post-scan-plugin.rst setup.py for the scancode-hello plugin, defining package metadata and the entry point that registers the SayHello class under the 'scancode_post_scan' group. ```default #!/usr/bin/env python # -*- encoding: utf-8 -*- from __future__ import absolute_import from __future__ import print_function from glob import glob from os.path import basename from os.path import join from os.path import splitext from setuptools import find_packages from setuptools import setup desc = '''A ScanCode post-scan plugin to to illustrate the creation of a simple post-scan plugin.''' setup( name='scancode-hello', version='1.0.0', license='Apache-2.0 with ScanCode acknowledgment', description=desc, long_description=desc, author='nexB', author_email='info@aboutcode.org', url='https://github.com/aboutcode-org/scancode-plugins/blob/main/misc/scancode-hello/', packages=find_packages('src'), package_dir={'': 'src'}, py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')], include_package_data=True, zip_safe=False, classifiers=[ # complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Topic :: Utilities', ], keywords=[ 'scancode', 'plugin', 'post-scan' ], install_requires=[ 'scancode-toolkit', ], entry_points={ 'scancode_post_scan': [ 'hello = hello_scancode.hello_scancode:SayHello', ], } ) ``` -------------------------------- ### Example scan output with license_policy Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/reference/scancode-plugins/licence-policy-plugin.rst Example JSON output from a scan with the license policy plugin. Shows the `license_policy` attribute added to a resource when a matching license is detected. ```none { "path": "samples/zlib/deflate.c", "type": "file", "detected_license_expression": "zlib", "detected_license_expression_spdx": "Zlib", "license_detections": [ { "license-expression": "zlib", ... ... ... } ], "license_policy": { "license_key": "zlib", "label": "Approved License", "color_code": "#00800", "icon": "icon-ok-circle" }, "scan_errors": [] } ``` -------------------------------- ### Set up development environment Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/src/commoncode/README.rst Run these commands to configure and activate a development environment for commoncode. ```bash ./configure --dev source venv/bin/activate ``` -------------------------------- ### ScanCode --examples output for version 32.0.0 Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/reference/scancode-cli/cli-help-text-options.rst Output of `scancode --examples` for ScanCode version 32.0.0. Shows command-line examples for scanning files/directories, output formats (JSON, HTML), ignoring files, glob patterns, and verbose mode. Includes notes on Windows path separators and glob pattern behavior. ```default Scancode command lines examples: (Note for Windows: use '\' back slash instead of '/' forward slash for paths.) Scan a single file for copyrights. Print scan results to stdout as pretty JSON: scancode --copyright samples/zlib/zlib.h --json-pp - Scan a single file for licenses, print verbose progress to stderr as each file is scanned. Save scan to a JSON file: scancode --license --verbose samples/zlib/zlib.h --json licenses.json Scan a directory explicitly for licenses and copyrights. Redirect JSON scan results to a file: scancode --license --copyright samples/zlib/ --json - > scan.json Scan a directory while ignoring a single file. Scan for license, copyright and package manifests. Use four parallel processes. Print scan results to stdout as pretty formatted JSON. scancode -lc --package --ignore README --processes 4 --json-pp - samples/ Scan a directory while ignoring all files with .txt extension. Print scan results to stdout as pretty formatted JSON. It is recommended to use quotes around glob patterns to prevent pattern expansion by the shell: scancode --json-pp - --ignore "*.txt" samples/ Special characters supported in GLOB pattern: - * matches everything - ? matches any single character - [seq] matches any character in seq - [!seq] matches any character not in seq For a literal match, wrap the meta-characters in brackets. For example, '[?]' matches the character '?'. For details on GLOB patterns see https://en.wikipedia.org/wiki/Glob_(programming). Note: Glob patterns cannot be applied to path as strings. For example, this will not ignore "samples/JGroups/licenses". scancode --json - --ignore "samples*licenses" samples/ Scan a directory while ignoring multiple files (or glob patterns). Print the scan results to stdout as JSON: scancode --json - --ignore README --ignore "*.txt" samples/ Scan a directory for licenses and copyrights. Save scan results to an HTML file: scancode --license --copyright --html scancode_result.html samples/zlib ``` -------------------------------- ### Entry point configuration in setup.py Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/tutorials/adding-a-post-scan-plugin.rst Shows the entry_points line that maps the 'hello' command to the SayHello class in the hello_scancode module. The first hello_scancode is the folder name, the second is the .py file, and SayHello is the plugin class. ```default 'hello = hello_scancode.hello_scancode:SayHello', ``` -------------------------------- ### Compile and run HelloWorld with new templates Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic3/no_license_68.txt Compile and run the HelloWorld example after adding new templates. The output shows the rendered messages for the helloWorld, helloName, and helloNames templates. ```bash ~/helloworld_java$ javac -classpath soy-20100426.jar HelloWorld.java ~/helloworld_java$ java -classpath .:soy-20100426.jar HelloWorld Hello world! ----------------- Hello Ana! ----------------- Hello Ana!
Hello Bob!
Hello Cid!
Hello Dee! ``` -------------------------------- ### Get IEEE 802.11 mode with iwpriv Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/external/fossology-tests/Intel/README.ipw3945.txt Reports the configured IEEE 802.11 mode. Example output shows '802.11abg (7)'. ```shell % iwpriv eth1 get_mode eth1 get_mode:802.11abg (7) ``` -------------------------------- ### Build and preview docs locally Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/getting-started/contribute/contributing-docs.rst Build the HTML documentation locally and open the output in a browser. Requires the virtual environment to be activated. ```default source venv/bin/activate make docs ``` ```default open docs/_build/index.html ``` -------------------------------- ### Example plugin directory structure Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/how-to-guides/how-to-install-new-license-plugin.rst Directory structure of an example external license plugin with tests, showing the layout of source, license, rules, and test files. ```default licenses_to_install1/ ├── src/ │ └── licenses_to_install1/ │ ├── licenses/ │ │ ├── example-installed-1.LICENSE │ ├── rules/ │ │ ├── example-installed-1.RULE │ └── __init__.py/ ├── tests/ │ ├── data/ │ │ ├── example-installed-1.txt │ │ └── example-installed-1.txt.yml │ └── test_detection_datadriven.py ├── apache-2.0.LICENSE ├── MANIFEST.in ├── setup.cfg └── setup.py ``` -------------------------------- ### Initialize confdefs.h and write package defines Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/fsf-free_and_fsf-free_and_fsf-free.txt Removes old conftest files and confdefs.h, creates a new confdefs.h with a newline, then appends PACKAGE_NAME, PACKAGE_TARNAME, PACKAGE_VERSION, PACKAGE_STRING, and PACKAGE_BUGREPORT defines using here-documents. ```shell # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -rf conftest* confdefs.h # AIX cpp loses on an empty file, so make sure it contains at least a newline. echo >confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF ``` -------------------------------- ### Basic urllib3 usage with PoolManager Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/pypi/unpacked_wheel/metadata-2.0/urllib3-1.26.4.dist-info/DESCRIPTION.rst Shows how to make a simple GET request using urllib3's PoolManager. The example prints the HTTP status code and response data. ```python >>> import urllib3 >>> http = urllib3.PoolManager() >>> r = http.request('GET', 'http://httpbin.org/robots.txt') >>> r.status 200 >>> r.data 'User-agent: *\nDisallow: /deny\n' ``` -------------------------------- ### Get status function start in C Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/gpl-2.0-plus_26.txt Starts the get_status function that retrieves a status string from name_hashtable based on the status_node. The comment indicates that num 1 returns want status, 2 returns flag, and 3 returns status. The function body is incomplete in the source, showing only the initial variable declarations. ```C /* if num = 1, it returns the want status, 2 returns flag, 3 returns status */ unsigned int get_status(const unsigned int status_node, const int num) { char *status_string = name_hashtable[status_hashtable[status_node]->status]; char *state_sub_string; unsigned int state_sub_num; int len; int i; ``` -------------------------------- ### Run HelloWorld with generated constants Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic3/no_license_68.txt Run the HelloWorld example after using SoyParseInfoGenerator. The output is the same as before, showing the rendered messages for the three templates. ```bash ~/helloworld_java$ java -classpath .:soy-20100426.jar HelloWorld Hello world! ----------------- Hello Ana! ----------------- Hello Ana!
Hello Bob!
Hello Cid!
Hello Dee! ``` -------------------------------- ### Setup and executable permission for config.status Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/fsf-free_and_fsf-free_and_fsf-free_and_gpl-2.0-autoconf_and_other.txt Sets up file descriptor 6 and marks the start of the main body of the config.status script. It then makes the script executable if the write succeeded, otherwise sets ac_write_fail. ```shell exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 ``` -------------------------------- ### tw_initialize_units() GET_PARAM command setup Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/gpl-2.0_17.txt Starts unit initialization by setting up a GET_PARAM command packet to retrieve unit information from the controller. Returns 1 if the command packet virtual address is NULL. ```C int tw_initialize_units(TW_Device_Extension *tw_dev) { int found = 0, error = 0; unsigned char request_id = 0; TW_Command *command_packet; TW_Param *param; int i, j, imax, num_units = 0, num_raid_five = 0; unsigned long command_que_value; u32 command_que_addr; u32 response_que_addr; TW_Response_Queue response_queue; unsigned long param_value; unsigned char *is_unit_present; unsigned char *raid_level; dprintk(KERN_NOTICE "3w-xxxx: tw_initialize_units()\n"); command_que_addr = tw_dev->registers.command_que_addr; response_que_addr = tw_dev->registers.response_que_addr; /* Setup the command packet */ command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; if (command_packet == NULL) { printk(KERN_WARNING "3w-xxxx: tw_initialize_units(): Bad command packet virtual address.\n"); return 1; } memset(command_packet, 0, sizeof(TW_Sector)); command_packet->byte0.opcode = TW_OP_GET_PARAM; command_packet->byte0.sgl_offset = 2; command_packet->size = 4; command_packet->request_id = request_id; command_packet->byte3.unit = 0; command_packet->byte3.host_id = 0; command_packet->status = 0; command_packet->flags = 0; command_packet->byte6.block_count = 1; ``` -------------------------------- ### Calculate max cmds per lun and setup queues Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/gpl-2.0_17.txt Sets up command queue parameters for a 3ware controller. If RAID 5 is used, it uses a larger bounce buffer size; otherwise, it uses the configured or default command per LUN value. ```C /* Calculate max cmds per lun, and setup queues */ if ((tw_dev->num_raid_five > 0) && (tw_dev->tw_pci_dev->device == TW_DEVICE_ID)) { tw_host->cmd_per_lun = (TW_MAX_BOUNCEBUF-2)/tw_dev->num_units; tw_dev->free_head = TW_Q_START; tw_dev->free_tail = TW_Q_START; tw_dev->free_wrap = TW_MAX_BOUNCEBUF - 1; } else { /* Check for user configured cmd_per_lun */ #ifdef CONFIG_3W_XXXX_CMD_PER_LUN tw_host->cmd_per_lun = CONFIG_3W_XXXX_CMD_PER_LUN; if (tw_host->cmd_per_lun > TW_MAX_CMDS_PER_LUN) tw_host->cmd_per_lun = TW_MAX_CMDS_PER_LUN; #else /* Use SHT cmd_per_lun default */ tw_host->cmd_per_lun = TW_MAX_CMDS_PER_LUN; #endif tw_dev->free_head = TW_Q_START; tw_dev->free_tail = TW_Q_START; tw_dev->free_wrap = TW_Q_LENGTH - 1; } ``` -------------------------------- ### Example test package set-up with bsr _060FPSP_TEST+128+0 Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic3/motorola_6.txt Example test package set-up showing system-provided print routines and a call to the floating-point test entry point. The _print_str and _print_num routines are placeholders that the system must provide. The bsr instruction invokes the main FP test entry point at offset 0x00 (128+0). ```assembly _print_str: . # provided by system rts _print_num: . # provided by system rts . . bsr _060FPSP_TEST+128+0 . . rts ``` -------------------------------- ### Amiga scheduler timer initialization Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/gpl_18.txt Sets up the Amiga scheduler timer: allocates a resource for the CIAB timer, configures timer A in continuous mode from Eclk, installs an interrupt handler for IRQ_AMIGA_CIAB_TA, and starts the timer. Warns if resource allocation fails. ```C static unsigned short jiffy_ticks; static void __init amiga_sched_init(void (*timer_routine)(int, void *, struct pt_regs *)) { static struct resource sched_res = { "timer", 0x00bfd400, 0x00bfd5ff, }; jiffy_ticks = (amiga_eclock+HZ/2)/HZ; if (request_resource(&mb_resources._ciab, &sched_res)) printk("Cannot allocate ciab.ta{lo,hi}\n"); ciab.cra &= 0xC0; /* turn off timer A, continuous mode, from Eclk */ ciab.talo = jiffy_ticks % 256; ciab.tahi = jiffy_ticks / 256; /* install interrupt service routine for CIAB Timer A * * Please don't change this to use ciaa, as it interferes with the * SCSI code. We'll have to take a look at this later */ request_irq(IRQ_AMIGA_CIAB_TA, timer_routine, 0, "timer", NULL); /* start timer */ ciab.cra |= 0x11; } ``` -------------------------------- ### Generate SPDX tag-value output with --spdx-tv Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/reference/scancode-cli/cli-output-format-options.rst Run a ScanCode scan on the samples directory and publish results in SPDX tag-value format. The output file starts with a document information section and a creation info section, as shown in the example output. ```shell scancode -clpieu --spdx-tv output.spdx samples ``` ```none # Document Information SPDXVersion: SPDX-2.1 DataLicense: CC0-1.0 DocumentComment: Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. No content created from ScanCode should be considered or used as legal advice. Consult an Attorney for any legal advice. ScanCode is a free software code scanning tool from nexB Inc. and others. Visit https://github.com/aboutcode-org/scancode-toolkit/ for support and download. # Creation Info Creator: Tool: ScanCode 2.2.1 Created: 2019-09-22T21:55:04Z ``` -------------------------------- ### Find lease: initialize and get client IP Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic2/bsd-new_14.txt Starts the find_lease function by declaring local variables and determining the client IP address. If ciaddr is set, it copies that; otherwise it looks up the DHCP requested address option and evaluates it, setting got_requested_address if found. ```C int find_lease (struct lease **lp, struct packet *packet, struct shared_network *share, int *ours, int *allocatedp, struct lease *ip_lease_in, const char *file, int line) { struct lease *uid_lease = (struct lease *)0; struct lease *ip_lease = (struct lease *)0; struct lease *hw_lease = (struct lease *)0; struct lease *lease = (struct lease *)0; struct iaddr cip; struct host_decl *hp = (struct host_decl *)0; struct host_decl *host = (struct host_decl *)0; struct lease *fixed_lease = (struct lease *)0; struct lease *next = (struct lease *)0; struct option_cache *oc; struct data_string d1; int have_client_identifier = 0; struct data_string client_identifier; int status; struct hardware h; if (packet -> raw -> ciaddr.s_addr) { cip.len = 4; memcpy (cip.iabuf, &packet -> raw -> ciaddr, 4); } else { /* Look up the requested address. */ oc = lookup_option (&dhcp_universe, packet -> options, DHO_DHCP_REQUESTED_ADDRESS); memset (&d1, 0, sizeof d1); if (oc && evaluate_option_cache (&d1, packet, (struct lease *)0, (struct client_state *)0, packet -> options, (struct option_state *)0, &global_scope, oc, MDL)) { packet -> got_requested_address = 1; cip.len = 4; memcpy (cip.iabuf, d1.data, cip.len); data_string_forget (&d1, MDL); } else cip.len = 0; } ``` -------------------------------- ### zpipe.c: Example of zlib inflate() and deflate() Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/cluecode/data/ics/zlib-examples/zlib_how.html This is the complete zpipe.c example program from the zlib documentation. It demonstrates proper use of zlib's inflate() and deflate() functions. The code is provided to the public domain and is not copyrighted. ```c /* zpipe.c: example of proper use of zlib's inflate() and deflate() Not copyrighted -- provided to the public domain Version 1.4 11 December 2005 Mark Adler */ } ``` -------------------------------- ### Generate main pip requirements with gen_requirements.py Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/etc/scripts/README.rst Generate the main pip requirements file. Start with a clean virtualenv to avoid injecting requirements specific to the tools used here. Optionally install or update extra main requirements after the ./configure step so they are included in the generated main requirements. ```shell ./configure --clean ./configure python etc/scripts/gen_requirements.py --site-packages-dir ``` -------------------------------- ### Example output with license_policy object Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/reference/scancode-cli/cli-post-scan-options.rst Sample JSON output showing the added license_policy object with fields from the policy file. ```json { "path": "samples/JGroups/licenses/apache-2.0.txt", "license_detections": [ "license_expression": "apache-2.0", "matches": {...} "identifier": "apache_2_0-9804422e-94ac-ad40-b53a-ee6f8ddb7a3b" ], "detected_license_expression": "apache-2.0", "detected_license_expression_spdx": "Apache-2.0", "license_policy": { "license_key": "apache-2.0", "label": "Approved License", "color_code": "#008000", "icon": "icon-ok-circle" }, ... } ``` -------------------------------- ### Set up signal frame with setup_frame Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic1/gpl_29.txt Builds a signal frame on the user stack, copies the sigcontext and extra frame data, sets up the sigreturn trampoline, and adjusts the stack for the exception frame. On error, forces SIGSEGV. ```c static void setup_frame (int sig, struct k_sigaction *ka, sigset_t *set, struct pt_regs *regs) { struct sigframe *frame; int fsize = frame_extra_sizes[regs->format]; struct sigcontext context; int err = 0; if (fsize < 0) { #ifdef DEBUG printk ("setup_frame: Unknown frame format %#x\n", regs->format); #endif goto give_sigsegv; } frame = get_sigframe(ka, regs, sizeof(*frame) + fsize); if (fsize) { err |= copy_to_user (frame + 1, regs + 1, fsize); regs->stkadj = fsize; } err |= __put_user((current->exec_domain && current->exec_domain->signal_invmap && sig < 32 ? current->exec_domain->signal_invmap[sig] : sig), &frame->sig); err |= __put_user(regs->vector, &frame->code); err |= __put_user(&frame->sc, &frame->psc); if (_NSIG_WORDS > 1) err |= copy_to_user(frame->extramask, &set->sig[1], sizeof(frame->extramask)); setup_sigcontext(&context, regs, set->sig[0]); err |= copy_to_user (&frame->sc, &context, sizeof(context)); /* Set up to return from userspace. */ err |= __put_user(frame->retcode, &frame->pretcode); /* moveq #,d0; trap #0 */ err |= __put_user(0x70004e40 + (__NR_sigreturn << 16), (long *)(frame->retcode)); if (err) goto give_sigsegv; push_cache ((unsigned long) &frame->retcode); /* Set up registers for signal handler */ wrusp ((unsigned long) frame); regs->pc = (unsigned long) ka->sa.sa_handler; adjust_stack: /* Prepare to skip over the extra stuff in the exception frame. */ if (regs->stkadj) { struct pt_regs *tregs = (struct pt_regs *)((ulong)regs + regs->stkadj); #if DEBUG printk("Performing stackadjust=%04x\n", regs->stkadj); #endif /* This must be copied with decreasing addresses to handle overlaps. */ tregs->vector = 0; tregs->format = 0; tregs->pc = regs->pc; tregs->sr = regs->sr; } return; give_sigsegv: if (sig == SIGSEGV) ka->sa.sa_handler = SIG_DFL; force_sig(SIGSEGV, current); goto adjust_stack; } ``` -------------------------------- ### Create Mock Lease from Host Declaration (mockup_lease) Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic2/bsd-new_14.txt This function creates a lease structure based on a host declaration and a shared network. It allocates a lease, finds a suitable address, copies client identifier and hardware address, and sets lease fields. Returns 1 on success and 0 on failure. ```C int mockup_lease (struct lease **lp, struct packet *packet, struct shared_network *share, struct host_decl *hp) { struct lease *lease = (struct lease *)0; const unsigned char **s; isc_result_t status; struct host_decl *rhp = (struct host_decl *)0; status = lease_allocate (&lease, MDL); if (status != ISC_R_SUCCESS) return 0; if (host_reference (&rhp, hp, MDL) != ISC_R_SUCCESS) return 0; if (!find_host_for_network (&lease -> subnet, &rhp, &lease -> ip_addr, share)) { lease_dereference (&lease, MDL); return 0; } host_reference (&lease -> host, rhp, MDL); if (rhp -> client_identifier.len > sizeof lease -> uid_buf) lease -> uid = dmalloc (rhp -> client_identifier.len, MDL); else lease -> uid = lease -> uid_buf; if (!lease -> uid) { lease_dereference (&lease, MDL); host_dereference (&rhp, MDL); return 0; } memcpy (lease -> uid, rhp -> client_identifier.data, rhp -> client_identifier.len); lease -> uid_len = rhp -> client_identifier.len; lease -> hardware_addr = rhp -> interface; lease -> starts = lease -> timestamp = lease -> ends = MIN_TIME; lease -> flags = STATIC_LEASE; lease -> binding_state = FTS_FREE; lease_reference (lp, lease, MDL); lease_dereference (&lease, MDL); host_dereference (&rhp, MDL); return 1; } ``` -------------------------------- ### Install JsonMapper via PEAR Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/external/fossology-tests/AGPL/readme.rst Installs JsonMapper via PEAR by discovering the channel and installing the package. Run these commands in a terminal. ```shell $ pear channel-discover pear.nrdev.de $ pear install nr/jsonmapper-alpha ``` -------------------------------- ### Windows Docker build with manual version tag Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/getting-started/installation/install-scancode-using-docker.rst Windows example showing how to obtain the version tag and use it in the Docker build command. ```default C:\scancode-toolkit>git describe --tags v32.5.0 C:\scancode-toolkit>docker build --tag scancode-toolkit --tag scancode-toolkit:v32.5.0 . ``` -------------------------------- ### Verify ScanCode installation with help command Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/getting-started/installation/install-scancode-from-source.rst Runs the scancode help command to verify the installation. If no errors appear, the installation is successful. ```shell scancode --help ``` -------------------------------- ### Hello World Output Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic3/no_license_68.txt Expected output when running the Hello World example. ```text Hello world! ``` -------------------------------- ### Setuptools entry_points for scancode_plugins Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/reference/scancode-plugins/plugin-architecture.rst Example of setuptools entry_points configuration for loading Python plugins via pluggy. The 'scancode_plugins' group maps a plugin name to a module. Loaded using PluginManager.load_setuptools_entrypoints('scancode_plugins'). ```none entry_points = { 'scancode_plugins': [ 'name_of_plugin = ignore_regex', ] } ``` -------------------------------- ### Install MongoDB Compass with install_compass script Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic3/mongo_readme.txt Install MongoDB Compass using the install_compass script packaged with MongoDB. Downloads and installs the appropriate package for your platform. ```bash $ ./install_compass ``` -------------------------------- ### Check partition start positions Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic2/bsd-original-uc_and_gpl_and_gpl_and_gpl_and_other.txt This code snippet is part of a function that checks partition start positions. It updates the previous index and returns the current index when the last start position is greater than the current one, otherwise it updates the last start position and index. ```c if (last_p_start_pos > p_start_pos) { if (prev) *prev = last_i; return i; } last_p_start_pos = p_start_pos; last_i = i; } } return 0; } ``` -------------------------------- ### help Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/licensedcode/data/datadriven/lic2/bsd-new_62.txt Prints all available commands in omshell with syntax pointers. ```APIDOC ## help ### Description Prints all available commands in omshell with syntax pointers. ### Usage In omshell, type `help` to see the list of commands. ### Example ``` > help ``` ### Notes - Provides a summary of all commands and their syntax. ``` -------------------------------- ### Install requirements for thirdparty scripts Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/etc/scripts/README.rst Install the tools in this directory. These requirements need to be installed for other usages of the tools, either in their own isolated virtualenv or in the main configured development virtualenv. ```shell pip install --requirement etc/scripts/requirements.txt ``` -------------------------------- ### Install Intel-specific Python via Homebrew Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/docs/source/getting-started/installation/install-scancode-from-release-archives.rst Uses the Intel Homebrew installation to install Python optimized for x86_64 architecture. This ensures Python is compatible with the x86_64 environment. ```default /usr/local/Homebrew/bin/brew install python3 ``` -------------------------------- ### Configure and activate virtual environment Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/CONTRIBUTING.rst Configure the local environment for development and activate the virtual environment. Run ./configure --dev on Unix-like systems or configure --dev on Windows. Then activate the virtual environment with source venv/bin/activate or . venv/bin/activate on Unix-like systems, or venv\Scripts\activate on Windows. Rerun the activate step when opening a new terminal and rerun ./configure after pulling new code. ```bash ./configure --dev ``` ```bash configure --dev ``` ```bash source venv/bin/activate ``` ```bash . venv/bin/activate ``` ```bash venv\Scripts\activate ``` -------------------------------- ### Install urllib3 with pip Source: https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/data/pypi/unpacked_wheel/metadata-2.0/urllib3-1.26.4.dist-info/DESCRIPTION.rst Command to install urllib3 using pip. ```bash $ python -m pip install urllib3 ```