Skip to content

Commit

Permalink
remove useless code delimiters
Browse files Browse the repository at this point in the history
These code delimiters are useless and we've decided not to use them
in future code. However, many contributors use existing files as
templates and they keep creeping up in new code. So the only solution
is to remove them completely.

Here's the command and python script I used to do this:
$ find . -name "*.c" -o -name "*.h" -print0 | xargs -0 python code-delimiters.py
$ cat code-delimiters.py
import sys
import re
import os
import chardet

def remove_include_comments(filenames):
    # Regex for comments with leading/trailing blank lines (replace with single newline)
    comment_pattern_with_blanks = re.compile(r"\n/\*+\/\n(?:/\*+[^\n]*\n){1}/\*+\/\n\s*\n", re.DOTALL)

    # Regex for comments without leading/trailing blank lines (replace with nothing)
    comment_pattern_no_blanks = re.compile(r"/\*+\/\n(?:/\*+[^\n]*\n){1}/\*+\/\n", re.DOTALL)

    for filename in filenames:
        try:
            with open(filename, 'rb') as f:  # Open in binary mode first
                raw_content = f.read()

            encoding_result = chardet.detect(raw_content)  # Detect the encoding
            encoding = encoding_result['encoding']

            if encoding is None:
                print(f"Could not detect encoding for {filename}. Skipping.")
                continue # Skip the file if encoding cannot be detected

            try:
                content = raw_content.decode(encoding) # Decode with detected encoding
            except UnicodeDecodeError:
                print(f"Decoding error with {filename} using {encoding}. Skipping.")
                continue # Skip the file if decoding fails

            # First pass: Remove comments with leading/trailing blanks
            new_content = comment_pattern_with_blanks.sub("\n", content)

            # Second pass: Remove comments without leading/trailing blanks
            new_content = comment_pattern_no_blanks.sub("", new_content)  # Operate on the modified content

            if new_content != content:
                with open(filename, 'w', newline='') as f:
                    f.write(new_content)
                print(f"Modified: {filename}")
            else:
                print(f"No changes: {filename}")

        except FileNotFoundError:
            print(f"File not found: {filename}")
        except Exception as e:
            print(f"Error processing {filename}: {e}")

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python script.py <file1> <file2> ...")
        sys.exit(1)

    filenames = sys.argv[1:]
    remove_include_comments(filenames)

Signed-off-by: Darius Berghe <[email protected]>
  • Loading branch information
buha committed Feb 24, 2025
1 parent 1e873ea commit 88083db
Show file tree
Hide file tree
Showing 560 changed files with 0 additions and 4,896 deletions.
13 changes: 0 additions & 13 deletions drivers/accel/adxl313/adxl313.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@
#ifndef __ADXL313_H__
#define __ADXL313_H__

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <stdint.h>
#include <string.h>
#include "no_os_util.h"
#include "no_os_i2c.h"
#include "no_os_spi.h"

/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/
/* SPI commands */
#define ADXL313_SPI_READ (0x80)
#define ADXL313_SPI_WRITE (0x00)
Expand Down Expand Up @@ -233,10 +227,6 @@
#define ADXL313_Y_EN NO_OS_BIT(2)
#define ADXL313_Z_EN NO_OS_BIT(3)

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/

/**
* @enum adxl313_type
* @brief Enum for device type.
Expand Down Expand Up @@ -529,9 +519,6 @@ struct adxl313_dev {
uint8_t comm_buff[24];
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
/*! Init. the comm. peripheral and check if the ADXL313 is present. */
int adxl313_init(struct adxl313_dev **device,
struct adxl313_init_param init_param);
Expand Down
13 changes: 0 additions & 13 deletions drivers/accel/adxl313/iio_adxl313.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,8 @@
#ifndef IIO_ADXL313_H
#define IIO_ADXL313_H

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include "iio.h"

