2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2015-10-08 20:48:40 +02:00
|
|
|
* tools/nxstyle.c
|
|
|
|
*
|
2024-09-10 14:15:58 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2020-03-31 19:43:28 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-10-08 20:48:40 +02:00
|
|
|
*
|
2020-03-31 19:43:28 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-10-08 20:48:40 +02:00
|
|
|
*
|
2020-03-31 19:43:28 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-10-08 20:48:40 +02:00
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2015-10-08 20:48:40 +02:00
|
|
|
* Included Files
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2018-11-19 14:50:59 +01:00
|
|
|
#include <stdlib.h>
|
2015-10-08 20:48:40 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
2020-01-13 19:08:45 +01:00
|
|
|
#include <stdint.h>
|
2015-10-08 20:48:40 +02:00
|
|
|
#include <string.h>
|
2018-11-19 14:50:59 +01:00
|
|
|
#include <strings.h>
|
2015-10-08 20:48:40 +02:00
|
|
|
#include <ctype.h>
|
2020-01-12 17:07:54 +01:00
|
|
|
#include <limits.h>
|
2019-12-30 19:34:43 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <libgen.h>
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2015-10-08 20:48:40 +02:00
|
|
|
* Pre-processor Definitions
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
#define NXSTYLE_VERSION "0.01"
|
|
|
|
|
|
|
|
#define LINE_SIZE 512
|
2020-01-02 10:22:08 +01:00
|
|
|
#define RANGE_NUMBER 4096
|
2020-01-12 17:07:54 +01:00
|
|
|
#define DEFAULT_WIDTH 78
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
#define FIRST_SECTION INCLUDED_FILES
|
|
|
|
#define LAST_SECTION PUBLIC_FUNCTION_PROTOTYPES
|
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
#define FATAL(m, l, o) message(FATAL, (m), (l), (o))
|
2020-01-12 17:07:54 +01:00
|
|
|
#define FATALFL(m, s) message(FATAL, (m), -1, -1)
|
2019-12-30 19:34:43 +01:00
|
|
|
#define WARN(m, l, o) message(WARN, (m), (l), (o))
|
|
|
|
#define ERROR(m, l, o) message(ERROR, (m), (l), (o))
|
2020-01-12 17:07:54 +01:00
|
|
|
#define ERRORFL(m, s) message(ERROR, (m), -1, -1)
|
2019-12-30 19:34:43 +01:00
|
|
|
#define INFO(m, l, o) message(INFO, (m), (l), (o))
|
2020-01-12 17:07:54 +01:00
|
|
|
#define INFOFL(m, s) message(INFO, (m), -1, -1)
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2019-12-30 19:34:43 +01:00
|
|
|
* Private types
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2019-12-30 19:34:43 +01:00
|
|
|
|
|
|
|
enum class_e
|
|
|
|
{
|
|
|
|
INFO,
|
|
|
|
WARN,
|
|
|
|
ERROR,
|
|
|
|
FATAL
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *class_text[] =
|
|
|
|
{
|
|
|
|
"info",
|
|
|
|
"warning",
|
|
|
|
"error",
|
|
|
|
"fatal"
|
|
|
|
};
|
|
|
|
|
|
|
|
enum file_e
|
|
|
|
{
|
2020-01-13 19:08:45 +01:00
|
|
|
UNKNOWN = 0x00,
|
|
|
|
C_HEADER = 0x01,
|
|
|
|
C_SOURCE = 0x02
|
|
|
|
};
|
|
|
|
|
|
|
|
enum section_s
|
|
|
|
{
|
|
|
|
NO_SECTION = 0,
|
|
|
|
INCLUDED_FILES,
|
|
|
|
PRE_PROCESSOR_DEFINITIONS,
|
|
|
|
PUBLIC_TYPES,
|
|
|
|
PRIVATE_TYPES,
|
|
|
|
PRIVATE_DATA,
|
|
|
|
PUBLIC_DATA,
|
|
|
|
PRIVATE_FUNCTIONS,
|
|
|
|
PRIVATE_FUNCTION_PROTOTYPES,
|
|
|
|
INLINE_FUNCTIONS,
|
|
|
|
PUBLIC_FUNCTIONS,
|
|
|
|
PUBLIC_FUNCTION_PROTOTYPES
|
|
|
|
};
|
|
|
|
|
2020-03-09 12:53:21 +01:00
|
|
|
enum pptype_e
|
|
|
|
{
|
|
|
|
PPLINE_NONE = 0,
|
|
|
|
PPLINE_DEFINE,
|
2020-03-14 14:36:47 +01:00
|
|
|
PPLINE_IF,
|
|
|
|
PPLINE_ELIF,
|
|
|
|
PPLINE_ELSE,
|
|
|
|
PPLINE_ENDIF,
|
2020-03-09 12:53:21 +01:00
|
|
|
PPLINE_OTHER
|
|
|
|
};
|
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
struct file_section_s
|
|
|
|
{
|
|
|
|
const char *name; /* File section name */
|
|
|
|
uint8_t ftype; /* File type where section found */
|
2019-12-30 19:34:43 +01:00
|
|
|
};
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2019-12-30 19:34:43 +01:00
|
|
|
* Private data
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
static enum file_e g_file_type = UNKNOWN;
|
|
|
|
static enum section_s g_section = NO_SECTION;
|
|
|
|
static int g_maxline = DEFAULT_WIDTH;
|
|
|
|
static int g_status = 0;
|
|
|
|
static int g_verbose = 2;
|
|
|
|
static int g_rangenumber = 0;
|
2020-01-02 10:22:08 +01:00
|
|
|
static int g_rangestart[RANGE_NUMBER];
|
|
|
|
static int g_rangecount[RANGE_NUMBER];
|
2021-03-04 20:34:39 +01:00
|
|
|
static char g_file_name[PATH_MAX];
|
2023-04-11 07:27:14 +02:00
|
|
|
static bool g_skipmixedcase;
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
static const struct file_section_s g_section_info[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
" *\n", /* Index: NO_SECTION */
|
|
|
|
C_SOURCE | C_HEADER
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Included Files\n", /* Index: INCLUDED_FILES */
|
|
|
|
C_SOURCE | C_HEADER
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Pre-processor Definitions\n", /* Index: PRE_PROCESSOR_DEFINITIONS */
|
|
|
|
C_SOURCE | C_HEADER
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Public Types\n", /* Index: PUBLIC_TYPES */
|
|
|
|
C_HEADER
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Private Types\n", /* Index: PRIVATE_TYPES */
|
|
|
|
C_SOURCE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Private Data\n", /* Index: PRIVATE_DATA */
|
|
|
|
C_SOURCE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Public Data\n", /* Index: PUBLIC_DATA */
|
|
|
|
C_SOURCE | C_HEADER
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Private Functions\n", /* Index: PRIVATE_FUNCTIONS */
|
|
|
|
C_SOURCE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Private Function Prototypes\n", /* Index: PRIVATE_FUNCTION_PROTOTYPES */
|
|
|
|
C_SOURCE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Inline Functions\n", /* Index: INLINE_FUNCTIONS */
|
|
|
|
C_SOURCE | C_HEADER
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Public Functions\n", /* Index: PUBLIC_FUNCTIONS */
|
|
|
|
C_SOURCE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
" * Public Function Prototypes\n", /* Index: PUBLIC_FUNCTION_PROTOTYPES */
|
2020-04-01 21:38:53 +02:00
|
|
|
C_SOURCE | C_HEADER
|
2020-01-13 19:08:45 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-03-31 19:43:28 +02:00
|
|
|
static const char *g_white_prefix[] =
|
|
|
|
{
|
2022-03-20 16:33:40 +01:00
|
|
|
"ASCII_", /* Ref: include/nuttx/ascii.h */
|
2024-07-26 11:41:57 +02:00
|
|
|
"Dl_info", /* Ref: include/dlfcn.h */
|
2020-03-31 19:43:28 +02:00
|
|
|
"Elf", /* Ref: include/elf.h, include/elf32.h, include/elf64.h */
|
2020-11-05 13:51:38 +01:00
|
|
|
"PRId", /* Ref: inttypes.h */
|
|
|
|
"PRIi", /* Ref: inttypes.h */
|
|
|
|
"PRIo", /* Ref: inttypes.h */
|
|
|
|
"PRIu", /* Ref: inttypes.h */
|
|
|
|
"PRIx", /* Ref: inttypes.h */
|
|
|
|
"SCNd", /* Ref: inttypes.h */
|
|
|
|
"SCNi", /* Ref: inttypes.h */
|
|
|
|
"SCNo", /* Ref: inttypes.h */
|
|
|
|
"SCNu", /* Ref: inttypes.h */
|
|
|
|
"SCNx", /* Ref: inttypes.h */
|
2020-03-31 19:43:28 +02:00
|
|
|
"SYS_", /* Ref: include/sys/syscall.h */
|
|
|
|
"STUB_", /* Ref: syscall/syscall_lookup.h, syscall/sycall_stublookup.c */
|
2022-03-20 16:33:40 +01:00
|
|
|
"XK_", /* Ref: include/input/X11_keysymdef.h */
|
2020-03-31 19:43:28 +02:00
|
|
|
"b8", /* Ref: include/fixedmath.h */
|
|
|
|
"b16", /* Ref: include/fixedmath.h */
|
|
|
|
"b32", /* Ref: include/fixedmath.h */
|
|
|
|
"ub8", /* Ref: include/fixedmath.h */
|
|
|
|
"ub16", /* Ref: include/fixedmath.h */
|
|
|
|
"ub32", /* Ref: include/fixedmath.h */
|
2022-03-19 17:22:42 +01:00
|
|
|
"lua_", /* Ref: apps/interpreters/lua/lua-5.x.x/src/lua.h */
|
|
|
|
"luaL_", /* Ref: apps/interpreters/lua/lua-5.x.x/src/lauxlib.h */
|
2024-02-03 14:15:50 +01:00
|
|
|
"V4L2_", /* Ref: include/sys/video_controls.h */
|
2024-02-18 08:52:30 +01:00
|
|
|
"Ifx", /* Ref: arch/tricore/src */
|
2020-03-31 19:43:28 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2022-05-13 04:46:52 +02:00
|
|
|
static const char *g_white_suffix[] =
|
|
|
|
{
|
2022-05-13 14:31:29 +02:00
|
|
|
/* Ref: include/nuttx/wireless/nrf24l01.h */
|
|
|
|
|
2022-05-13 04:46:52 +02:00
|
|
|
"Mbps",
|
2022-05-13 14:31:29 +02:00
|
|
|
"kHz",
|
|
|
|
"kbps",
|
2022-05-13 04:46:52 +02:00
|
|
|
"us",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2023-04-26 11:27:43 +02:00
|
|
|
static const char *g_white_content_list[] =
|
2020-06-22 18:14:42 +02:00
|
|
|
{
|
2021-03-03 14:50:27 +01:00
|
|
|
/* Ref: gnu_unwind_find_exidx.c */
|
|
|
|
|
|
|
|
"__EIT_entry",
|
|
|
|
|
|
|
|
/* Ref: gnu_unwind_find_exidx.c */
|
|
|
|
|
|
|
|
"__gnu_Unwind_Find_exidx",
|
|
|
|
|
2022-05-03 14:19:02 +02:00
|
|
|
/* Ref: lib_impure.c */
|
|
|
|
|
|
|
|
"__sFILE_fake",
|
|
|
|
|
2021-03-03 14:50:27 +01:00
|
|
|
/* Ref: stdlib.h */
|
|
|
|
|
|
|
|
"_Exit",
|
|
|
|
|
2021-05-06 14:22:42 +02:00
|
|
|
/* Ref: stdatomic.h */
|
|
|
|
|
|
|
|
"_Atomic",
|
|
|
|
|
2023-04-22 13:08:00 +02:00
|
|
|
/* Ref: https://en.cppreference.com/w/c/keyword/_Thread_local */
|
|
|
|
|
|
|
|
"_Thread_local",
|
|
|
|
|
2021-03-03 14:50:27 +01:00
|
|
|
/* Ref: unwind-arm-common.h */
|
|
|
|
|
2021-04-19 07:55:34 +02:00
|
|
|
"_Unwind",
|
2021-03-03 14:50:27 +01:00
|
|
|
|
|
|
|
/* Ref:
|
|
|
|
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/tempnam.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
"P_tmpdir",
|
|
|
|
|
|
|
|
/* Ref:
|
|
|
|
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/tempnam.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
"L_tmpnam",
|
|
|
|
|
2021-04-03 17:37:27 +02:00
|
|
|
/* Ref:
|
|
|
|
* nuttx/compiler.h
|
|
|
|
*/
|
2021-03-29 20:28:58 +02:00
|
|
|
|
|
|
|
"_Far",
|
|
|
|
"_Erom",
|
|
|
|
|
2022-01-27 02:16:14 +01:00
|
|
|
/* Ref:
|
|
|
|
* arch/sim/src/sim/up_wpcap.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"Address",
|
|
|
|
"Description",
|
|
|
|
"FirstUnicastAddress",
|
|
|
|
"GetAdaptersAddresses",
|
|
|
|
"GetProcAddress",
|
|
|
|
"LoadLibrary",
|
|
|
|
"lpSockaddr",
|
|
|
|
"Next",
|
|
|
|
"PhysicalAddressLength",
|
|
|
|
"PhysicalAddress",
|
|
|
|
"WideCharToMultiByte",
|
|
|
|
|
2022-01-24 14:46:17 +01:00
|
|
|
/* Ref:
|
|
|
|
* drivers/segger/note_sysview.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"SEGGER_SYSVIEW",
|
|
|
|
"TaskID",
|
|
|
|
"sName",
|
|
|
|
"Prio",
|
|
|
|
"StackBase",
|
|
|
|
"StackSize",
|
|
|
|
|
2022-01-31 10:31:32 +01:00
|
|
|
/* Ref:
|
|
|
|
* drivers/segger/syslog_rtt.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"SEGGER_RTT",
|
|
|
|
|
2021-04-03 17:37:27 +02:00
|
|
|
/* Ref:
|
|
|
|
* fs/nfs/rpc.h
|
|
|
|
* fs/nfs/nfs_proto.h
|
2021-12-29 13:17:34 +01:00
|
|
|
* fs/nfs/nfs_mount.h
|
|
|
|
* fs/nfs/nfs_vfsops.c
|
2021-04-03 17:37:27 +02:00
|
|
|
*/
|
2021-04-03 14:48:33 +02:00
|
|
|
|
|
|
|
"CREATE3args",
|
|
|
|
"CREATE3resok",
|
|
|
|
"LOOKUP3args",
|
|
|
|
"LOOKUP3filename",
|
|
|
|
"LOOKUP3resok",
|
|
|
|
"WRITE3args",
|
|
|
|
"WRITE3resok",
|
|
|
|
"READ3args",
|
|
|
|
"READ3resok",
|
|
|
|
"REMOVE3args",
|
|
|
|
"REMOVE3resok",
|
|
|
|
"RENAME3args",
|
|
|
|
"RENAME3resok",
|
|
|
|
"MKDIR3args",
|
|
|
|
"MKDIR3resok",
|
|
|
|
"RMDIR3args",
|
|
|
|
"RMDIR3resok",
|
|
|
|
"READDIR3args",
|
|
|
|
"READDIR3resok",
|
|
|
|
"SETATTR3args",
|
|
|
|
"SETATTR3resok",
|
|
|
|
"FS3args",
|
2021-12-29 13:17:34 +01:00
|
|
|
"SIZEOF_rpc_reply_read",
|
|
|
|
"SIZEOF_rpc_call_write",
|
|
|
|
"SIZEOF_rpc_reply_readdir",
|
|
|
|
"SIZEOF_nfsmount",
|
2021-04-03 14:48:33 +02:00
|
|
|
|
2021-10-09 09:22:28 +02:00
|
|
|
/* Ref:
|
|
|
|
* mm/kasan/kasan.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"__asan_loadN",
|
|
|
|
"__asan_storeN",
|
|
|
|
"__asan_loadN_noabort",
|
|
|
|
"__asan_storeN_noabort",
|
|
|
|
|
2022-02-14 20:29:52 +01:00
|
|
|
/* Ref:
|
|
|
|
* tools/jlink-nuttx.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"RTOS_Init",
|
|
|
|
"RTOS_GetVersion",
|
|
|
|
"RTOS_GetSymbols",
|
|
|
|
"RTOS_GetNumThreads",
|
|
|
|
"RTOS_GetCurrentThreadId",
|
|
|
|
"RTOS_GetThreadId",
|
|
|
|
"RTOS_GetThreadDisplay",
|
|
|
|
"RTOS_GetThreadReg",
|
|
|
|
"RTOS_GetThreadRegList",
|
|
|
|
"RTOS_GetThreadRegList",
|
|
|
|
"RTOS_SetThreadReg",
|
|
|
|
"RTOS_SetThreadRegList",
|
|
|
|
"RTOS_UpdateThreads",
|
|
|
|
|
2022-11-19 13:46:37 +01:00
|
|
|
/* Ref:
|
|
|
|
* sim/posix/sim_x11eventloop.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"Display",
|
|
|
|
"Button1Mask",
|
|
|
|
"Button2Mask",
|
|
|
|
"Button3Mask",
|
|
|
|
"Button1",
|
|
|
|
"Button2",
|
|
|
|
"Button3",
|
|
|
|
"XEvent",
|
|
|
|
"XPending",
|
|
|
|
"XNextEvent",
|
|
|
|
"KeyPress",
|
|
|
|
"KeyRelease",
|
|
|
|
"MotionNotify",
|
|
|
|
"ButtonPress",
|
|
|
|
"ButtonRelease",
|
|
|
|
"XLookupKeysym",
|
|
|
|
|
|
|
|
/* Ref:
|
|
|
|
* sim/posix/sim_x11framebuffer.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"Window",
|
|
|
|
"XShmSegmentInfo",
|
|
|
|
"XImage",
|
|
|
|
"XGCValues",
|
|
|
|
"XTextProperty",
|
|
|
|
"XSizeHints",
|
|
|
|
"XOpenDisplay",
|
|
|
|
"XCreateSimpleWindow",
|
|
|
|
"DefaultRootWindow",
|
|
|
|
"XStringListToTextProperty",
|
|
|
|
"XSetWMProperties",
|
|
|
|
"XMapWindow",
|
|
|
|
"XSelectInput",
|
|
|
|
"XAllowEvents",
|
|
|
|
"XGrabButton",
|
|
|
|
"XCreateGC",
|
|
|
|
"XSetErrorHandler",
|
|
|
|
"XSync",
|
|
|
|
"XShmDetach",
|
|
|
|
"XDestroyImage",
|
|
|
|
"XUngrabButton",
|
|
|
|
"XCloseDisplay",
|
|
|
|
"XShmQueryExtension",
|
|
|
|
"XShmCreateImage",
|
|
|
|
"XShmAttach",
|
|
|
|
"DefaultVisual",
|
|
|
|
"XCreateImage",
|
|
|
|
"XGetWindowAttributes",
|
|
|
|
"DefaultColormap",
|
|
|
|
"XAllocColor",
|
|
|
|
"XShmPutImage",
|
|
|
|
"XPutImage",
|
|
|
|
"Colormap",
|
|
|
|
"DefaultScreen",
|
|
|
|
"BlackPixel",
|
|
|
|
"PSize",
|
|
|
|
"PMinSize",
|
|
|
|
"PMaxSize",
|
|
|
|
"ButtonPressMask",
|
|
|
|
"ButtonReleaseMask",
|
|
|
|
"PointerMotionMask",
|
|
|
|
"KeyPressMask",
|
|
|
|
"KeyReleaseMask",
|
|
|
|
"ButtonMotionMask",
|
|
|
|
"GrabModeAsync",
|
|
|
|
"GCGraphicsExposures",
|
|
|
|
"XErrorEvent",
|
|
|
|
"AnyModifier",
|
|
|
|
"None",
|
|
|
|
"Status",
|
|
|
|
"DoGreen",
|
|
|
|
"DoRed",
|
|
|
|
"DoBlue",
|
|
|
|
"ZPixmap",
|
|
|
|
"readOnly",
|
|
|
|
"XWindowAttributes",
|
|
|
|
"XColor",
|
|
|
|
"AsyncBoth",
|
|
|
|
"CurrentTime",
|
2023-08-28 09:39:47 +02:00
|
|
|
"XUnmapWindow",
|
2024-01-24 04:01:35 +01:00
|
|
|
"XFree",
|
2022-11-19 13:46:37 +01:00
|
|
|
|
2024-03-21 12:03:16 +01:00
|
|
|
/* Ref:
|
|
|
|
* nuttx/arch/sim/src/sim_hostdecoder.*
|
|
|
|
*/
|
|
|
|
|
|
|
|
"ISVCDecoder",
|
|
|
|
"SBufferInfo",
|
|
|
|
"SDecodingParam",
|
|
|
|
"eEcActiveIdc",
|
|
|
|
"sVideoProperty",
|
|
|
|
"eVideoBsType",
|
|
|
|
"cmResultSuccess",
|
|
|
|
"uiInBsTimeStamp",
|
|
|
|
"dsErrorFree",
|
|
|
|
"iBufferStatus",
|
|
|
|
"UsrData",
|
|
|
|
"sSystemBuffer",
|
|
|
|
"iWidth",
|
|
|
|
"iHeight",
|
|
|
|
"iStride",
|
|
|
|
"uiOutYuvTimeStamp",
|
|
|
|
"WelsCreateDecoder",
|
|
|
|
"WelsDestroyDecoder",
|
|
|
|
"Initialize",
|
|
|
|
"Uninitialize",
|
|
|
|
"DecodeFrame2",
|
|
|
|
"FlushFrame",
|
|
|
|
"SetOption",
|
|
|
|
"GetOption",
|
|
|
|
|
2022-11-19 13:46:37 +01:00
|
|
|
/* Ref:
|
|
|
|
* sim/posix/sim_deviceimage.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"inflateInit",
|
|
|
|
"inflateEnd",
|
|
|
|
"Bytef",
|
|
|
|
|
|
|
|
/* Ref:
|
|
|
|
* sim/posix/sim_hostmemory.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"CreateFileMapping",
|
|
|
|
"MapViewOfFile",
|
|
|
|
"CloseHandle",
|
|
|
|
"UnmapViewOfFile",
|
|
|
|
|
|
|
|
/* Ref:
|
|
|
|
* sim/posix/sim_hostmisc.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"CaptureStackBackTrace",
|
|
|
|
|
|
|
|
/* Ref:
|
|
|
|
* sim/posix/sim_hosttime.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"GetSystemTimeAsFileTime",
|
|
|
|
"QueryPerformanceFrequency",
|
|
|
|
"QueryPerformanceCounter",
|
|
|
|
"CreateWaitableTimer",
|
|
|
|
"SetWaitableTimer",
|
|
|
|
"WaitForSingleObject",
|
|
|
|
"dwHighDateTime",
|
|
|
|
"dwLowDateTime",
|
|
|
|
"QuadPart",
|
|
|
|
|
|
|
|
/* Ref:
|
2022-11-21 20:08:47 +01:00
|
|
|
* sim/posix/sim_hostuart.c
|
2022-11-19 13:46:37 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
"GetStdHandle",
|
|
|
|
"GetConsoleMode",
|
|
|
|
"SetConsoleMode",
|
|
|
|
"WriteConsole",
|
|
|
|
"ReadConsole",
|
|
|
|
"FlushConsoleInputBuffer",
|
|
|
|
"GetNumberOfConsoleInputEvents",
|
|
|
|
|
2023-02-17 11:19:05 +01:00
|
|
|
/* Ref:
|
|
|
|
* apps/testing/drivertest/drivertest_xxx.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"CMUnitTest",
|
|
|
|
|
2023-02-26 07:48:03 +01:00
|
|
|
/* Ref:
|
|
|
|
* apps/examples/hello_nim/hello_nim_main.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"NimMain",
|
|
|
|
|
2022-12-01 02:54:11 +01:00
|
|
|
/* Ref:
|
|
|
|
* sim/posix/sim_rawgadget.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"bRequestType",
|
|
|
|
"bRequest",
|
|
|
|
"wValue",
|
|
|
|
"wIndex",
|
|
|
|
"wLength",
|
|
|
|
"bLength",
|
|
|
|
"bDescriptorType",
|
|
|
|
"bEndpointAddress",
|
|
|
|
"bmAttributes",
|
|
|
|
"wMaxPacketSize",
|
|
|
|
"bInterval",
|
|
|
|
|
2022-11-30 12:08:14 +01:00
|
|
|
/* Ref:
|
|
|
|
* sim/posix/sim_libusb.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"bNumConfigurations",
|
|
|
|
"bDeviceClass",
|
|
|
|
"idVendor",
|
|
|
|
"idProduct",
|
|
|
|
|
2023-05-16 08:46:35 +02:00
|
|
|
/* Ref:
|
|
|
|
* sim/posix/sim_hostmisc.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"_NSGetExecutablePath",
|
|
|
|
|
2023-03-05 14:30:31 +01:00
|
|
|
/* Ref:
|
|
|
|
* arch/arm/src/nrf52/sdc/nrf.h
|
|
|
|
* arch/arm/src/nrf53/sdc/nrf.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
"IRQn_Type",
|
|
|
|
|
2023-09-25 10:25:34 +02:00
|
|
|
/* Ref:
|
|
|
|
* fs/zipfs/zip_vfs.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"unzFile",
|
|
|
|
"uLong",
|
|
|
|
"unzOpen2_64",
|
|
|
|
"unzLocateFile",
|
|
|
|
"unzOpenCurrentFile",
|
|
|
|
"unzClose",
|
|
|
|
"unzReadCurrentFile",
|
|
|
|
"unzGetCurrentFileInfo64",
|
|
|
|
"unzGoToNextFile",
|
|
|
|
"unzGoToFirstFile",
|
2020-06-22 18:14:42 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2023-04-11 07:27:14 +02:00
|
|
|
static const char *g_white_headers[] =
|
|
|
|
{
|
|
|
|
"windows.h",
|
2024-02-18 08:52:30 +01:00
|
|
|
|
|
|
|
/* Ref:
|
|
|
|
* arch/tricore/src/common/tricore_serial.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
"IfxAsclin_Asc.h",
|
2023-04-11 07:27:14 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2023-04-26 11:27:43 +02:00
|
|
|
static const char *g_white_files[] =
|
|
|
|
{
|
|
|
|
/* Skip assembler file headers
|
|
|
|
* Ref:
|
|
|
|
* libs/libc/machine/arm/arm-acle-compat.h
|
|
|
|
* libs/libc/machine/arm/arm_asm.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
"arm-acle-compat.h",
|
|
|
|
"arm_asm.h",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2018-11-19 14:50:59 +01:00
|
|
|
* Private Functions
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2018-11-19 14:50:59 +01:00
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2020-01-13 19:08:45 +01:00
|
|
|
* Name: show_usage
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
static void show_usage(char *progname, int exitcode, char *what)
|
2018-11-19 14:50:59 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
fprintf(stderr, "%s version %s\n\n", basename(progname), NXSTYLE_VERSION);
|
|
|
|
if (what)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", what);
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
fprintf(stderr, "Usage: %s [-m <excess>] [-v <level>] "
|
|
|
|
"[-r <start,count>] <filename>\n",
|
2020-01-02 10:22:08 +01:00
|
|
|
basename(progname));
|
2019-12-30 19:34:43 +01:00
|
|
|
fprintf(stderr, " %s -h this help\n", basename(progname));
|
2020-03-07 14:35:08 +01:00
|
|
|
fprintf(stderr, " %s -v <level> where level is\n",
|
|
|
|
basename(progname));
|
2019-12-30 19:34:43 +01:00
|
|
|
fprintf(stderr, " 0 - no output\n");
|
|
|
|
fprintf(stderr, " 1 - PASS/FAIL\n");
|
|
|
|
fprintf(stderr, " 2 - output each line (default)\n");
|
2018-11-19 14:50:59 +01:00
|
|
|
exit(exitcode);
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2020-01-13 19:08:45 +01:00
|
|
|
* Name: skip
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2020-01-02 10:22:08 +01:00
|
|
|
static int skip(int lineno)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < g_rangenumber; i++)
|
|
|
|
{
|
2020-03-07 14:35:08 +01:00
|
|
|
if (lineno >= g_rangestart[i] && lineno < g_rangestart[i] +
|
|
|
|
g_rangecount[i])
|
2020-01-02 10:22:08 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_rangenumber != 0;
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2020-01-13 19:08:45 +01:00
|
|
|
* Name: message
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
static int message(enum class_e class, const char *text, int lineno, int ndx)
|
|
|
|
{
|
|
|
|
FILE *out = stdout;
|
|
|
|
|
2020-01-02 10:22:08 +01:00
|
|
|
if (skip(lineno))
|
|
|
|
{
|
|
|
|
return g_status;
|
|
|
|
}
|
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
if (class > INFO)
|
|
|
|
{
|
|
|
|
out = stderr;
|
|
|
|
g_status |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_verbose == 2)
|
|
|
|
{
|
|
|
|
if (lineno == -1 && ndx == -1)
|
|
|
|
{
|
2020-01-07 15:12:18 +01:00
|
|
|
fprintf(out, "%s: %s: %s\n", g_file_name, class_text[class], text);
|
2019-12-30 19:34:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(out, "%s:%d:%d: %s: %s\n", g_file_name, lineno, ndx,
|
|
|
|
class_text[class], text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_status;
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2020-01-13 19:08:45 +01:00
|
|
|
* Name: check_spaces_left
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
static void check_spaces_left(char *line, int lineno, int ndx)
|
|
|
|
{
|
|
|
|
/* Unary operator should generally be preceded by a space but make also
|
2019-06-30 00:19:10 +02:00
|
|
|
* follow a left parenthesis at the beginning of a parenthetical list or
|
2019-03-01 17:50:02 +01:00
|
|
|
* expression or follow a right parentheses in the case of a cast.
|
|
|
|
*/
|
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
if (ndx-- > 0 && line[ndx] != ' ' && line[ndx] != '(' && line[ndx] != ')')
|
2019-03-01 17:50:02 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Operator/assignment must be preceded with whitespace",
|
|
|
|
lineno, ndx);
|
2019-03-01 17:50:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2020-01-13 19:08:45 +01:00
|
|
|
* Name: check_spaces_leftright
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
static void check_spaces_leftright(char *line, int lineno, int ndx1, int ndx2)
|
|
|
|
{
|
|
|
|
if (ndx1 > 0 && line[ndx1 - 1] != ' ')
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Operator/assignment must be preceded with whitespace",
|
|
|
|
lineno, ndx1);
|
2019-03-01 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (line[ndx2 + 1] != '\0' && line[ndx2 + 1] != '\n' && line[ndx2 + 1] != ' ')
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Operator/assignment must be followed with whitespace",
|
|
|
|
lineno, ndx2);
|
2019-03-01 17:50:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 11:44:41 +02:00
|
|
|
/********************************************************************************
|
|
|
|
* Name: check_nospaces_leftright
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if there are whitespaces on the left of right. If there is, report
|
|
|
|
* an error.
|
|
|
|
*
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
static void check_nospaces_leftright(char *line, int lineno, int ndx1, int ndx2)
|
|
|
|
{
|
|
|
|
if (ndx1 > 0 && line[ndx1 - 1] == ' ')
|
|
|
|
{
|
|
|
|
ERROR("There should be no spaces before the operator/assignment",
|
|
|
|
lineno, ndx1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line[ndx2 + 1] == ' ')
|
|
|
|
{
|
|
|
|
ERROR("There should be no spaces after the operator/assignment",
|
|
|
|
lineno, ndx2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Name: check_operand_leftright
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if the operator is next to an operand. If not, report the error.
|
|
|
|
*
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
static void check_operand_leftright(char *line, int lineno, int ndx1, int ndx2)
|
|
|
|
{
|
|
|
|
/* The cases below includes("xx" represents the operator):
|
|
|
|
* " xx " | " xx(end)" | " xx;" | " xx\n" | " xx)" | " xx]" - (ndx1 > 0)
|
|
|
|
* "(xx " | "(xx(end)" | "(xx;" | "(xx\n" | "(xx)" | "(xx]" - (ndx1 > 0)
|
|
|
|
* "[xx " | "[xx(end)" | "[xx;" | "[xx\n" | "[xx)" | "[xx]" - (ndx1 > 0)
|
|
|
|
* "xx " | "xx(end)" | "xx;" | "xx\n" | "xx)" | "xx]" - (ndx1 = 0)
|
|
|
|
* In these cases, the operators must be not next any operands, thus errors
|
|
|
|
* are reported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ndx1 > 0 && (line[ndx1 - 1] == ' ' || line[ndx1 - 1] == '(' ||
|
|
|
|
line[ndx1 - 1] == '[') &&
|
|
|
|
(line[ndx2 + 1] == ' ' || line[ndx2 + 1] == '\0' ||
|
|
|
|
line[ndx2 + 1] == ';' || line[ndx2 + 1] == '\n' ||
|
|
|
|
line[ndx2 + 1] == ')' || line[ndx2 + 1] == ']'))
|
|
|
|
{
|
|
|
|
ERROR("Operator must be next to an operand", lineno, ndx2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2020-01-13 19:08:45 +01:00
|
|
|
* Name: block_comment_width
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the width of a block comment
|
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2020-01-12 17:07:54 +01:00
|
|
|
static int block_comment_width(char *line)
|
|
|
|
{
|
|
|
|
int b;
|
|
|
|
int e;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
/* Skip over any leading whitespace on the line */
|
|
|
|
|
|
|
|
for (b = 0; isspace(line[b]); b++)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip over any trailing whitespace at the end of the line */
|
|
|
|
|
2020-06-16 16:00:15 +02:00
|
|
|
for (e = strlen(line) - 1; e >= 0 && isspace(line[e]); e--)
|
2020-01-12 17:07:54 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Number of characters on the line */
|
|
|
|
|
|
|
|
n = e - b + 1;
|
|
|
|
if (n < 4)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The first line of a block comment starts with "[slash]***" and ends with
|
|
|
|
* "***"
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (strncmp(&line[b], "/***", 4) == 0 &&
|
|
|
|
strncmp(&line[e - 2], "***", 3) == 0)
|
|
|
|
{
|
|
|
|
/* Return the the length of the line up to the final '*' */
|
|
|
|
|
|
|
|
return e + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The last line of a block begins with whitespace then "***" and ends
|
|
|
|
* with "***[slash]"
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (strncmp(&line[b], "***", 3) == 0 &&
|
2020-01-12 18:47:11 +01:00
|
|
|
strncmp(&line[e - 3], "***/", 4) == 0)
|
2020-01-12 17:07:54 +01:00
|
|
|
{
|
|
|
|
/* Return the the length of the line up to the final '*' */
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* But there is also a special single line comment that begins with "[slash]* "
|
|
|
|
* and ends with "***[slash]"
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (strncmp(&line[b], "/*", 2) == 0 &&
|
2020-01-12 18:47:11 +01:00
|
|
|
strncmp(&line[e - 3], "***/", 4) == 0)
|
2020-01-12 17:07:54 +01:00
|
|
|
{
|
|
|
|
/* Return the the length of the line up to the final '*' */
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return zero if the line is not the first or last line of a block
|
|
|
|
* comment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2020-01-13 19:08:45 +01:00
|
|
|
* Name: get_line_width
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the maximum line width by examining the width of the block comments.
|
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2020-01-12 17:07:54 +01:00
|
|
|
static int get_line_width(FILE *instream)
|
|
|
|
{
|
|
|
|
char line[LINE_SIZE]; /* The current line being examined */
|
2020-03-06 21:14:23 +01:00
|
|
|
int max = 0;
|
|
|
|
int min = INT_MAX;
|
|
|
|
int lineno = 0;
|
|
|
|
int lineno_max = 0;
|
|
|
|
int lineno_min = 0;
|
2020-01-12 17:07:54 +01:00
|
|
|
int len;
|
|
|
|
|
|
|
|
while (fgets(line, LINE_SIZE, instream))
|
|
|
|
{
|
2020-03-06 07:16:25 +01:00
|
|
|
lineno++;
|
2020-01-12 17:07:54 +01:00
|
|
|
len = block_comment_width(line);
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
if (len > max)
|
|
|
|
{
|
|
|
|
max = len;
|
2020-03-06 07:16:25 +01:00
|
|
|
lineno_max = lineno;
|
2020-01-12 17:07:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (len < min)
|
|
|
|
{
|
|
|
|
min = len;
|
2020-03-08 13:55:46 +01:00
|
|
|
lineno_min = lineno;
|
2020-01-12 17:07:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max < min)
|
|
|
|
{
|
|
|
|
ERRORFL("No block comments found", g_file_name);
|
|
|
|
return DEFAULT_WIDTH;
|
|
|
|
}
|
|
|
|
else if (max != min)
|
|
|
|
{
|
2020-03-06 07:16:25 +01:00
|
|
|
ERROR("Block comments have different lengths", lineno_max, max);
|
|
|
|
ERROR("Block comments have different lengths", lineno_min, min);
|
2020-01-12 17:07:54 +01:00
|
|
|
return DEFAULT_WIDTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return min;
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2020-01-13 19:08:45 +01:00
|
|
|
* Name: check_section_header
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if the current line holds a section header
|
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
|
|
|
static bool check_section_header(const char *line, int lineno)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Search g_section_info[] to find a matching section header line */
|
|
|
|
|
|
|
|
for (i = FIRST_SECTION; i <= LAST_SECTION; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(line, g_section_info[i].name) == 0)
|
|
|
|
{
|
|
|
|
g_section = (enum section_s)i;
|
|
|
|
|
|
|
|
/* Verify that this section is appropriate for this file type */
|
|
|
|
|
|
|
|
if ((g_file_type & g_section_info[i].ftype) == 0)
|
|
|
|
{
|
|
|
|
ERROR("Invalid section for this file type", lineno, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:43:28 +02:00
|
|
|
/********************************************************************************
|
2023-04-26 11:27:43 +02:00
|
|
|
* Name: white_file_list
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return true if the filename string with a white-listed name
|
|
|
|
*
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
static bool white_file_list(const char *filename)
|
|
|
|
{
|
|
|
|
const char **pptr;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
for (pptr = g_white_files;
|
|
|
|
(str = *pptr) != NULL;
|
|
|
|
pptr++)
|
|
|
|
{
|
|
|
|
if (strstr(filename, str) != NULL)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Name: white_content_list
|
2020-03-31 19:43:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return true if the identifier string begins with a white-listed prefix
|
|
|
|
*
|
|
|
|
********************************************************************************/
|
|
|
|
|
2023-04-26 11:27:43 +02:00
|
|
|
static bool white_content_list(const char *ident, int lineno)
|
2020-03-31 19:43:28 +02:00
|
|
|
{
|
|
|
|
const char **pptr;
|
|
|
|
const char *str;
|
2022-05-13 04:46:52 +02:00
|
|
|
size_t len2;
|
|
|
|
size_t len;
|
2020-03-31 19:43:28 +02:00
|
|
|
|
|
|
|
for (pptr = g_white_prefix;
|
|
|
|
(str = *pptr) != NULL;
|
|
|
|
pptr++)
|
|
|
|
{
|
2022-05-13 04:46:52 +02:00
|
|
|
len = strlen(str);
|
|
|
|
if (strncmp(ident, str, len) == 0)
|
2020-03-31 19:43:28 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 07:27:14 +02:00
|
|
|
for (pptr = g_white_headers;
|
|
|
|
(str = *pptr) != NULL;
|
|
|
|
pptr++)
|
|
|
|
{
|
|
|
|
if (strstr(ident, str) != NULL)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-13 04:46:52 +02:00
|
|
|
len2 = strlen(ident);
|
2022-05-13 14:31:29 +02:00
|
|
|
while (!isalnum(ident[len2 - 1]))
|
2022-05-13 04:46:52 +02:00
|
|
|
{
|
|
|
|
len2--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pptr = g_white_suffix;
|
2020-06-22 18:14:42 +02:00
|
|
|
(str = *pptr) != NULL;
|
|
|
|
pptr++)
|
|
|
|
{
|
2022-05-13 04:46:52 +02:00
|
|
|
len = strlen(str);
|
|
|
|
if (len2 >= len && strncmp(ident + len2 - len, str, len) == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 18:14:42 +02:00
|
|
|
|
2023-04-26 11:27:43 +02:00
|
|
|
for (pptr = g_white_content_list;
|
2022-05-13 04:46:52 +02:00
|
|
|
(str = *pptr) != NULL;
|
|
|
|
pptr++)
|
|
|
|
{
|
|
|
|
len = strlen(str);
|
2020-06-22 18:14:42 +02:00
|
|
|
if (strncmp(ident, str, len) == 0 &&
|
|
|
|
isalnum(ident[len]) == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:43:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/********************************************************************************
|
2015-10-08 20:48:40 +02:00
|
|
|
* Public Functions
|
2020-03-07 14:35:08 +01:00
|
|
|
********************************************************************************/
|
2015-10-08 20:48:40 +02:00
|
|
|
|
|
|
|
int main(int argc, char **argv, char **envp)
|
|
|
|
{
|
2019-02-08 14:49:19 +01:00
|
|
|
FILE *instream; /* File input stream */
|
|
|
|
char line[LINE_SIZE]; /* The current line being examined */
|
2019-12-30 19:34:43 +01:00
|
|
|
char buffer[100]; /* Localy format error strings */
|
2019-02-08 14:49:19 +01:00
|
|
|
char *lptr; /* Temporary pointer into line[] */
|
2019-06-30 02:38:56 +02:00
|
|
|
char *ext; /* Temporary file extension */
|
2019-02-08 14:49:19 +01:00
|
|
|
bool btabs; /* True: TAB characters found on the line */
|
2019-10-23 20:49:27 +02:00
|
|
|
bool bcrs; /* True: Carriage return found on the line */
|
2019-02-08 14:49:19 +01:00
|
|
|
bool bfunctions; /* True: In private or public functions */
|
|
|
|
bool bstatm; /* True: This line is beginning of a statement */
|
|
|
|
bool bfor; /* True: This line is beginning of a 'for' statement */
|
2024-07-29 19:59:32 +02:00
|
|
|
bool bif; /* True: This line is beginning of a 'if' statement */
|
2019-02-08 14:49:19 +01:00
|
|
|
bool bswitch; /* True: Within a switch statement */
|
|
|
|
bool bstring; /* True: Within a string */
|
|
|
|
bool bquote; /* True: Backslash quoted character next */
|
2019-06-30 00:19:10 +02:00
|
|
|
bool bblank; /* Used to verify block comment terminator */
|
2019-06-30 23:10:14 +02:00
|
|
|
bool bexternc; /* True: Within 'extern "C"' */
|
2020-03-09 12:53:21 +01:00
|
|
|
enum pptype_e ppline; /* > 0: The next line the continuation of a
|
|
|
|
* pre-processor command */
|
|
|
|
int rhcomment; /* Indentation of Comment to the right of code
|
|
|
|
* (-1 -> don't check position) */
|
|
|
|
int prevrhcmt; /* Indentation of previous Comment to the right
|
|
|
|
* of code (-1 -> don't check position) */
|
2019-02-08 14:49:19 +01:00
|
|
|
int lineno; /* Current line number */
|
|
|
|
int indent; /* Indentation level */
|
|
|
|
int ncomment; /* Comment nesting level on this line */
|
|
|
|
int prevncomment; /* Comment nesting level on the previous line */
|
2019-02-17 17:57:28 +01:00
|
|
|
int bnest; /* Brace nesting level on this line */
|
|
|
|
int prevbnest; /* Brace nesting level on the previous line */
|
|
|
|
int dnest; /* Data declaration nesting level on this line */
|
|
|
|
int prevdnest; /* Data declaration nesting level on the previous line */
|
|
|
|
int pnest; /* Parenthesis nesting level on this line */
|
2020-03-14 14:36:47 +01:00
|
|
|
int ppifnest; /* #if nesting level on this line */
|
|
|
|
int inasm; /* > 0: Within #ifdef __ASSEMBLY__ */
|
2019-11-09 15:15:12 +01:00
|
|
|
int comment_lineno; /* Line on which the last comment was closed */
|
2019-02-08 14:49:19 +01:00
|
|
|
int blank_lineno; /* Line number of the last blank line */
|
|
|
|
int noblank_lineno; /* A blank line is not needed after this line */
|
2019-03-10 16:53:33 +01:00
|
|
|
int lbrace_lineno; /* Line number of last left brace */
|
2019-10-24 18:49:28 +02:00
|
|
|
int rbrace_lineno; /* Last line containing a right brace */
|
2019-06-30 23:10:14 +02:00
|
|
|
int externc_lineno; /* Last line where 'extern "C"' declared */
|
2019-02-08 14:49:19 +01:00
|
|
|
int linelen; /* Length of the line */
|
2020-01-12 17:07:54 +01:00
|
|
|
int excess;
|
2015-10-08 20:48:40 +02:00
|
|
|
int n;
|
|
|
|
int i;
|
2019-12-30 19:34:43 +01:00
|
|
|
int c;
|
2018-11-19 14:50:59 +01:00
|
|
|
|
2020-01-12 17:07:54 +01:00
|
|
|
excess = 0;
|
2020-01-02 10:22:08 +01:00
|
|
|
while ((c = getopt(argc, argv, ":hv:gm:r:")) != -1)
|
2018-11-19 14:50:59 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'm':
|
2020-01-12 17:07:54 +01:00
|
|
|
excess = atoi(optarg);
|
|
|
|
if (excess < 1)
|
2019-12-30 19:34:43 +01:00
|
|
|
{
|
2020-01-12 17:07:54 +01:00
|
|
|
show_usage(argv[0], 1, "Bad value for <excess>.");
|
|
|
|
excess = 0;
|
2019-12-30 19:34:43 +01:00
|
|
|
}
|
2020-01-12 17:07:54 +01:00
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
g_verbose = atoi(optarg);
|
|
|
|
if (g_verbose < 0 || g_verbose > 2)
|
|
|
|
{
|
|
|
|
show_usage(argv[0], 1, "Bad value for <level>.");
|
|
|
|
}
|
2020-01-12 17:07:54 +01:00
|
|
|
|
|
|
|
break;
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2020-01-02 10:22:08 +01:00
|
|
|
case 'r':
|
|
|
|
g_rangestart[g_rangenumber] = atoi(strtok(optarg, ","));
|
|
|
|
g_rangecount[g_rangenumber++] = atoi(strtok(NULL, ","));
|
|
|
|
break;
|
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
case 'h':
|
|
|
|
show_usage(argv[0], 0, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ':':
|
|
|
|
show_usage(argv[0], 1, "Missing argument.");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
show_usage(argv[0], 1, "Unrecognized option.");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
show_usage(argv[0], 0, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind < argc - 1 || argv[optind] == NULL)
|
2018-11-19 14:50:59 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
show_usage(argv[0], 1, "No file name given.");
|
2018-11-19 14:50:59 +01:00
|
|
|
}
|
|
|
|
|
2021-03-04 20:34:39 +01:00
|
|
|
/* Resolve the absolute path for the input file */
|
|
|
|
|
|
|
|
if (realpath(argv[optind], g_file_name) == NULL)
|
|
|
|
{
|
|
|
|
FATALFL("Failed to resolve absolute path.", g_file_name);
|
|
|
|
return 1;
|
|
|
|
}
|
2020-01-12 17:07:54 +01:00
|
|
|
|
2019-06-30 02:38:56 +02:00
|
|
|
/* Are we parsing a header file? */
|
|
|
|
|
2020-01-07 15:12:18 +01:00
|
|
|
ext = strrchr(g_file_name, '.');
|
2019-06-30 02:38:56 +02:00
|
|
|
|
|
|
|
if (ext == 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if (strcmp(ext, ".h") == 0)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
g_file_type = C_HEADER;
|
2019-06-30 02:38:56 +02:00
|
|
|
}
|
2019-12-30 19:34:43 +01:00
|
|
|
else if (strcmp(ext, ".c") == 0)
|
2019-06-30 02:38:56 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
g_file_type = C_SOURCE;
|
2019-06-30 02:38:56 +02:00
|
|
|
}
|
|
|
|
|
2020-01-07 15:12:18 +01:00
|
|
|
if (g_file_type == UNKNOWN)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-04-26 11:27:43 +02:00
|
|
|
if (white_file_list(g_file_name))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-06 03:01:42 +01:00
|
|
|
instream = fopen(g_file_name, "r");
|
|
|
|
|
|
|
|
if (!instream)
|
|
|
|
{
|
|
|
|
FATALFL("Failed to open", g_file_name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the line width */
|
|
|
|
|
|
|
|
g_maxline = get_line_width(instream) + excess;
|
|
|
|
rewind(instream);
|
|
|
|
|
2020-03-09 12:53:21 +01:00
|
|
|
btabs = false; /* True: TAB characters found on the line */
|
|
|
|
bcrs = false; /* True: Carriage return found on the line */
|
|
|
|
bfunctions = false; /* True: In private or public functions */
|
|
|
|
bswitch = false; /* True: Within a switch statement */
|
|
|
|
bstring = false; /* True: Within a string */
|
|
|
|
bexternc = false; /* True: Within 'extern "C"' */
|
2024-08-26 15:00:01 +02:00
|
|
|
bif = false; /* True: This line is beginning of a 'if' statement */
|
2020-03-09 12:53:21 +01:00
|
|
|
ppline = PPLINE_NONE; /* > 0: The next line the continuation of a
|
|
|
|
* pre-processor command */
|
|
|
|
rhcomment = 0; /* Indentation of Comment to the right of code
|
|
|
|
* (-1 -> don't check position) */
|
|
|
|
prevrhcmt = 0; /* Indentation of previous Comment to the right
|
|
|
|
* of code (-1 -> don't check position) */
|
|
|
|
lineno = 0; /* Current line number */
|
|
|
|
ncomment = 0; /* Comment nesting level on this line */
|
|
|
|
bnest = 0; /* Brace nesting level on this line */
|
|
|
|
dnest = 0; /* Data declaration nesting level on this line */
|
|
|
|
pnest = 0; /* Parenthesis nesting level on this line */
|
2020-03-14 14:36:47 +01:00
|
|
|
ppifnest = 0; /* #if nesting level on this line */
|
|
|
|
inasm = 0; /* > 0: Within #ifdef __ASSEMBLY__ */
|
2020-03-09 12:53:21 +01:00
|
|
|
comment_lineno = -1; /* Line on which the last comment was closed */
|
|
|
|
blank_lineno = -1; /* Line number of the last blank line */
|
|
|
|
noblank_lineno = -1; /* A blank line is not needed after this line */
|
|
|
|
lbrace_lineno = -1; /* Line number of last left brace */
|
|
|
|
rbrace_lineno = -1; /* Last line containing a right brace */
|
|
|
|
externc_lineno = -1; /* Last line where 'extern "C"' declared */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-05 20:08:57 +01:00
|
|
|
/* Process each line in the input stream */
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
while (fgets(line, LINE_SIZE, instream))
|
|
|
|
{
|
|
|
|
lineno++;
|
|
|
|
indent = 0;
|
2019-02-17 17:57:28 +01:00
|
|
|
prevbnest = bnest; /* Brace nesting level on the previous line */
|
2020-03-07 14:35:08 +01:00
|
|
|
prevdnest = dnest; /* Data declaration nesting level on the
|
|
|
|
* previous line */
|
2019-02-08 14:49:19 +01:00
|
|
|
prevncomment = ncomment; /* Comment nesting level on the previous line */
|
2020-03-07 14:35:08 +01:00
|
|
|
bstatm = false; /* True: This line is beginning of a
|
|
|
|
* statement */
|
2019-02-08 14:49:19 +01:00
|
|
|
bfor = false; /* REVISIT: Implies for() is all on one line */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-03-07 14:35:08 +01:00
|
|
|
/* If we are not in a comment, then this certainly is not a right-hand
|
|
|
|
* comment.
|
|
|
|
*/
|
2019-10-27 18:45:33 +01:00
|
|
|
|
2020-03-08 20:08:47 +01:00
|
|
|
prevrhcmt = rhcomment;
|
2019-10-27 18:45:33 +01:00
|
|
|
if (ncomment <= 0)
|
|
|
|
{
|
2020-03-08 20:02:51 +01:00
|
|
|
rhcomment = 0;
|
2019-10-27 18:45:33 +01:00
|
|
|
}
|
|
|
|
|
2018-04-11 23:45:39 +02:00
|
|
|
/* Check for a blank line */
|
|
|
|
|
2018-10-29 23:25:57 +01:00
|
|
|
for (n = 0; line[n] != '\n' && isspace((int)line[n]); n++)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line[n] == '\n')
|
2018-08-21 21:07:29 +02:00
|
|
|
{
|
2018-10-29 23:25:57 +01:00
|
|
|
if (n > 0)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Blank line contains whitespace", lineno, 1);
|
2018-10-29 23:25:57 +01:00
|
|
|
}
|
|
|
|
|
2018-10-30 23:33:41 +01:00
|
|
|
if (lineno == 1)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("File begins with a blank line", 1, 1);
|
2018-10-30 23:33:41 +01:00
|
|
|
}
|
|
|
|
else if (lineno == blank_lineno + 1)
|
2018-08-24 13:51:44 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Too many blank lines", lineno, 1);
|
2018-08-24 13:51:44 +02:00
|
|
|
}
|
2019-03-10 16:53:33 +01:00
|
|
|
else if (lineno == lbrace_lineno + 1)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Blank line follows left brace", lineno, 1);
|
2019-03-10 16:53:33 +01:00
|
|
|
}
|
2018-08-24 13:51:44 +02:00
|
|
|
|
|
|
|
blank_lineno = lineno;
|
2018-10-30 23:33:41 +01:00
|
|
|
continue;
|
2018-08-21 21:07:29 +02:00
|
|
|
}
|
2018-10-30 01:00:30 +01:00
|
|
|
else /* This line is non-blank */
|
2018-04-11 23:45:39 +02:00
|
|
|
{
|
2018-10-29 23:25:57 +01:00
|
|
|
/* Check for a missing blank line after a comment */
|
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
if (lineno == comment_lineno + 1)
|
2018-04-11 23:45:39 +02:00
|
|
|
{
|
2018-10-29 23:25:57 +01:00
|
|
|
/* No blank line should be present if the current line contains
|
2018-10-30 23:33:41 +01:00
|
|
|
* a right brace, a pre-processor line, the start of another
|
|
|
|
* comment.
|
2018-10-30 01:00:30 +01:00
|
|
|
*
|
|
|
|
* REVISIT: Generates a false alarm if the current line is also
|
|
|
|
* a comment. Generally it is acceptable for one comment to
|
|
|
|
* follow another with no space separation.
|
2019-12-03 13:38:53 +01:00
|
|
|
*
|
2020-03-08 20:02:51 +01:00
|
|
|
* REVISIT: prevrhcmt is tested to case the preceding line
|
2019-12-03 13:38:53 +01:00
|
|
|
* contained comments to the right of the code. In such cases,
|
|
|
|
* the comments are normally aligned and do not follow normal
|
|
|
|
* indentation rules. However, this code will generate a false
|
|
|
|
* alarm if the comments are aligned to the right BUT the
|
|
|
|
* preceding line has no comment.
|
2018-08-21 21:32:05 +02:00
|
|
|
*/
|
|
|
|
|
2020-03-08 20:12:06 +01:00
|
|
|
if (line[n] != '}' && line[n] != '#' && prevrhcmt == 0)
|
2018-10-29 23:25:57 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Missing blank line after comment", comment_lineno,
|
|
|
|
1);
|
2018-10-29 23:25:57 +01:00
|
|
|
}
|
2018-04-11 23:45:39 +02:00
|
|
|
}
|
2019-02-08 15:30:06 +01:00
|
|
|
|
2019-02-09 14:19:10 +01:00
|
|
|
/* Files must begin with a comment (the file header).
|
|
|
|
* REVISIT: Logically, this belongs in the STEP 2 operations
|
|
|
|
* below.
|
|
|
|
*/
|
2019-02-08 15:30:06 +01:00
|
|
|
|
|
|
|
if (lineno == 1 && (line[n] != '/' || line[n + 1] != '*'))
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Missing file header comment block", lineno, 1);
|
2019-02-08 15:30:06 +01:00
|
|
|
}
|
2019-10-24 18:49:28 +02:00
|
|
|
|
2021-03-04 20:34:39 +01:00
|
|
|
if (lineno == 2)
|
|
|
|
{
|
|
|
|
if (line[n] == '*' && line[n + 1] == '\n')
|
|
|
|
{
|
|
|
|
ERROR("Missing relative file path in file header", lineno,
|
|
|
|
n);
|
|
|
|
}
|
|
|
|
else if (isspace(line[n + 2]))
|
|
|
|
{
|
|
|
|
ERROR("Too many whitespaces before relative file path",
|
|
|
|
lineno, n);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *apps_dir = "apps/";
|
|
|
|
const size_t apps_len = strlen(apps_dir);
|
|
|
|
size_t offset;
|
|
|
|
|
|
|
|
#ifdef TOPDIR
|
|
|
|
/* TOPDIR macro contains the absolute path to the "nuttx"
|
|
|
|
* root directory. It should have been defined via Makefile
|
|
|
|
* and it is required to accurately evaluate the relative
|
|
|
|
* path contained in the file header. Otherwise, skip this
|
|
|
|
* verification.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *basedir = strstr(g_file_name, TOPDIR);
|
|
|
|
if (basedir != NULL)
|
|
|
|
{
|
|
|
|
/* Add 1 to the offset for the slash character */
|
|
|
|
|
|
|
|
offset = strlen(TOPDIR) + 1;
|
|
|
|
|
|
|
|
/* Duplicate the line from the beginning of the
|
|
|
|
* relative file path, removing the '\n' at the end of
|
|
|
|
* the string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *line_dup = strndup(&line[n + 2],
|
|
|
|
strlen(&line[n + 2]) - 1);
|
|
|
|
|
|
|
|
if (strcmp(line_dup, basedir + offset) != 0)
|
|
|
|
{
|
|
|
|
ERROR("Relative file path does not match actual file",
|
|
|
|
lineno, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(line_dup);
|
|
|
|
}
|
|
|
|
else if (strncmp(&line[n + 2], apps_dir, apps_len) != 0)
|
|
|
|
{
|
|
|
|
/* g_file_name neither belongs to "nuttx" repository
|
|
|
|
* nor begins with the root dir of the other
|
|
|
|
* repository (e.g. "apps/")
|
|
|
|
*/
|
|
|
|
|
|
|
|
ERROR("Path relative to repository other than \"nuttx\" "
|
|
|
|
"must begin with the root directory", lineno, n);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
if (strncmp(&line[n + 2], apps_dir, apps_len) == 0)
|
|
|
|
{
|
|
|
|
/* Input file belongs to the "apps" repository */
|
|
|
|
|
|
|
|
/* Calculate the offset to the first directory
|
|
|
|
* after the "apps/" folder.
|
|
|
|
*/
|
|
|
|
|
|
|
|
offset += apps_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Duplicate the line from the beginning of the
|
|
|
|
* relative file path, removing the '\n' at the end of
|
|
|
|
* the string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *line_dup = strndup(&line[n + 2],
|
|
|
|
strlen(&line[n + 2]) - 1);
|
|
|
|
|
|
|
|
ssize_t base =
|
|
|
|
strlen(g_file_name) - strlen(&line_dup[offset]);
|
|
|
|
|
|
|
|
if (base < 0 ||
|
|
|
|
(base != 0 && g_file_name[base - 1] != '/') ||
|
|
|
|
strcmp(&g_file_name[base], &line_dup[offset]) != 0)
|
|
|
|
{
|
|
|
|
ERROR("Relative file path does not match actual file",
|
|
|
|
lineno, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(line_dup);
|
|
|
|
#ifdef TOPDIR
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
/* Check for a blank line following a right brace */
|
2019-10-24 18:49:28 +02:00
|
|
|
|
|
|
|
if (bfunctions && lineno == rbrace_lineno + 1)
|
2019-12-30 19:34:43 +01:00
|
|
|
{
|
|
|
|
/* Check if this line contains a right brace. A right brace
|
|
|
|
* must be followed by 'else', 'while', 'break', a blank line,
|
|
|
|
* another right brace, or a pre-processor directive like #endif
|
|
|
|
*/
|
2019-10-24 18:49:28 +02:00
|
|
|
|
2020-03-12 21:11:12 +01:00
|
|
|
if (dnest == 0 &&
|
|
|
|
strchr(line, '}') == NULL && line[n] != '#' &&
|
2019-12-30 19:34:43 +01:00
|
|
|
strncmp(&line[n], "else", 4) != 0 &&
|
|
|
|
strncmp(&line[n], "while", 5) != 0 &&
|
|
|
|
strncmp(&line[n], "break", 5) != 0)
|
|
|
|
{
|
|
|
|
ERROR("Right brace must be followed by a blank line",
|
|
|
|
rbrace_lineno, n + 1);
|
|
|
|
}
|
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
/* If the right brace is followed by a pre-processor command
|
2019-12-30 19:34:43 +01:00
|
|
|
* like #endif (but not #else or #elif), then set the right
|
|
|
|
* brace line number to the line number of the pre-processor
|
|
|
|
* command (it then must be followed by a blank line)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (line[n] == '#')
|
|
|
|
{
|
|
|
|
int ii;
|
|
|
|
|
|
|
|
for (ii = n + 1; line[ii] != '\0' && isspace(line[ii]); ii++)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(&line[ii], "else", 4) != 0 &&
|
|
|
|
strncmp(&line[ii], "elif", 4) != 0)
|
|
|
|
{
|
|
|
|
rbrace_lineno = lineno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 23:45:39 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
/* STEP 1: Find the indentation level and the start of real stuff on
|
|
|
|
* the line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (n = 0; line[n] != '\n' && isspace((int)line[n]); n++)
|
|
|
|
{
|
|
|
|
switch (line[n])
|
|
|
|
{
|
|
|
|
case ' ':
|
|
|
|
{
|
|
|
|
indent++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\t':
|
|
|
|
{
|
|
|
|
if (!btabs)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("TABs found. First detected", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
btabs = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
indent = (indent + 4) & ~3;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-10-23 20:49:27 +02:00
|
|
|
case '\r':
|
|
|
|
{
|
|
|
|
if (!bcrs)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Carriage returns found. "
|
|
|
|
"First detected", lineno, n);
|
2019-10-23 20:49:27 +02:00
|
|
|
bcrs = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
default:
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"Unexpected white space character %02x found",
|
|
|
|
line[n]);
|
|
|
|
ERROR(buffer, lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* STEP 2: Detect some certain start of line conditions */
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-02-17 17:57:28 +01:00
|
|
|
/* Skip over pre-processor lines (or continuations of pre-processor
|
|
|
|
* lines as indicated by ppline)
|
|
|
|
*/
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-03-09 12:53:21 +01:00
|
|
|
if (line[indent] == '#' || ppline != PPLINE_NONE)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
int len;
|
2020-01-13 19:08:45 +01:00
|
|
|
int ii;
|
2019-02-17 17:57:28 +01:00
|
|
|
|
2018-08-21 21:07:29 +02:00
|
|
|
/* Suppress error for comment following conditional compilation */
|
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
noblank_lineno = lineno;
|
2019-02-17 17:57:28 +01:00
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
/* Check pre-processor commands if this is not a continuation
|
|
|
|
* line.
|
|
|
|
*/
|
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
ii = indent + 1;
|
|
|
|
|
2020-03-09 12:53:21 +01:00
|
|
|
if (ppline == PPLINE_NONE)
|
2020-01-13 19:08:45 +01:00
|
|
|
{
|
|
|
|
/* Skip to the pre-processor command following the '#' */
|
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
while (line[ii] != '\0' && isspace(line[ii]))
|
|
|
|
{
|
|
|
|
ii++;
|
|
|
|
}
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
if (line[ii] != '\0')
|
|
|
|
{
|
|
|
|
/* Make sure that pre-processor definitions are all in
|
|
|
|
* the pre-processor definitions section.
|
|
|
|
*/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
ppline = PPLINE_OTHER;
|
2020-03-09 12:53:21 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
if (strncmp(&line[ii], "define", 6) == 0)
|
|
|
|
{
|
|
|
|
ppline = PPLINE_DEFINE;
|
2020-03-09 12:53:21 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
if (g_section != PRE_PROCESSOR_DEFINITIONS)
|
|
|
|
{
|
|
|
|
/* A complication is the header files always have
|
|
|
|
* the idempotence guard definitions before the
|
|
|
|
* "Pre-processor Definitions section".
|
|
|
|
*/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
if (g_section == NO_SECTION &&
|
|
|
|
g_file_type != C_HEADER)
|
|
|
|
{
|
|
|
|
/* Only a warning because there is some usage
|
|
|
|
* of define outside the Pre-processor
|
|
|
|
* Definitions section which is justifiable.
|
|
|
|
* Should be manually checked.
|
|
|
|
*/
|
|
|
|
|
|
|
|
WARN("#define outside of 'Pre-processor "
|
|
|
|
"Definitions' section",
|
|
|
|
lineno, ii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
/* Make sure that files are included only in the Included
|
|
|
|
* Files section.
|
|
|
|
*/
|
2020-01-13 19:08:45 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
else if (strncmp(&line[ii], "include", 7) == 0)
|
|
|
|
{
|
|
|
|
if (g_section != INCLUDED_FILES)
|
|
|
|
{
|
|
|
|
/* Only a warning because there is some usage of
|
|
|
|
* include outside the Included Files section
|
|
|
|
* which may be is justifiable. Should be
|
|
|
|
* manually checked.
|
|
|
|
*/
|
|
|
|
|
|
|
|
WARN("#include outside of 'Included Files' "
|
|
|
|
"section",
|
|
|
|
lineno, ii);
|
|
|
|
}
|
2023-04-26 11:27:43 +02:00
|
|
|
else if (white_content_list(&line[ii], lineno))
|
2023-04-11 07:27:14 +02:00
|
|
|
{
|
|
|
|
g_skipmixedcase = true;
|
|
|
|
}
|
2020-03-14 14:36:47 +01:00
|
|
|
}
|
|
|
|
else if (strncmp(&line[ii], "if", 2) == 0)
|
|
|
|
{
|
|
|
|
ppifnest++;
|
|
|
|
|
|
|
|
ppline = PPLINE_IF;
|
|
|
|
ii += 2;
|
|
|
|
}
|
|
|
|
else if (strncmp(&line[ii], "elif", 4) == 0)
|
|
|
|
{
|
|
|
|
if (ppifnest == inasm)
|
|
|
|
{
|
|
|
|
inasm = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ppline = PPLINE_ELIF;
|
|
|
|
ii += 4;
|
|
|
|
}
|
|
|
|
else if (strncmp(&line[ii], "else", 4) == 0)
|
|
|
|
{
|
|
|
|
if (ppifnest == inasm)
|
|
|
|
{
|
|
|
|
inasm = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ppline = PPLINE_ELSE;
|
|
|
|
}
|
|
|
|
else if (strncmp(&line[ii], "endif", 4) == 0)
|
|
|
|
{
|
|
|
|
if (ppifnest == inasm)
|
|
|
|
{
|
|
|
|
inasm = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ppifnest--;
|
|
|
|
|
|
|
|
ppline = PPLINE_ENDIF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ppline == PPLINE_IF || ppline == PPLINE_ELIF)
|
|
|
|
{
|
|
|
|
int bdef = 0;
|
|
|
|
|
|
|
|
if (strncmp(&line[ii], "def", 3) == 0)
|
|
|
|
{
|
|
|
|
bdef = 1;
|
|
|
|
ii += 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (line[ii] != '\0' && isspace(line[ii]))
|
|
|
|
{
|
|
|
|
ii++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(&line[ii], "defined", 7) == 0)
|
|
|
|
{
|
|
|
|
bdef = 1;
|
|
|
|
ii += 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bdef)
|
|
|
|
{
|
|
|
|
while (line[ii] != '\0' &&
|
|
|
|
(isspace(line[ii]) || line[ii] == '('))
|
|
|
|
{
|
|
|
|
ii++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(&line[ii], "__ASSEMBLY__", 12) == 0)
|
|
|
|
{
|
|
|
|
inasm = ppifnest;
|
|
|
|
}
|
|
|
|
}
|
2020-01-13 19:08:45 +01:00
|
|
|
}
|
|
|
|
|
2019-02-17 17:57:28 +01:00
|
|
|
/* Check if the next line will be a continuation of the pre-
|
|
|
|
* processor command.
|
|
|
|
*/
|
|
|
|
|
|
|
|
len = strlen(&line[indent]) + indent - 1;
|
|
|
|
if (line[len] == '\n')
|
|
|
|
{
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
2020-03-08 20:02:51 +01:00
|
|
|
/* Propagate rhcomment over preprocessor lines Issue #120 */
|
|
|
|
|
2020-03-19 15:00:42 +01:00
|
|
|
if (prevrhcmt != 0)
|
|
|
|
{
|
|
|
|
/* Don't check position */
|
|
|
|
|
|
|
|
rhcomment = -1;
|
|
|
|
}
|
2020-03-08 20:02:51 +01:00
|
|
|
|
2020-03-09 12:53:21 +01:00
|
|
|
lptr = strstr(line, "/*");
|
|
|
|
if (lptr != NULL)
|
2020-03-08 13:29:47 +01:00
|
|
|
{
|
2020-03-09 12:53:21 +01:00
|
|
|
n = lptr - &line[0];
|
|
|
|
if (line[n + 2] == '\n')
|
2020-03-08 13:29:47 +01:00
|
|
|
{
|
2020-03-09 12:53:21 +01:00
|
|
|
ERROR("C comment opening on separate line", lineno, n);
|
|
|
|
}
|
|
|
|
else if (!isspace((int)line[n + 2]) && line[n + 2] != '*')
|
|
|
|
{
|
|
|
|
ERROR("Missing space after opening C comment", lineno, n);
|
|
|
|
}
|
2020-03-08 13:29:47 +01:00
|
|
|
|
2020-03-09 12:53:21 +01:00
|
|
|
if (strstr(lptr, "*/") == NULL)
|
|
|
|
{
|
|
|
|
/* Increment the count of nested comments */
|
2020-03-08 13:29:47 +01:00
|
|
|
|
2020-03-09 12:53:21 +01:00
|
|
|
ncomment++;
|
|
|
|
}
|
2020-03-08 20:02:51 +01:00
|
|
|
|
2020-03-09 12:53:21 +01:00
|
|
|
if (ppline == PPLINE_DEFINE)
|
|
|
|
{
|
2020-03-08 22:37:39 +01:00
|
|
|
rhcomment = n;
|
2020-03-09 12:53:21 +01:00
|
|
|
if (prevrhcmt > 0 && n != prevrhcmt)
|
2020-03-08 20:02:51 +01:00
|
|
|
{
|
2020-03-08 22:37:39 +01:00
|
|
|
rhcomment = prevrhcmt;
|
|
|
|
WARN("Wrong column position of comment right of code",
|
|
|
|
lineno, n);
|
2020-03-08 13:29:47 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-09 12:53:21 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Signal rhcomment, but ignore position */
|
|
|
|
|
|
|
|
rhcomment = -1;
|
2020-03-09 16:16:06 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
if (ncomment > 0 &&
|
|
|
|
(ppline == PPLINE_IF ||
|
|
|
|
ppline == PPLINE_ELSE ||
|
|
|
|
ppline == PPLINE_ELIF))
|
2020-03-09 16:16:06 +01:00
|
|
|
{
|
2020-03-14 14:36:47 +01:00
|
|
|
/* in #if... and #el... */
|
2020-03-10 12:47:06 +01:00
|
|
|
|
2020-03-09 16:16:06 +01:00
|
|
|
ERROR("No multiline comment right of code allowed here",
|
|
|
|
lineno, n);
|
|
|
|
}
|
2020-03-09 12:53:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line[len] != '\\' || ncomment > 0)
|
|
|
|
{
|
|
|
|
ppline = PPLINE_NONE;
|
2020-03-08 13:29:47 +01:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-11 23:45:39 +02:00
|
|
|
/* Check for a single line comment */
|
|
|
|
|
|
|
|
linelen = strlen(line);
|
2024-07-29 19:59:32 +02:00
|
|
|
|
|
|
|
/* Minimum is slash, star, star, slash, newline */
|
|
|
|
|
|
|
|
if (linelen >= 5)
|
2018-04-11 23:45:39 +02:00
|
|
|
{
|
|
|
|
lptr = strstr(line, "*/");
|
2019-10-25 20:34:42 +02:00
|
|
|
if (line[indent] == '/' && line[indent + 1] == '*' &&
|
2018-04-11 23:45:39 +02:00
|
|
|
lptr - line == linelen - 3)
|
|
|
|
{
|
2019-12-01 18:37:30 +01:00
|
|
|
/* If preceding comments were to the right of code, then we can
|
|
|
|
* assume that there is a columnar alignment of columns that do
|
2020-03-08 20:02:51 +01:00
|
|
|
* no follow the usual alignment. So the rhcomment flag
|
2019-12-01 18:37:30 +01:00
|
|
|
* should propagate.
|
|
|
|
*/
|
|
|
|
|
2020-03-08 20:02:51 +01:00
|
|
|
rhcomment = prevrhcmt;
|
2019-12-01 18:37:30 +01:00
|
|
|
|
2018-10-30 23:33:41 +01:00
|
|
|
/* Check if there should be a blank line before the comment */
|
|
|
|
|
|
|
|
if (lineno > 1 &&
|
|
|
|
comment_lineno != lineno - 1 &&
|
2018-08-24 13:51:44 +02:00
|
|
|
blank_lineno != lineno - 1 &&
|
2019-12-01 18:37:30 +01:00
|
|
|
noblank_lineno != lineno - 1 &&
|
2020-03-08 20:02:51 +01:00
|
|
|
rhcomment == 0)
|
2018-08-21 21:07:29 +02:00
|
|
|
{
|
2020-03-07 14:35:08 +01:00
|
|
|
/* TODO: This generates a false alarm if preceded
|
|
|
|
* by a label.
|
|
|
|
*/
|
2018-08-21 21:32:05 +02:00
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Missing blank line before comment found", lineno, 1);
|
2018-08-21 21:07:29 +02:00
|
|
|
}
|
|
|
|
|
2019-11-09 16:09:33 +01:00
|
|
|
/* 'comment_lineno 'holds the line number of the last closing
|
|
|
|
* comment. It is used only to verify that the comment is
|
|
|
|
* followed by a blank line.
|
|
|
|
*/
|
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
comment_lineno = lineno;
|
2018-04-11 23:45:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
/* Check for the comment block indicating the beginning of a new file
|
|
|
|
* section.
|
|
|
|
*/
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
if (check_section_header(line, lineno))
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2020-01-13 19:08:45 +01:00
|
|
|
if (g_section == PRIVATE_FUNCTIONS || g_section == PUBLIC_FUNCTIONS)
|
|
|
|
{
|
|
|
|
bfunctions = true; /* Latched */
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for some kind of declaration.
|
|
|
|
* REVISIT: The following logic fails for any non-standard types.
|
|
|
|
* REVISIT: Terminator after keyword might not be a space. Might be
|
|
|
|
* a newline, for example. struct and unions are often unnamed, for
|
|
|
|
* example.
|
|
|
|
*/
|
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
else if (inasm == 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2020-03-14 14:36:47 +01:00
|
|
|
if (strncmp(&line[indent], "auto ", 5) == 0 ||
|
|
|
|
strncmp(&line[indent], "bool ", 5) == 0 ||
|
|
|
|
strncmp(&line[indent], "char ", 5) == 0 ||
|
|
|
|
strncmp(&line[indent], "CODE ", 5) == 0 ||
|
|
|
|
strncmp(&line[indent], "const ", 6) == 0 ||
|
|
|
|
strncmp(&line[indent], "double ", 7) == 0 ||
|
|
|
|
strncmp(&line[indent], "struct ", 7) == 0 ||
|
|
|
|
strncmp(&line[indent], "struct\n", 7) == 0 || /* May be unnamed */
|
|
|
|
strncmp(&line[indent], "enum ", 5) == 0 ||
|
|
|
|
strncmp(&line[indent], "extern ", 7) == 0 ||
|
|
|
|
strncmp(&line[indent], "EXTERN ", 7) == 0 ||
|
|
|
|
strncmp(&line[indent], "FAR ", 4) == 0 ||
|
|
|
|
strncmp(&line[indent], "float ", 6) == 0 ||
|
|
|
|
strncmp(&line[indent], "int ", 4) == 0 ||
|
|
|
|
strncmp(&line[indent], "int16_t ", 8) == 0 ||
|
|
|
|
strncmp(&line[indent], "int32_t ", 8) == 0 ||
|
|
|
|
strncmp(&line[indent], "long ", 5) == 0 ||
|
|
|
|
strncmp(&line[indent], "off_t ", 6) == 0 ||
|
|
|
|
strncmp(&line[indent], "register ", 9) == 0 ||
|
|
|
|
strncmp(&line[indent], "short ", 6) == 0 ||
|
|
|
|
strncmp(&line[indent], "signed ", 7) == 0 ||
|
|
|
|
strncmp(&line[indent], "size_t ", 7) == 0 ||
|
|
|
|
strncmp(&line[indent], "ssize_t ", 8) == 0 ||
|
|
|
|
strncmp(&line[indent], "static ", 7) == 0 ||
|
|
|
|
strncmp(&line[indent], "time_t ", 7) == 0 ||
|
|
|
|
strncmp(&line[indent], "typedef ", 8) == 0 ||
|
|
|
|
strncmp(&line[indent], "uint8_t ", 8) == 0 ||
|
|
|
|
strncmp(&line[indent], "uint16_t ", 9) == 0 ||
|
|
|
|
strncmp(&line[indent], "uint32_t ", 9) == 0 ||
|
|
|
|
strncmp(&line[indent], "union ", 6) == 0 ||
|
|
|
|
strncmp(&line[indent], "union\n", 6) == 0 || /* May be unnamed */
|
|
|
|
strncmp(&line[indent], "unsigned ", 9) == 0 ||
|
|
|
|
strncmp(&line[indent], "void ", 5) == 0 ||
|
|
|
|
strncmp(&line[indent], "volatile ", 9) == 0)
|
2019-06-30 23:10:14 +02:00
|
|
|
{
|
2020-03-14 14:36:47 +01:00
|
|
|
/* Check if this is extern "C"; We don't typically indent
|
|
|
|
* following this.
|
|
|
|
*/
|
2019-06-30 23:10:14 +02:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
if (strncmp(&line[indent], "extern \"C\"", 10) == 0)
|
|
|
|
{
|
|
|
|
externc_lineno = lineno;
|
|
|
|
}
|
2019-06-30 18:35:10 +02:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
/* bfunctions: True: Processing private or public functions.
|
|
|
|
* bnest: Brace nesting level on this line
|
|
|
|
* dnest: Data declaration nesting level on this line
|
|
|
|
*/
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
/* REVISIT: Also picks up function return types */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
/* REVISIT: Logic problem for nested data/function declarations */
|
2019-02-15 01:33:23 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
if ((!bfunctions || bnest > 0) && dnest == 0)
|
|
|
|
{
|
|
|
|
dnest = 1;
|
|
|
|
}
|
2019-02-17 17:57:28 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
/* Check for multiple definitions of variables on the line.
|
|
|
|
* Ignores declarations within parentheses which are probably
|
|
|
|
* formal parameters.
|
2019-02-17 17:57:28 +01:00
|
|
|
*/
|
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
if (pnest == 0)
|
2019-02-17 17:57:28 +01:00
|
|
|
{
|
2020-03-14 14:36:47 +01:00
|
|
|
int tmppnest;
|
2024-01-26 08:06:23 +01:00
|
|
|
bool tmpbstring;
|
2020-03-14 14:36:47 +01:00
|
|
|
|
|
|
|
/* Note, we have not yet parsed each character on the line so
|
|
|
|
* a comma have have been be preceded by '(' on the same line.
|
|
|
|
* We will have parse up to any comma to see if that is the
|
|
|
|
* case.
|
|
|
|
*/
|
|
|
|
|
2024-01-26 08:06:23 +01:00
|
|
|
for (i = indent, tmppnest = 0, tmpbstring = false;
|
2020-03-14 14:36:47 +01:00
|
|
|
line[i] != '\n' && line[i] != '\0';
|
|
|
|
i++)
|
2019-02-17 17:57:28 +01:00
|
|
|
{
|
2024-01-26 08:06:23 +01:00
|
|
|
if (tmppnest == 0 && !tmpbstring && line[i] == ',')
|
2019-02-17 17:57:28 +01:00
|
|
|
{
|
2020-03-14 14:36:47 +01:00
|
|
|
ERROR("Multiple data definitions", lineno, i + 1);
|
2019-02-17 17:57:28 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-03-14 14:36:47 +01:00
|
|
|
else if (line[i] == '(')
|
|
|
|
{
|
|
|
|
tmppnest++;
|
|
|
|
}
|
|
|
|
else if (line[i] == ')')
|
|
|
|
{
|
|
|
|
if (tmppnest < 1)
|
|
|
|
{
|
|
|
|
/* We should catch this later */
|
2019-02-17 17:57:28 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmppnest--;
|
|
|
|
}
|
2024-01-26 08:06:23 +01:00
|
|
|
else if (line[i] == '"')
|
|
|
|
{
|
|
|
|
tmpbstring = !tmpbstring;
|
|
|
|
}
|
2020-03-14 14:36:47 +01:00
|
|
|
else if (line[i] == ';')
|
|
|
|
{
|
|
|
|
/* Break out if the semicolon terminates the
|
|
|
|
* declaration is found. Avoids processing any
|
|
|
|
* righthand comments in most cases.
|
|
|
|
*/
|
2019-02-17 17:57:28 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-02-17 17:57:28 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-15 01:33:23 +01:00
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
/* Check for a keyword indicating the beginning of a statement.
|
|
|
|
* REVISIT: This, obviously, will not detect statements that do not
|
|
|
|
* begin with a C keyword (such as assignment statements).
|
|
|
|
*/
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
else if (strncmp(&line[indent], "break ", 6) == 0 ||
|
|
|
|
strncmp(&line[indent], "case ", 5) == 0 ||
|
|
|
|
#if 0 /* Part of switch */
|
|
|
|
strncmp(&line[indent], "case ", 5) == 0 ||
|
|
|
|
#endif
|
|
|
|
strncmp(&line[indent], "continue ", 9) == 0 ||
|
|
|
|
|
|
|
|
#if 0 /* Part of switch */
|
|
|
|
strncmp(&line[indent], "default ", 8) == 0 ||
|
|
|
|
#endif
|
|
|
|
strncmp(&line[indent], "do ", 3) == 0 ||
|
|
|
|
strncmp(&line[indent], "else ", 5) == 0 ||
|
|
|
|
strncmp(&line[indent], "goto ", 5) == 0 ||
|
|
|
|
strncmp(&line[indent], "return ", 7) == 0 ||
|
2023-12-14 15:22:07 +01:00
|
|
|
#if 0 /* Doesn't follow pattern */
|
2020-03-14 14:36:47 +01:00
|
|
|
strncmp(&line[indent], "switch ", 7) == 0 ||
|
|
|
|
#endif
|
|
|
|
strncmp(&line[indent], "while ", 6) == 0)
|
|
|
|
{
|
|
|
|
bstatm = true;
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2024-07-29 19:59:32 +02:00
|
|
|
else if(strncmp(&line[indent], "if ", 3) == 0)
|
|
|
|
{
|
|
|
|
bif = true;
|
|
|
|
bstatm = true;
|
|
|
|
}
|
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
/* Spacing works a little differently for and switch statements */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
else if (strncmp(&line[indent], "for ", 4) == 0)
|
|
|
|
{
|
|
|
|
bfor = true;
|
|
|
|
bstatm = true;
|
|
|
|
}
|
|
|
|
else if (strncmp(&line[indent], "switch ", 7) == 0)
|
|
|
|
{
|
|
|
|
bswitch = true;
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
/* Also check for C keywords with missing white space */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
else if (strncmp(&line[indent], "do(", 3) == 0 ||
|
|
|
|
strncmp(&line[indent], "while(", 6) == 0)
|
|
|
|
{
|
|
|
|
ERROR("Missing whitespace after keyword", lineno, n);
|
|
|
|
bstatm = true;
|
|
|
|
}
|
2024-07-29 19:59:32 +02:00
|
|
|
else if (strncmp(&line[indent], "if(", 3) == 0)
|
|
|
|
{
|
|
|
|
ERROR("Missing whitespace after keyword", lineno, n);
|
|
|
|
bif = true;
|
|
|
|
bstatm = true;
|
|
|
|
}
|
2020-03-14 14:36:47 +01:00
|
|
|
else if (strncmp(&line[indent], "for(", 4) == 0)
|
|
|
|
{
|
|
|
|
ERROR("Missing whitespace after keyword", lineno, n);
|
|
|
|
bfor = true;
|
|
|
|
bstatm = true;
|
|
|
|
}
|
|
|
|
else if (strncmp(&line[indent], "switch(", 7) == 0)
|
|
|
|
{
|
|
|
|
ERROR("Missing whitespace after keyword", lineno, n);
|
|
|
|
bswitch = true;
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* STEP 3: Parse each character on the line */
|
|
|
|
|
2019-02-08 14:49:19 +01:00
|
|
|
bquote = false; /* True: Backslash quoted character next */
|
2019-06-30 00:19:10 +02:00
|
|
|
bblank = true; /* Used to verify block comment terminator */
|
2019-02-08 14:49:19 +01:00
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
for (; line[n] != '\n' && line[n] != '\0'; n++)
|
|
|
|
{
|
2019-10-23 20:49:27 +02:00
|
|
|
/* Report any use of non-standard white space characters */
|
|
|
|
|
|
|
|
if (isspace(line[n]))
|
|
|
|
{
|
|
|
|
if (line[n] == '\t')
|
|
|
|
{
|
|
|
|
if (!btabs)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("TABs found. First detected", lineno, n);
|
2019-10-23 20:49:27 +02:00
|
|
|
btabs = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (line[n] == '\r')
|
|
|
|
{
|
|
|
|
if (!bcrs)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Carriage returns found. "
|
|
|
|
"First detected", lineno, n);
|
2019-10-23 20:49:27 +02:00
|
|
|
bcrs = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (line[n] != ' ')
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"Unexpected white space character %02x found",
|
|
|
|
line[n]);
|
|
|
|
ERROR(buffer, lineno, n);
|
2019-10-23 20:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 00:19:10 +02:00
|
|
|
/* Skip over identifiers */
|
2019-03-05 20:08:57 +01:00
|
|
|
|
|
|
|
if (ncomment == 0 && !bstring && (line[n] == '_' || isalpha(line[n])))
|
|
|
|
{
|
|
|
|
bool have_upper = false;
|
|
|
|
bool have_lower = false;
|
|
|
|
int ident_index = n;
|
|
|
|
|
|
|
|
/* Parse over the identifier. Check if it contains mixed upper-
|
|
|
|
* and lower-case characters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
have_upper |= isupper(line[n]);
|
2019-03-12 21:22:52 +01:00
|
|
|
|
|
|
|
/* The coding standard provides for some exceptions of lower
|
|
|
|
* case characters in pre-processor strings:
|
|
|
|
*
|
|
|
|
* IPv[4|6] as an IP version number
|
|
|
|
* ICMPv6 as an ICMP version number
|
|
|
|
* IGMPv2 as an IGMP version number
|
|
|
|
* [0-9]p[0-9] as a decimal point
|
|
|
|
* d[0-9] as a divisor
|
2020-05-19 01:28:40 +02:00
|
|
|
* Hz for frequencies (including KHz, MHz, etc.)
|
2019-03-12 21:22:52 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!have_lower && islower(line[n]))
|
|
|
|
{
|
|
|
|
switch (line[n])
|
|
|
|
{
|
2019-03-13 14:05:31 +01:00
|
|
|
/* A sequence containing 'v' may occur at the
|
2019-03-12 21:48:43 +01:00
|
|
|
* beginning of the identifier.
|
|
|
|
*/
|
|
|
|
|
2019-03-12 21:22:52 +01:00
|
|
|
case 'v':
|
|
|
|
if (n > 1 &&
|
|
|
|
line[n - 2] == 'I' &&
|
|
|
|
line[n - 1] == 'P' &&
|
|
|
|
(line[n + 1] == '4' ||
|
|
|
|
line[n + 1] == '6'))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if (n > 3 &&
|
|
|
|
line[n - 4] == 'I' &&
|
|
|
|
line[n - 3] == 'C' &&
|
|
|
|
line[n - 2] == 'M' &&
|
|
|
|
line[n - 1] == 'P' &&
|
|
|
|
line[n + 1] == '6')
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if (n > 3 &&
|
|
|
|
line[n - 4] == 'I' &&
|
|
|
|
line[n - 3] == 'G' &&
|
|
|
|
line[n - 2] == 'M' &&
|
|
|
|
line[n - 1] == 'P' &&
|
|
|
|
line[n + 1] == '2')
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
have_lower = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-04-02 20:57:08 +02:00
|
|
|
/* Sequences containing 'p', 'd', or 'z' must have
|
|
|
|
* been preceded by upper case characters.
|
2019-03-12 21:48:43 +01:00
|
|
|
*/
|
|
|
|
|
2019-03-12 21:22:52 +01:00
|
|
|
case 'p':
|
2019-03-12 21:48:43 +01:00
|
|
|
if (!have_upper || n < 1 ||
|
2019-03-13 14:05:31 +01:00
|
|
|
!isdigit(line[n - 1]) ||
|
|
|
|
!isdigit(line[n + 1]))
|
2019-03-12 21:22:52 +01:00
|
|
|
{
|
|
|
|
have_lower = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
2019-03-12 21:48:43 +01:00
|
|
|
if (!have_upper || !isdigit(line[n + 1]))
|
2019-03-12 21:22:52 +01:00
|
|
|
{
|
|
|
|
have_lower = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-04-02 20:57:08 +02:00
|
|
|
case 'z':
|
2020-05-19 01:28:40 +02:00
|
|
|
if (!have_upper || n < 1 ||
|
|
|
|
line[n - 1] != 'H')
|
2020-04-02 20:57:08 +02:00
|
|
|
{
|
|
|
|
have_lower = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
2019-03-12 21:22:52 +01:00
|
|
|
default:
|
|
|
|
have_lower = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:08:57 +01:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
while (line[n] == '_' || isalnum(line[n]));
|
|
|
|
|
2019-03-09 16:21:12 +01:00
|
|
|
/* Check for mixed upper and lower case */
|
|
|
|
|
2019-03-05 20:08:57 +01:00
|
|
|
if (have_upper && have_lower)
|
|
|
|
{
|
2020-03-31 19:43:28 +02:00
|
|
|
/* Ignore symbols that begin with white-listed prefixes */
|
2020-03-06 03:15:04 +01:00
|
|
|
|
2023-04-11 07:27:14 +02:00
|
|
|
if (g_skipmixedcase ||
|
2023-04-26 11:27:43 +02:00
|
|
|
white_content_list(&line[ident_index], lineno))
|
2020-03-06 03:15:04 +01:00
|
|
|
{
|
|
|
|
/* No error */
|
|
|
|
}
|
|
|
|
|
2019-03-09 16:21:12 +01:00
|
|
|
/* Special case hex constants. These will look like
|
|
|
|
* identifiers starting with 'x' or 'X' but preceded
|
|
|
|
* with '0'
|
|
|
|
*/
|
|
|
|
|
2020-02-03 17:13:18 +01:00
|
|
|
else if (ident_index < 1 ||
|
|
|
|
(line[ident_index] != 'x' &&
|
|
|
|
line[ident_index] != 'X') ||
|
|
|
|
line[ident_index - 1] != '0')
|
2019-03-09 16:21:12 +01:00
|
|
|
{
|
2020-02-03 17:13:18 +01:00
|
|
|
ERROR("Mixed case identifier found",
|
|
|
|
lineno, ident_index);
|
2019-03-09 16:21:12 +01:00
|
|
|
}
|
|
|
|
else if (have_upper)
|
|
|
|
{
|
2020-02-03 17:13:18 +01:00
|
|
|
ERROR("Upper case hex constant found",
|
|
|
|
lineno, ident_index);
|
2019-03-09 16:21:12 +01:00
|
|
|
}
|
2019-03-05 20:08:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the identifier is the last thing on the line */
|
|
|
|
|
|
|
|
if (line[n] == '\n' || line[n] == '\0')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle comments */
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
if (line[n] == '/' && !bstring)
|
|
|
|
{
|
|
|
|
/* Check for start of a C comment */
|
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
if (line[n + 1] == '*')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2018-08-24 13:51:44 +02:00
|
|
|
if (line[n + 2] == '\n')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("C comment opening on separate line", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
2019-10-23 20:49:27 +02:00
|
|
|
else if (!isspace((int)line[n + 2]) && line[n + 2] != '*')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Missing space after opening C comment", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
2019-12-01 18:37:30 +01:00
|
|
|
/* Increment the count of nested comments */
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
ncomment++;
|
2019-12-01 18:37:30 +01:00
|
|
|
|
|
|
|
/* If there is anything to the left of the left brace, then
|
|
|
|
* this must be a comment to the right of code.
|
|
|
|
* Also if preceding comments were to the right of code, then
|
|
|
|
* we can assume that there is a columnar alignment of columns
|
2020-03-08 20:02:51 +01:00
|
|
|
* that do no follow the usual alignment. So the rhcomment
|
2019-12-01 18:37:30 +01:00
|
|
|
* flag should propagate.
|
|
|
|
*/
|
|
|
|
|
2020-03-08 20:02:51 +01:00
|
|
|
if (prevrhcmt == 0)
|
|
|
|
{
|
|
|
|
if (n != indent)
|
|
|
|
{
|
|
|
|
rhcomment = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rhcomment = n;
|
2020-03-09 12:53:21 +01:00
|
|
|
if (prevrhcmt > 0 && n != prevrhcmt)
|
2020-03-08 20:02:51 +01:00
|
|
|
{
|
|
|
|
rhcomment = prevrhcmt;
|
2020-03-10 12:47:06 +01:00
|
|
|
if (n != indent)
|
|
|
|
{
|
|
|
|
WARN("Wrong column position of "
|
|
|
|
"comment right of code", lineno, n);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERROR("Wrong column position or missing "
|
|
|
|
"blank line before comment", lineno, n);
|
|
|
|
}
|
2020-03-08 20:02:51 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-01 18:37:30 +01:00
|
|
|
|
2024-08-26 15:00:01 +02:00
|
|
|
/* Allow comments on the same line as the if statement */
|
|
|
|
|
|
|
|
if (bif == true)
|
|
|
|
{
|
|
|
|
bif = false;
|
|
|
|
}
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
n++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for end of a C comment */
|
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
else if (n > 0 && line[n - 1] == '*')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
|
|
|
if (n < 2)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Closing C comment not indented", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
2020-03-11 18:08:01 +01:00
|
|
|
else if (!isspace((int)line[n - 2]) && line[n - 2] != '*')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Missing space before closing C comment", lineno,
|
|
|
|
n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 14:49:19 +01:00
|
|
|
/* Check for block comments that are not on a separate line.
|
|
|
|
* This would be the case if we are we are within a comment
|
|
|
|
* that did not start on this line and the current line is
|
|
|
|
* not blank up to the point where the comment was closed.
|
|
|
|
*/
|
|
|
|
|
2020-03-08 20:02:51 +01:00
|
|
|
if (prevncomment > 0 && !bblank && rhcomment == 0)
|
2019-02-08 14:49:19 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Block comment terminator must be on a "
|
|
|
|
"separate line", lineno, n);
|
2019-02-08 14:49:19 +01:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
#if 0
|
|
|
|
/* REVISIT: Generates false alarms when portions of an
|
|
|
|
* expression are commented out within the expression.
|
|
|
|
*/
|
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
if (line[n + 1] != '\n')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Garbage on line after C comment", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-30 23:33:41 +01:00
|
|
|
/* Handle nested comments */
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
if (ncomment > 0)
|
|
|
|
{
|
2018-10-30 23:33:41 +01:00
|
|
|
/* Remember the line number of the line containing the
|
|
|
|
* closing of the outermost comment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (--ncomment == 0)
|
|
|
|
{
|
2019-11-09 15:15:12 +01:00
|
|
|
/* 'comment_lineno 'holds the line number of the
|
|
|
|
* last closing comment. It is used only to
|
|
|
|
* verify that the comment is followed by a blank
|
2019-12-01 18:37:30 +01:00
|
|
|
* line.
|
2018-10-31 19:42:18 +01:00
|
|
|
*/
|
|
|
|
|
2019-12-01 18:37:30 +01:00
|
|
|
comment_lineno = lineno;
|
2019-11-09 15:15:12 +01:00
|
|
|
|
2020-03-08 20:02:51 +01:00
|
|
|
/* Note that rhcomment must persist to support a
|
2019-11-09 15:15:12 +01:00
|
|
|
* later test for comment alignment. We will fix
|
|
|
|
* that at the top of the loop when ncomment == 0.
|
2019-10-27 18:45:33 +01:00
|
|
|
*/
|
2018-10-30 23:33:41 +01:00
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-08 20:02:51 +01:00
|
|
|
/* Note that rhcomment must persist to support a later
|
2019-10-27 18:45:33 +01:00
|
|
|
* test for comment alignment. We will will fix that
|
|
|
|
* at the top of the loop when ncomment == 0.
|
|
|
|
*/
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
ncomment = 0;
|
2021-12-26 23:18:22 +01:00
|
|
|
ERROR("Closing without opening comment", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
2018-10-30 23:33:41 +01:00
|
|
|
|
|
|
|
n++;
|
|
|
|
continue;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
2019-10-27 18:45:33 +01:00
|
|
|
/* Check for C++ style comments */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
else if (line[n + 1] == '/')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2021-05-07 19:10:28 +02:00
|
|
|
/* Check for URI schemes, e.g. "http://" or "https://" */
|
2019-10-27 18:45:33 +01:00
|
|
|
|
2021-12-26 23:18:22 +01:00
|
|
|
if ((ncomment == 0) &&
|
|
|
|
(n == 0 || strncmp(&line[n - 1], "://", 3) != 0))
|
2019-10-27 18:45:33 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("C++ style comment", lineno, n);
|
2019-10-27 18:45:33 +01:00
|
|
|
n++;
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:49:19 +01:00
|
|
|
/* Check if the line is blank so far. This is only used to
|
|
|
|
* to verify the the closing of a block comment is on a separate
|
|
|
|
* line. So we also need to treat '*' as a 'blank'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!isblank(line[n]) && line[n] != '*')
|
|
|
|
{
|
|
|
|
bblank = false;
|
|
|
|
}
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
/* Check for a string... ignore if we are in the middle of a
|
|
|
|
* comment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ncomment == 0)
|
|
|
|
{
|
2019-06-30 00:19:10 +02:00
|
|
|
/* Backslash quoted character */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
|
|
|
if (line[n] == '\\')
|
|
|
|
{
|
|
|
|
bquote = true;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2019-06-30 00:19:10 +02:00
|
|
|
/* Check for quoted characters: \" in string */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
|
|
|
if (line[n] == '"' && !bquote)
|
|
|
|
{
|
|
|
|
bstring = !bstring;
|
|
|
|
}
|
|
|
|
|
|
|
|
bquote = false;
|
|
|
|
}
|
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
/* The rest of the line is only examined of we are not in a comment,
|
|
|
|
* in a string or in assembly.
|
2015-10-08 20:48:40 +02:00
|
|
|
*
|
|
|
|
* REVISIT: Should still check for whitespace at the end of the
|
|
|
|
* line.
|
|
|
|
*/
|
|
|
|
|
2020-03-14 14:36:47 +01:00
|
|
|
if (ncomment == 0 && !bstring && inasm == 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
|
|
|
switch (line[n])
|
|
|
|
{
|
|
|
|
/* Handle logic nested with curly braces */
|
|
|
|
|
|
|
|
case '{':
|
|
|
|
{
|
|
|
|
if (n > indent)
|
|
|
|
{
|
2020-04-06 20:02:29 +02:00
|
|
|
/* REVISIT: dnest is always > 0 here if bfunctions ==
|
|
|
|
* false.
|
|
|
|
*/
|
2019-06-30 00:19:10 +02:00
|
|
|
|
2020-03-12 21:11:12 +01:00
|
|
|
if (dnest == 0 || !bfunctions || lineno == rbrace_lineno)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Left bracket not on separate line", lineno,
|
|
|
|
n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-24 13:51:44 +02:00
|
|
|
else if (line[n + 1] != '\n')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
if (dnest == 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Garbage follows left bracket", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 17:57:28 +01:00
|
|
|
bnest++;
|
|
|
|
if (dnest > 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
dnest++;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
2018-08-21 21:07:29 +02:00
|
|
|
|
2019-06-30 23:10:14 +02:00
|
|
|
/* Check if we are within 'extern "C"', we don't
|
|
|
|
* normally indent in that case because the 'extern "C"'
|
|
|
|
* is conditioned on __cplusplus.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (lineno == externc_lineno ||
|
|
|
|
lineno - 1 == externc_lineno)
|
|
|
|
{
|
|
|
|
bexternc = true;
|
|
|
|
}
|
|
|
|
|
2018-08-21 21:07:29 +02:00
|
|
|
/* Suppress error for comment following a left brace */
|
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
noblank_lineno = lineno;
|
2019-03-10 16:53:33 +01:00
|
|
|
lbrace_lineno = lineno;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '}':
|
|
|
|
{
|
2019-03-10 16:53:33 +01:00
|
|
|
/* Decrement the brace nesting level */
|
|
|
|
|
2019-02-17 17:57:28 +01:00
|
|
|
if (bnest < 1)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Unmatched right brace", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
bnest--;
|
|
|
|
if (bnest < 1)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
bnest = 0;
|
2015-10-08 20:48:40 +02:00
|
|
|
bswitch = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-10 16:53:33 +01:00
|
|
|
/* Decrement the declaration nesting level */
|
|
|
|
|
2019-02-17 17:57:28 +01:00
|
|
|
if (dnest < 3)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
dnest = 0;
|
2019-06-30 23:10:14 +02:00
|
|
|
bexternc = false;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
dnest--;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
2019-03-10 16:53:33 +01:00
|
|
|
/* The right brace should be on a separate line */
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
if (n > indent)
|
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
if (dnest == 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Right bracket not on separate line",
|
2015-10-08 20:48:40 +02:00
|
|
|
lineno, n);
|
|
|
|
}
|
|
|
|
}
|
2019-03-10 16:53:33 +01:00
|
|
|
|
|
|
|
/* Check for garbage following the left brace */
|
|
|
|
|
|
|
|
if (line[n + 1] != '\n' &&
|
|
|
|
line[n + 1] != ',' &&
|
|
|
|
line[n + 1] != ';')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-11-19 18:32:57 +01:00
|
|
|
int sndx = n + 1;
|
2019-11-19 18:43:20 +01:00
|
|
|
bool whitespace = false;
|
2019-11-19 18:32:57 +01:00
|
|
|
|
|
|
|
/* Skip over spaces */
|
|
|
|
|
|
|
|
while (line[sndx] == ' ')
|
|
|
|
{
|
|
|
|
sndx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* One possibility is that the right bracket is
|
|
|
|
* followed by an identifier then a semi-colon.
|
|
|
|
* Comma is possible to but would be a case of
|
|
|
|
* multiple declaration of multiple instances.
|
2015-10-08 20:48:40 +02:00
|
|
|
*/
|
|
|
|
|
2019-11-19 18:32:57 +01:00
|
|
|
if (line[sndx] == '_' || isalpha(line[sndx]))
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-11-19 18:32:57 +01:00
|
|
|
int endx = sndx;
|
|
|
|
|
|
|
|
/* Skip to the end of the identifier. Checking
|
|
|
|
* for mixed case identifiers will be done
|
|
|
|
* elsewhere.
|
2018-10-30 01:00:30 +01:00
|
|
|
*/
|
|
|
|
|
2019-11-19 18:32:57 +01:00
|
|
|
while (line[endx] == '_' ||
|
|
|
|
isalnum(line[endx]))
|
|
|
|
{
|
|
|
|
endx++;
|
|
|
|
}
|
|
|
|
|
2019-11-19 18:43:20 +01:00
|
|
|
/* Skip over spaces */
|
|
|
|
|
|
|
|
while (line[endx] == ' ')
|
|
|
|
{
|
|
|
|
whitespace = true;
|
|
|
|
endx++;
|
|
|
|
}
|
|
|
|
|
2019-11-19 18:32:57 +01:00
|
|
|
/* Handle according to what comes after the
|
|
|
|
* identifier.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (strncmp(&line[sndx], "while", 5) == 0)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("'while' must be on a separate line",
|
2019-11-19 18:32:57 +01:00
|
|
|
lineno, sndx);
|
|
|
|
}
|
|
|
|
else if (line[endx] == ',')
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Multiple data definitions on line",
|
2019-11-19 18:32:57 +01:00
|
|
|
lineno, endx);
|
|
|
|
}
|
2019-11-19 18:43:20 +01:00
|
|
|
else if (line[endx] == ';')
|
|
|
|
{
|
|
|
|
if (whitespace)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Space precedes semi-colon",
|
|
|
|
lineno, endx);
|
2019-11-19 18:43:20 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-12 21:11:12 +01:00
|
|
|
else if (line[endx] == '=')
|
|
|
|
{
|
|
|
|
/* There's a struct initialization following */
|
|
|
|
|
|
|
|
check_spaces_leftright(line, lineno, endx, endx);
|
|
|
|
dnest = 1;
|
|
|
|
}
|
2019-11-19 18:43:20 +01:00
|
|
|
else
|
2019-11-19 18:32:57 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Garbage follows right bracket",
|
|
|
|
lineno, n);
|
2019-11-19 18:32:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Garbage follows right bracket", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-10 16:53:33 +01:00
|
|
|
|
2020-04-06 20:02:29 +02:00
|
|
|
/* The right brace should not be preceded with a a blank
|
|
|
|
* line.
|
|
|
|
*/
|
2019-03-10 16:53:33 +01:00
|
|
|
|
|
|
|
if (lineno == blank_lineno + 1)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Blank line precedes right brace at line",
|
|
|
|
lineno, 1);
|
2019-03-10 16:53:33 +01:00
|
|
|
}
|
2019-10-24 18:49:28 +02:00
|
|
|
|
|
|
|
rbrace_lineno = lineno;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-10-23 20:49:27 +02:00
|
|
|
/* Handle logic with parentheses */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
|
|
|
case '(':
|
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
/* Increase the parenthetical nesting level */
|
|
|
|
|
|
|
|
pnest++;
|
|
|
|
|
|
|
|
/* Check for inappropriate space around parentheses */
|
|
|
|
|
2024-07-29 19:59:32 +02:00
|
|
|
if (line[n + 1] == ' ')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Space follows left parenthesis", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ')':
|
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
/* Decrease the parenthetical nesting level */
|
|
|
|
|
|
|
|
if (pnest < 1)
|
2024-07-29 19:59:32 +02:00
|
|
|
{
|
|
|
|
ERROR("Unmatched right parentheses", lineno, n);
|
|
|
|
pnest = 0;
|
|
|
|
}
|
|
|
|
else
|
2019-02-17 17:57:28 +01:00
|
|
|
{
|
|
|
|
pnest--;
|
|
|
|
}
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
/* Allow ')' as first thing on the line (n == indent)
|
|
|
|
* Allow "for (xx; xx; )" (bfor == true)
|
|
|
|
*/
|
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
if (n > 0 && n != indent && line[n - 1] == ' ' && !bfor)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2024-07-29 19:59:32 +02:00
|
|
|
ERROR("Space precedes right parenthesis", lineno, n);
|
|
|
|
}
|
|
|
|
|
2024-08-26 15:00:01 +02:00
|
|
|
/* Unset bif if last parenthesis is closed */
|
|
|
|
|
|
|
|
if (bif == true && pnest == 0)
|
2024-07-29 19:59:32 +02:00
|
|
|
{
|
2024-08-26 15:00:01 +02:00
|
|
|
bif = false;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Check for inappropriate space around square brackets */
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
{
|
2018-08-24 13:51:44 +02:00
|
|
|
if (line[n + 1] == ' ')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Space follows left bracket", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ']':
|
|
|
|
{
|
2018-08-24 13:51:44 +02:00
|
|
|
if (n > 0 && line[n - 1] == ' ')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Space precedes right bracket", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Semi-colon may terminate a declaration */
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
{
|
2018-08-24 13:51:44 +02:00
|
|
|
if (!isspace((int)line[n + 1]))
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Missing whitespace after semicolon", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Semicolon terminates a declaration/definition if there
|
2019-02-17 17:57:28 +01:00
|
|
|
* was no left curly brace (i.e., dnest is only 1).
|
2015-10-08 20:48:40 +02:00
|
|
|
*/
|
|
|
|
|
2019-02-17 17:57:28 +01:00
|
|
|
if (dnest == 1)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
dnest = 0;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Semi-colon may terminate a declaration */
|
|
|
|
|
|
|
|
case ',':
|
|
|
|
{
|
2018-08-24 13:51:44 +02:00
|
|
|
if (!isspace((int)line[n + 1]))
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Missing whitespace after comma", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Skip over character constants */
|
|
|
|
|
|
|
|
case '\'':
|
|
|
|
{
|
|
|
|
int endndx = n + 2;
|
|
|
|
|
2018-08-24 13:51:44 +02:00
|
|
|
if (line[n + 1] != '\n' && line[n + 1] != '\0')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2018-08-24 13:51:44 +02:00
|
|
|
if (line[n + 1] == '\\')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
|
|
|
for (;
|
|
|
|
line[endndx] != '\n' &&
|
|
|
|
line[endndx] != '\0' &&
|
|
|
|
line[endndx] != '\'';
|
|
|
|
endndx++);
|
|
|
|
}
|
|
|
|
|
fix: nxstyle: fix a bug after "'\'"
When nxstyle.c detects a "\'", it seeks the other "\'", records the index as "endndx", then skip the "'x'". But it makes the index "n" as "endndx+1".Then it comes to the "n++" in "for()". So the character after "'x'" will be skipped, causing some errors.
For example, "{"devid", no_argument, NULL, 'i'},", the "}" will be skipped, causing a lot of error reports.
Now it's fixed.
Signed-off-by: liucheng5 <liucheng5@xiaomi.com>
2021-10-26 14:35:29 +02:00
|
|
|
n = endndx;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Check for space around various operators */
|
|
|
|
|
|
|
|
case '-':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2021-09-10 11:44:41 +02:00
|
|
|
/* -> */
|
|
|
|
|
|
|
|
if (line[n + 1] == '>')
|
|
|
|
{
|
|
|
|
/* -> must have no whitespaces on its left or right */
|
|
|
|
|
|
|
|
check_nospaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -- */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2021-09-10 11:44:41 +02:00
|
|
|
else if (line[n + 1] == '-')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2021-09-10 11:44:41 +02:00
|
|
|
/* "--" should be next to its operand. If there are
|
|
|
|
* whitespaces or non-operand characters on both left
|
2023-09-18 10:31:07 +02:00
|
|
|
* and right (e.g. "a -- ", "a[i --]", "(-- i)"),
|
2021-09-10 11:44:41 +02:00
|
|
|
* there's an error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
check_operand_leftright(line, lineno, n, n + 1);
|
2015-10-08 20:48:40 +02:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* -= */
|
|
|
|
|
|
|
|
else if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
2020-04-03 08:56:19 +02:00
|
|
|
|
|
|
|
/* Scientific notation with a negative exponent (eg. 10e-10)
|
|
|
|
* REVISIT: This fails for cases where the variable name
|
|
|
|
* ends with 'e' preceded by a digit:
|
|
|
|
* a = abc1e-10;
|
|
|
|
* a = ABC1E-10;
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if ((line[n - 1] == 'e' || line[n - 1] == 'E') &&
|
|
|
|
isdigit(line[n + 1]) && isdigit(line[n - 2]))
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
}
|
2019-03-01 17:50:02 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* '-' may function as a unary operator and snuggle
|
|
|
|
* on the left.
|
|
|
|
*/
|
|
|
|
|
|
|
|
check_spaces_left(line, lineno, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
case '+':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* ++ */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
if (line[n + 1] == '+')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2021-09-10 11:44:41 +02:00
|
|
|
/* "++" should be next to its operand. If there are
|
|
|
|
* whitespaces or non-operand characters on both left
|
2023-09-18 10:31:07 +02:00
|
|
|
* and right (e.g. "a ++ ", "a[i ++]", "(++ i)"),
|
2021-09-10 11:44:41 +02:00
|
|
|
* there's an error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
check_operand_leftright(line, lineno, n, n + 1);
|
2015-10-08 20:48:40 +02:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* += */
|
|
|
|
|
|
|
|
else if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* '+' may function as a unary operator and snuggle
|
|
|
|
* on the left.
|
|
|
|
*/
|
|
|
|
|
|
|
|
check_spaces_left(line, lineno, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
case '&':
|
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* &<variable> OR &(<expression>) */
|
|
|
|
|
|
|
|
if (isalpha((int)line[n + 1]) || line[n + 1] == '_' ||
|
|
|
|
line[n + 1] == '(')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-03-01 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* &&, &= */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
else if (line[n + 1] == '=' || line[n + 1] == '&')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
2015-10-08 20:48:40 +02:00
|
|
|
n++;
|
2019-03-01 17:50:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n);
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '/':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2020-03-11 18:08:01 +01:00
|
|
|
/* C comment terminator */
|
2019-03-01 17:50:02 +01:00
|
|
|
|
2019-03-11 19:48:17 +01:00
|
|
|
if (line[n - 1] == '*')
|
2019-03-01 17:50:02 +01:00
|
|
|
{
|
2019-03-11 19:48:17 +01:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* C++-style comment */
|
|
|
|
|
|
|
|
else if (line[n + 1] == '/')
|
|
|
|
{
|
2019-10-27 18:45:33 +01:00
|
|
|
/* Check for "http://" or "https://" */
|
|
|
|
|
|
|
|
if ((n < 5 || strncmp(&line[n - 5], "http://", 7) != 0) &&
|
|
|
|
(n < 6 || strncmp(&line[n - 6], "https://", 8) != 0))
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("C++ style comment on at %d:%d\n",
|
2019-10-27 18:45:33 +01:00
|
|
|
lineno, n);
|
|
|
|
}
|
|
|
|
|
2019-03-11 19:48:17 +01:00
|
|
|
n++;
|
2019-03-01 17:50:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* /= */
|
|
|
|
|
|
|
|
else if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
2019-03-11 19:48:17 +01:00
|
|
|
|
|
|
|
/* Division operator */
|
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '*':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* *\/, ** */
|
|
|
|
|
|
|
|
if (line[n] == '*' &&
|
|
|
|
(line[n + 1] == '/' ||
|
|
|
|
line[n + 1] == '*'))
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *<variable>, *(<expression>) */
|
|
|
|
|
|
|
|
else if (isalpha((int)line[n + 1]) ||
|
|
|
|
line[n + 1] == '_' ||
|
|
|
|
line[n + 1] == '(')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (<type> *) */
|
|
|
|
|
|
|
|
else if (line[n + 1] == ')')
|
|
|
|
{
|
|
|
|
/* REVISIT: This gives false alarms on syntax like *--ptr */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2021-11-25 06:06:35 +01:00
|
|
|
if (line[n - 1] != ' ' && line[n - 1] != '(')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Operator/assignment must be preceded "
|
|
|
|
"with whitespace", lineno, n);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* *= */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
else if (line[n + 1] == '=')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-03-01 17:50:02 +01:00
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
2019-03-01 17:50:02 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* A single '*' may be an binary operator, but
|
|
|
|
* it could also be a unary operator when used to deference
|
|
|
|
* a pointer.
|
|
|
|
*/
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
check_spaces_left(line, lineno, n);
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
break;
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
case '%':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* %= */
|
|
|
|
|
|
|
|
if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n);
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
break;
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
case '<':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* <=, <<, <<= */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
else if (line[n + 1] == '<')
|
|
|
|
{
|
|
|
|
if (line[n + 2] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 2);
|
|
|
|
n += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n);
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
break;
|
2015-10-12 22:29:43 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
case '>':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* >=, >>, >>= */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
else if (line[n + 1] == '>')
|
|
|
|
{
|
|
|
|
if (line[n + 2] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 2);
|
|
|
|
n += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n);
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
break;
|
2015-10-08 20:48:40 +02:00
|
|
|
|
|
|
|
case '|':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* |=, || */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
else if (line[n + 1] == '|')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n);
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
break;
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
case '^':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* ^= */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n);
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
break;
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
case '=':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* == */
|
|
|
|
|
|
|
|
if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n);
|
|
|
|
}
|
2015-10-12 22:29:43 +02:00
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '~':
|
2019-03-01 17:50:02 +01:00
|
|
|
check_spaces_left(line, lineno, n);
|
|
|
|
break;
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
case '!':
|
2019-12-30 19:34:43 +01:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* != */
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
if (line[n + 1] == '=')
|
|
|
|
{
|
|
|
|
check_spaces_leftright(line, lineno, n, n + 1);
|
|
|
|
n++;
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-03-01 17:50:02 +01:00
|
|
|
/* !! */
|
|
|
|
|
|
|
|
else if (line[n + 1] == '!')
|
|
|
|
{
|
|
|
|
check_spaces_left(line, lineno, n);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_spaces_left(line, lineno, n);
|
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-30 23:33:41 +01:00
|
|
|
/* Loop terminates when NUL or newline character found */
|
|
|
|
|
2020-04-06 20:02:29 +02:00
|
|
|
if (line[n] == '\n' || line[n] == '\0')
|
2018-10-30 23:33:41 +01:00
|
|
|
{
|
2020-04-06 20:02:29 +02:00
|
|
|
/* If the parse terminated on the NULL, then back up to the last
|
|
|
|
* character (which should be the newline).
|
|
|
|
*/
|
|
|
|
|
|
|
|
int m = n;
|
|
|
|
if (line[m] == '\0' && m > 0)
|
|
|
|
{
|
|
|
|
m--;
|
|
|
|
}
|
|
|
|
|
2019-10-23 20:49:27 +02:00
|
|
|
/* Check for space at the end of the line. Except for carriage
|
|
|
|
* returns which we have already reported (one time) above.
|
|
|
|
*/
|
2018-11-19 14:50:59 +01:00
|
|
|
|
2020-04-06 20:02:29 +02:00
|
|
|
if (m > 1 && isspace((int)line[m - 1]) &&
|
|
|
|
line[m - 1] != '\n' && line[m - 1] != '\r')
|
2018-11-19 14:50:59 +01:00
|
|
|
{
|
2024-08-26 15:00:01 +02:00
|
|
|
/* Report warning on if statement only is pnest is 0
|
|
|
|
* This takes into consideration the multiline if statement.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (bif == true && pnest == 0)
|
|
|
|
{
|
|
|
|
WARN("If statement followed by garbage", lineno, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
ERROR("Dangling whitespace at the end of line", lineno, m);
|
2018-11-19 14:50:59 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 20:02:29 +02:00
|
|
|
/* The line width is determined by the location of the final
|
|
|
|
* asterisk in block comments. The closing line of the block
|
|
|
|
* comment will exceed that by one one character, the '/'
|
|
|
|
* following the final asterisk.
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if (m > g_maxline)
|
|
|
|
{
|
|
|
|
bool bslash;
|
|
|
|
int a;
|
|
|
|
|
|
|
|
for (bslash = false, a = m;
|
|
|
|
a > 2 && strchr("\n\r/", line[a]) != NULL;
|
|
|
|
a--)
|
|
|
|
{
|
|
|
|
if (line[a] == '/')
|
|
|
|
{
|
|
|
|
bslash = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bslash && line[a] == '*')
|
|
|
|
{
|
|
|
|
m = a + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for long lines
|
|
|
|
*
|
|
|
|
* REVISIT: Long line checks suppressed on right hand comments
|
|
|
|
* for now. This just prevents a large number of difficult-to-
|
|
|
|
* fix complaints that we would have otherwise.
|
|
|
|
*/
|
2018-11-19 14:50:59 +01:00
|
|
|
|
2020-04-06 20:02:29 +02:00
|
|
|
if (m > g_maxline && !rhcomment)
|
2018-11-19 14:50:59 +01:00
|
|
|
{
|
2024-05-14 23:01:24 +02:00
|
|
|
/* Ignore the line 2 (file path) */
|
|
|
|
|
|
|
|
if (lineno == 2)
|
|
|
|
{
|
|
|
|
INFO("Skipping checking line 2: path file\n", 2, m);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERROR("Long line found", lineno, m);
|
|
|
|
}
|
2018-11-19 14:50:59 +01:00
|
|
|
}
|
2018-10-30 23:33:41 +01:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
/* STEP 4: Check alignment */
|
|
|
|
|
|
|
|
/* Within a comment block, we need only check on the alignment of the
|
|
|
|
* comment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((ncomment > 0 || prevncomment > 0) && !bstring)
|
|
|
|
{
|
2019-12-01 18:37:30 +01:00
|
|
|
/* Nothing should begin in comment zero */
|
|
|
|
|
2019-06-30 23:10:14 +02:00
|
|
|
if (indent == 0 && line[0] != '/' && !bexternc)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-01 18:37:30 +01:00
|
|
|
/* NOTE: if this line contains a comment to the right of the
|
|
|
|
* code, then ncomment will be misleading because it was
|
|
|
|
* already incremented above.
|
|
|
|
*/
|
|
|
|
|
2020-03-08 20:02:51 +01:00
|
|
|
if (ncomment > 1 || rhcomment == 0)
|
2019-12-01 18:37:30 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("No indentation line", lineno, indent);
|
2019-12-01 18:37:30 +01:00
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
else if (indent == 1 && line[0] == ' ' && line[1] == '*')
|
|
|
|
{
|
|
|
|
/* Good indentation */
|
|
|
|
}
|
|
|
|
else if (indent > 0 && line[indent] == '\n')
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Whitespace on blank line", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
else if (indent > 0 && indent < 2)
|
|
|
|
{
|
2019-02-17 17:57:28 +01:00
|
|
|
if (bnest > 0)
|
2019-02-09 14:19:10 +01:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Insufficient indentation", lineno, indent);
|
2019-02-09 14:19:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Expected indentation line", lineno, indent);
|
2019-02-09 14:19:10 +01:00
|
|
|
}
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
else if (indent > 0 && !bswitch)
|
|
|
|
{
|
|
|
|
if (line[indent] == '/')
|
|
|
|
{
|
2019-12-01 18:37:30 +01:00
|
|
|
/* Comments should like at offsets 2, 6, 10, ...
|
|
|
|
* This rule is not followed, however, if the comments are
|
|
|
|
* aligned to the right of the code.
|
|
|
|
*/
|
|
|
|
|
2020-03-08 20:02:51 +01:00
|
|
|
if ((indent & 3) != 2 && rhcomment == 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Bad comment alignment", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* REVISIT: This screws up in cases where there is C code,
|
|
|
|
* followed by a comment that continues on the next line.
|
|
|
|
*/
|
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
else if (line[indent + 1] != '*')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Missing asterisk in comment", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (line[indent] == '*')
|
|
|
|
{
|
|
|
|
/* REVISIT: Generates false alarms on comments at the end of
|
|
|
|
* the line if there is nothing preceding (such as the aligned
|
2020-03-07 14:35:08 +01:00
|
|
|
* comments with a structure field definition). So disabled
|
|
|
|
* for comments before beginning of function definitions.
|
2019-10-25 20:34:42 +02:00
|
|
|
*
|
2020-03-07 14:35:08 +01:00
|
|
|
* Suppress this error if this is a comment to the right of
|
|
|
|
* code.
|
2019-10-27 18:45:33 +01:00
|
|
|
* Those may be unaligned.
|
2015-10-08 20:48:40 +02:00
|
|
|
*/
|
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
if ((indent & 3) != 3 && bfunctions && dnest == 0 &&
|
2020-03-08 20:02:51 +01:00
|
|
|
rhcomment == 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Bad comment block alignment", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
2019-11-09 19:10:22 +01:00
|
|
|
if (line[indent + 1] != ' ' &&
|
|
|
|
line[indent + 1] != '*' &&
|
|
|
|
line[indent + 1] != '\n' &&
|
|
|
|
line[indent + 1] != '/')
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Invalid character after asterisk "
|
|
|
|
"in comment block", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this is not the line containing the comment start, then this
|
|
|
|
* line should begin with '*'
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if (prevncomment > 0)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Missing asterisk in comment block", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for various alignment outside of the comment block */
|
|
|
|
|
2019-06-30 18:35:10 +02:00
|
|
|
else if ((ncomment == 0 && prevncomment == 0) && !bstring)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
|
|
|
if (indent == 0 && strchr("\n#{}", line[0]) == NULL)
|
|
|
|
{
|
|
|
|
/* Ignore if we are at global scope */
|
|
|
|
|
2019-02-17 17:57:28 +01:00
|
|
|
if (prevbnest > 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
|
|
|
bool blabel = false;
|
|
|
|
|
|
|
|
if (isalpha((int)line[indent]))
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
for (i = indent + 1; isalnum((int)line[i]) ||
|
|
|
|
line[i] == '_'; i++);
|
2015-10-08 20:48:40 +02:00
|
|
|
blabel = (line[i] == ':');
|
|
|
|
}
|
|
|
|
|
2019-06-30 23:10:14 +02:00
|
|
|
if (!blabel && !bexternc)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("No indentation line", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (indent == 1 && line[0] == ' ' && line[1] == '*')
|
|
|
|
{
|
|
|
|
/* Good indentation */
|
|
|
|
}
|
|
|
|
else if (indent > 0 && line[indent] == '\n')
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Whitespace on blank line", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
else if (indent > 0 && indent < 2)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Insufficient indentation line", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
else if (line[indent] == '{')
|
|
|
|
{
|
2020-01-28 16:17:49 +01:00
|
|
|
/* Check for left brace in first column, but preceded by a
|
|
|
|
* blank line. Should never happen (but could happen with
|
|
|
|
* internal compound statements).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (indent == 0 && lineno == blank_lineno + 1)
|
|
|
|
{
|
|
|
|
ERROR("Blank line before opening left brace", lineno, indent);
|
|
|
|
}
|
|
|
|
|
2019-06-30 18:35:10 +02:00
|
|
|
/* REVISIT: Possible false alarms in compound statements
|
|
|
|
* without a preceding conditional. That usage often violates
|
|
|
|
* the coding standard.
|
|
|
|
*/
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2020-01-28 16:17:49 +01:00
|
|
|
else if (!bfunctions && (indent & 1) != 0)
|
2019-06-30 18:35:10 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Bad left brace alignment", lineno, indent);
|
2019-06-30 18:35:10 +02:00
|
|
|
}
|
|
|
|
else if ((indent & 3) != 0 && !bswitch && dnest == 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Bad left brace alignment", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (line[indent] == '}')
|
|
|
|
{
|
2019-06-30 18:35:10 +02:00
|
|
|
/* REVISIT: Possible false alarms in compound statements
|
|
|
|
* without a preceding conditional. That usage often violates
|
|
|
|
* the coding standard.
|
|
|
|
*/
|
2015-10-08 20:48:40 +02:00
|
|
|
|
2019-06-30 18:35:10 +02:00
|
|
|
if (!bfunctions && (indent & 1) != 0)
|
|
|
|
{
|
2021-04-01 08:38:17 +02:00
|
|
|
ERROR("Bad left brace alignment", lineno, indent);
|
2019-06-30 18:35:10 +02:00
|
|
|
}
|
|
|
|
else if ((indent & 3) != 0 && !bswitch && prevdnest == 0)
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Bad right brace alignment", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (indent > 0)
|
|
|
|
{
|
|
|
|
/* REVISIT: Generates false alarms when a statement continues on
|
2019-12-30 19:34:43 +01:00
|
|
|
* the next line. The bstatm check limits to lines beginning
|
|
|
|
* with C keywords.
|
2015-10-08 20:48:40 +02:00
|
|
|
* REVISIT: The bstatm check will not detect statements that
|
2019-06-29 21:24:38 +02:00
|
|
|
* do not begin with a C keyword (such as assignment statements).
|
2015-10-08 20:48:40 +02:00
|
|
|
* REVISIT: Generates false alarms on comments at the end of
|
|
|
|
* the line if there is nothing preceding (such as the aligned
|
|
|
|
* comments with a structure field definition). So disabled for
|
|
|
|
* comments before beginning of function definitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((bstatm || /* Begins with C keyword */
|
2021-09-07 05:20:23 +02:00
|
|
|
(line[indent] == '/' &&
|
|
|
|
bfunctions &&
|
|
|
|
line[indent + 1] == '*')) && /* Comment in functions */
|
2015-10-08 20:48:40 +02:00
|
|
|
!bswitch && /* Not in a switch */
|
2019-02-17 17:57:28 +01:00
|
|
|
dnest == 0) /* Not a data definition */
|
2015-10-08 20:48:40 +02:00
|
|
|
{
|
|
|
|
if ((indent & 3) != 2)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Bad alignment", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 00:19:10 +02:00
|
|
|
/* Crazy cases. There should be no small odd alignments
|
2015-10-08 20:48:40 +02:00
|
|
|
* outside of comment/string. Odd alignments are possible
|
|
|
|
* on continued lines, but not if they are small.
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if (indent == 1 || indent == 3)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Small odd alignment", lineno, indent);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-30 19:34:43 +01:00
|
|
|
if (!bfunctions && g_file_type == C_SOURCE)
|
2019-06-29 19:43:37 +02:00
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("\"Private/Public Functions\" not found!"
|
2021-04-01 08:38:17 +02:00
|
|
|
" File will not be checked", lineno, 1);
|
2019-06-29 19:43:37 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:48:40 +02:00
|
|
|
if (ncomment > 0 || bstring)
|
|
|
|
{
|
2019-12-30 19:34:43 +01:00
|
|
|
ERROR("Comment or string found at end of file", lineno, 1);
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(instream);
|
2019-12-30 19:34:43 +01:00
|
|
|
if (g_verbose == 1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: %s nxstyle check\n", g_file_name,
|
|
|
|
g_status == 0 ? "PASSED" : "FAILED");
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_status;
|
2015-10-08 20:48:40 +02:00
|
|
|
}
|