/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/
struct adxl313_iio_dev {
struct adxl313_dev *adxl313_dev;
struct iio_device *iio_dev;
Expand All @@ -56,9 +46,6 @@ struct adxl313_iio_dev_init_param {
struct adxl313_init_param *adxl313_dev_init;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
int adxl313_iio_init(struct adxl313_iio_dev **iio_dev,
struct adxl313_iio_dev_init_param *init_param);

Expand Down
15 changes: 0 additions & 15 deletions drivers/accel/adxl345/adxl345.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,10 @@
#ifndef __ADXL345_H__
#define __ADXL345_H__

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <stdint.h>
#include "no_os_i2c.h"
#include "no_os_spi.h"

/******************************************************************************/
/******************************** ADXL345 *************************************/
/******************************************************************************/

/* Options for communicating with the device. */
#define ADXL345_SPI_COMM 0
#define ADXL345_I2C_COMM 1
Expand Down Expand Up @@ -182,10 +175,6 @@
/* ADXL345 Full Resolution Scale Factor */
#define ADXL345_SCALE_FACTOR 0.0039

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/

/**
* @enum adxl345_type
* @brief ADXL345 Supported devices.
Expand Down Expand Up @@ -263,10 +252,6 @@ struct adxl345_init_param {
uint8_t full_resolution_set;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/

/*! Reads the value of a register. */
uint8_t adxl345_get_register_value(struct adxl345_dev *dev,
uint8_t register_address);
Expand Down
12 changes: 0 additions & 12 deletions drivers/accel/adxl355/adxl355.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@
#ifndef __ADXL355_H__
#define __ADXL355_H__

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <stdint.h>
#include <string.h>
#include "no_os_util.h"
#include "no_os_i2c.h"
#include "no_os_spi.h"

/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/
/* SPI commands */
#define ADXL355_SPI_READ 0x01
#define ADXL355_SPI_WRITE 0x00
Expand Down Expand Up @@ -149,9 +143,6 @@
#define ADXL355_HPF_FIELD_MSK NO_OS_GENMASK( 6, 4)
#define ADXL355_INT_POL_FIELD_MSK NO_OS_BIT(6)

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/
enum adxl355_type {
ID_ADXL355,
ID_ADXL357,
Expand Down Expand Up @@ -311,9 +302,6 @@ struct adxl355_dev {
uint8_t comm_buff[289];
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
/*! Init. the comm. peripheral and checks if the ADXL355 part is present. */
int adxl355_init(struct adxl355_dev **device,
struct adxl355_init_param init_param);
Expand Down
12 changes: 0 additions & 12 deletions drivers/accel/adxl355/iio_adxl355.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,11 @@
#ifndef IIO_ADXL355_H
#define IIO_ADXL355_H

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include "iio.h"
#include "no_os_irq.h"

/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/
extern struct iio_trigger adxl355_iio_trig_desc;

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/
struct adxl355_iio_dev {
struct adxl355_dev *adxl355_dev;
struct iio_device *iio_dev;
Expand All @@ -59,9 +50,6 @@ struct adxl355_iio_dev_init_param {
struct adxl355_init_param *adxl355_dev_init;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
int adxl355_iio_init(struct adxl355_iio_dev **iio_dev,
struct adxl355_iio_dev_init_param *init_param);

Expand Down
15 changes: 0 additions & 15 deletions drivers/accel/adxl362/adxl362.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,9 @@
#ifndef __ADXL362_H__
#define __ADXL362_H__

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <stdint.h>
#include "no_os_spi.h"

/******************************************************************************/
/********************************* ADXL362 ************************************/
/******************************************************************************/

/* ADXL362 communication commands */
#define ADXL362_WRITE_REG 0x0A
#define ADXL362_READ_REG 0x0B
Expand Down Expand Up @@ -186,10 +179,6 @@
/* ADXL362 Reset settings */
#define ADXL362_RESET_KEY 0x52

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/

/**
* @struct adxl362_dev
* @brief ADXL362 Device structure.
Expand All @@ -210,10 +199,6 @@ struct adxl362_init_param {
struct no_os_spi_init_param spi_init;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/

/*! Initializes the device. */
int32_t adxl362_init(struct adxl362_dev **device,
struct adxl362_init_param init_param);
Expand Down
15 changes: 0 additions & 15 deletions drivers/accel/adxl367/adxl367.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,11 @@
#ifndef __ADXL367_H__
#define __ADXL367_H__

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "no_os_spi.h"
#include "no_os_i2c.h"

/******************************************************************************/
/********************************* ADXL367 ************************************/
/******************************************************************************/

/* ADXL367 communication commands */
#define ADXL367_WRITE_REG 0x0A
#define ADXL367_READ_REG 0x0B
Expand Down Expand Up @@ -284,10 +277,6 @@
/* Max change = 270mg. Sensitivity = 4LSB / mg */
#define ADXL367_SELF_TEST_MAX 270 * 100 / 25

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/

/**
* @enum adxl367_comm_type
* @brief Enum for communication type.
Expand Down Expand Up @@ -459,10 +448,6 @@ struct adxl367_init_param {
uint8_t i2c_slave_address;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/

/* Initializes the device. */
int adxl367_init(struct adxl367_dev **device,
struct adxl367_init_param init_param);
Expand Down
9 changes: 0 additions & 9 deletions drivers/accel/adxl367/iio_adxl367.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@
#ifndef IIO_ADXL367_H
#define IIO_ADXL367_H

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include "iio.h"

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/
struct adxl367_iio_dev {
struct adxl367_dev *adxl367_dev;
struct iio_device *iio_dev;
Expand All @@ -52,9 +46,6 @@ struct adxl367_iio_init_param {
struct adxl367_init_param *adxl367_initial_param;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
int adxl367_iio_init(struct adxl367_iio_dev **iio_dev,
struct adxl367_iio_init_param *init_param);

Expand Down
9 changes: 0 additions & 9 deletions drivers/accel/adxl372/adxl372.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,13 @@
#ifndef ADXL372_H_
#define ADXL372_H_

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <stdint.h>
#include "no_os_util.h"
#include "no_os_delay.h"
#include "no_os_gpio.h"
#include "no_os_i2c.h"
#include "no_os_spi.h"

/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/
/*
* ADXL372 registers definition
*/
Expand Down Expand Up @@ -407,9 +401,6 @@ struct adxl372_init_param {
enum adxl372_comm_type comm_type;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
int32_t adxl372_spi_reg_read(struct adxl372_dev *dev,
uint8_t reg_addr,
uint8_t *reg_data);
Expand Down
13 changes: 0 additions & 13 deletions drivers/accel/adxl38x/adxl38x.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,11 @@
#ifndef __ADXL38X_H__
#define __ADXL38X_H__

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "no_os_i2c.h"
#include "no_os_spi.h"

/******************************************************************************/
/******************************** ADXL38X *************************************/
/******************************************************************************/
/* Constants and Macros */

/* SPI */
Expand Down Expand Up @@ -226,9 +220,6 @@

#define ADXL38X_ST_LIMIT_DENOMINATOR 10

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/
/**
* @struct device_variant
* @brief ADXL38X Device selection.
Expand Down Expand Up @@ -398,10 +389,6 @@ union adxl38x_sts_reg_flags {
uint32_t value;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/

int adxl38x_read_device_data(struct adxl38x_dev *dev, uint8_t base_address,
uint16_t size, uint8_t *read_data);
int adxl38x_write_device_data(struct adxl38x_dev *dev, uint8_t base_address,
Expand Down
10 changes: 0 additions & 10 deletions drivers/adc-dac/ad74413r/iio_ad74413r.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,10 @@
#ifndef IIO_AD74413R_H
#define IIO_AD74413R_H

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include "iio.h"
#include "ad74413r.h"
#include "iio_trigger.h"

/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/

/**
* @brief Diagnostics channel state.
*/
Expand Down Expand Up @@ -103,9 +96,6 @@ struct ad74413r_channel_map {
uint32_t num_channels;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
int ad74413r_iio_init(struct ad74413r_iio_desc **,
struct ad74413r_iio_desc_init_param *);
int ad74413r_iio_remove(struct ad74413r_iio_desc *);
Expand Down
Loading

0 comments on commit 88083db

Please sign in to comment.