From f914ec6e2bba4d763d067d31b1d1c42952027810 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 1 Mar 2019 10:50:02 -0600 Subject: [PATCH] tools/nxstyle.c: Fix logic that detects if an operator is correctly delimited with spaces. sched/: Various changes because sched/ C files were used as Guinea Pigs to test nstyle.c. --- TODO | 9 + arch/arm/src/common/up_createstack.c | 2 +- sched/clock/clock_dow.c | 5 +- sched/clock/clock_initialize.c | 4 +- sched/environ/env_dup.c | 3 - sched/environ/env_putenv.c | 3 - sched/environ/env_release.c | 3 - sched/environ/env_removevar.c | 3 - sched/environ/env_unsetenv.c | 3 - sched/group/group_join.c | 1 + sched/group/group_killchildren.c | 2 +- sched/group/group_suspendchildren.c | 2 +- sched/mqueue/mq_send.c | 4 +- sched/pthread/pthread_condbroadcast.c | 2 - sched/pthread/pthread_condsignal.c | 2 - sched/pthread/pthread_mutextrylock.c | 3 - sched/pthread/pthread_mutexunlock.c | 52 ++- sched/sched/sched_foreach.c | 2 - sched/sched/sched_getsockets.c | 2 - sched/signal/sig_allocpendingsigaction.c | 3 +- sched/signal/sig_default.c | 5 +- sched/signal/sig_dispatch.c | 3 +- sched/signal/sig_releasependingsigaction.c | 6 +- sched/signal/sig_timedwait.c | 14 +- sched/task/task_atexit.c | 2 - sched/task/task_onexit.c | 2 - sched/wqueue/kwork_notifier.c | 3 +- tools/nxstyle.c | 450 ++++++++++++++------- 28 files changed, 362 insertions(+), 233 deletions(-) diff --git a/TODO b/TODO index d27cd7371f7..14a09fad4c6 100644 --- a/TODO +++ b/TODO @@ -903,15 +903,24 @@ o pthreads (sched/pthreads libs/libc/pthread) 1. The Use is not fully verified. How are these interfaces used? How should they be tested? + 2. These interfaces depend on architecture specific support support fraom each architecture that support is not be fully available to the pthread library in all cases. + + There should a setting, say CONFIG_ARCH_HAVE_TESTSET=y + that indicates if the architect provides up_testset(). + 3. It is also restricted to CONFIG_BUILD_FLAT because the critical test and set function (up_testset()) as prototyped in include/nuttx/spinlock() does not permit an inline function or macro to be used in user-mode application space. + Update: A better alternative would be to move the CPU- + depending up_testset() implementation from the arch/ + directories and into libs/libc/machine. + For these reasons, the selection is marked EXPERIMENTAL. Status: Open Priority: Low. These are new interfaces and not yet in wide use. The diff --git a/arch/arm/src/common/up_createstack.c b/arch/arm/src/common/up_createstack.c index 2f3bd3b4d4c..9ed678f9125 100644 --- a/arch/arm/src/common/up_createstack.c +++ b/arch/arm/src/common/up_createstack.c @@ -74,7 +74,7 @@ /* Stack alignment macros */ -#define STACK_ALIGN_MASK (CONFIG_STACK_ALIGNMENT-1) +#define STACK_ALIGN_MASK (CONFIG_STACK_ALIGNMENT - 1) #define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) #define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) diff --git a/sched/clock/clock_dow.c b/sched/clock/clock_dow.c index f57b8d0ad4d..94f9628049b 100644 --- a/sched/clock/clock_dow.c +++ b/sched/clock/clock_dow.c @@ -51,7 +51,10 @@ /* 23 * (month + 1) / 9, month = 0..11 */ -static const uint8_t g_lookup[12] = {2, 5, 7, 10, 12, 15, 17, 20, 23, 25, 28, 30}; +static const uint8_t g_lookup[12] = +{ + 2, 5, 7, 10, 12, 15, 17, 20, 23, 25, 28, 30 +}; /**************************************************************************** * Public Functions diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index b76ecde43d5..1034fc2c5f1 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -293,7 +293,9 @@ void clock_synchronize(void) #if defined(CONFIG_RTC) && !defined(CONFIG_SCHED_TICKLESS) void clock_resynchronize(FAR struct timespec *rtc_diff) { - struct timespec rtc_time, bias, curr_ts; + struct timespec rtc_time; + struct timespec bias; + struct timespec curr_ts; struct timespec rtc_diff_tmp; irqstate_t flags; int32_t carry; diff --git a/sched/environ/env_dup.c b/sched/environ/env_dup.c index 8ce8673d57f..316569cd5f0 100644 --- a/sched/environ/env_dup.c +++ b/sched/environ/env_dup.c @@ -137,6 +137,3 @@ int env_dup(FAR struct task_group_s *group) } #endif /* CONFIG_DISABLE_ENVIRON */ - - - diff --git a/sched/environ/env_putenv.c b/sched/environ/env_putenv.c index fa9a536ddfc..512f8cde509 100644 --- a/sched/environ/env_putenv.c +++ b/sched/environ/env_putenv.c @@ -114,6 +114,3 @@ errout: } #endif /* CONFIG_DISABLE_ENVIRON */ - - - diff --git a/sched/environ/env_release.c b/sched/environ/env_release.c index 61a113559b3..b05b1e62db2 100644 --- a/sched/environ/env_release.c +++ b/sched/environ/env_release.c @@ -95,6 +95,3 @@ void env_release(FAR struct task_group_s *group) } #endif /* CONFIG_DISABLE_ENVIRON */ - - - diff --git a/sched/environ/env_removevar.c b/sched/environ/env_removevar.c index 7efc6057eaa..f8c9e01fe45 100644 --- a/sched/environ/env_removevar.c +++ b/sched/environ/env_removevar.c @@ -115,6 +115,3 @@ int env_removevar(FAR struct task_group_s *group, FAR char *pvar) } #endif /* CONFIG_DISABLE_ENVIRON */ - - - diff --git a/sched/environ/env_unsetenv.c b/sched/environ/env_unsetenv.c index 74f44caee1d..d6fb818bcba 100644 --- a/sched/environ/env_unsetenv.c +++ b/sched/environ/env_unsetenv.c @@ -133,6 +133,3 @@ int unsetenv(FAR const char *name) } #endif /* CONFIG_DISABLE_ENVIRON */ - - - diff --git a/sched/group/group_join.c b/sched/group/group_join.c index 1f2c072e3ff..fdfcbc48951 100644 --- a/sched/group/group_join.c +++ b/sched/group/group_join.c @@ -56,6 +56,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + /* Is this worth making a configuration option? */ #define GROUP_REALLOC_MEMBERS 4 diff --git a/sched/group/group_killchildren.c b/sched/group/group_killchildren.c index 595d87865ef..19033ccaad3 100644 --- a/sched/group/group_killchildren.c +++ b/sched/group/group_killchildren.c @@ -116,7 +116,7 @@ static int group_killchildren_handler(pid_t pid, FAR void *arg) } } - /* Always return zero. We need to visit each member of the group*/ + /* Always return zero. We need to visit each member of the group. */ return OK; } diff --git a/sched/group/group_suspendchildren.c b/sched/group/group_suspendchildren.c index 4d594b72eb9..131ff72be6e 100644 --- a/sched/group/group_suspendchildren.c +++ b/sched/group/group_suspendchildren.c @@ -87,7 +87,7 @@ static int group_suspendchildren_handler(pid_t pid, FAR void *arg) } } - /* Always return zero. We need to visit each member of the group*/ + /* Always return zero. We need to visit each member of the group. */ return OK; } diff --git a/sched/mqueue/mq_send.c b/sched/mqueue/mq_send.c index c9bf30299ae..c65925259c0 100644 --- a/sched/mqueue/mq_send.c +++ b/sched/mqueue/mq_send.c @@ -122,8 +122,8 @@ int nxmq_send(mqd_t mqdes, FAR const char *msg, size_t msglen, if (msgq->nmsgs >= msgq->maxmsgs) /* Message queue not-FULL? */ { - /* Yes.. the message queue is full. Wait for space to become - * available in the message queue. + /* Yes.. the message queue is full. Wait for space to become + * available in the message queue. */ ret = nxmq_wait_send(mqdes); diff --git a/sched/pthread/pthread_condbroadcast.c b/sched/pthread/pthread_condbroadcast.c index 71e829ba196..0e7e1d53f56 100644 --- a/sched/pthread/pthread_condbroadcast.c +++ b/sched/pthread/pthread_condbroadcast.c @@ -121,5 +121,3 @@ int pthread_cond_broadcast(FAR pthread_cond_t *cond) sinfo("Returning %d\n", ret); return ret; } - - diff --git a/sched/pthread/pthread_condsignal.c b/sched/pthread/pthread_condsignal.c index 5b5f09adb8d..9a72d6c4a60 100644 --- a/sched/pthread/pthread_condsignal.c +++ b/sched/pthread/pthread_condsignal.c @@ -113,5 +113,3 @@ int pthread_cond_signal(FAR pthread_cond_t *cond) sinfo("Returning %d\n", ret); return ret; } - - diff --git a/sched/pthread/pthread_mutextrylock.c b/sched/pthread/pthread_mutextrylock.c index 28b17c2466b..3d8c18f7f53 100644 --- a/sched/pthread/pthread_mutextrylock.c +++ b/sched/pthread/pthread_mutextrylock.c @@ -211,6 +211,3 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex) sinfo("Returning %d\n", ret); return ret; } - - - diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 11516dd6c37..228edb1f1d0 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -199,45 +199,43 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) #endif /* !CONFIG_PTHREAD_MUTEX_UNSAFE || CONFIG_PTHREAD_MUTEX_TYPES */ #ifdef CONFIG_PTHREAD_MUTEX_TYPES - /* Yes, the caller owns the semaphore.. Is this a recursive mutex? */ + /* Yes, the caller owns the semaphore.. Is this a recursive mutex? */ - if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->nlocks > 1) - { - /* This is a recursive mutex and we there are multiple locks held. Retain - * the mutex lock, just decrement the count of locks held, and return - * success. - */ + if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->nlocks > 1) + { + /* This is a recursive mutex and we there are multiple locks held. Retain + * the mutex lock, just decrement the count of locks held, and return + * success. + */ - mutex->nlocks--; - ret = OK; - } - else + mutex->nlocks--; + ret = OK; + } + else #endif /* CONFIG_PTHREAD_MUTEX_TYPES */ - /* This is either a non-recursive mutex or is the outermost unlock of - * a recursive mutex. - * - * In the case where the calling thread is NOT the holder of the thread, - * the behavior is undefined per POSIX. Here we do the same as GLIBC: - * We allow the other thread to release the mutex even though it does - * not own it. - */ + /* This is either a non-recursive mutex or is the outermost unlock of + * a recursive mutex. + * + * In the case where the calling thread is NOT the holder of the thread, + * the behavior is undefined per POSIX. Here we do the same as GLIBC: + * We allow the other thread to release the mutex even though it does + * not own it. + */ - { - /* Nullify the pid and lock count then post the semaphore */ + { + /* Nullify the pid and lock count then post the semaphore */ - mutex->pid = -1; + mutex->pid = -1; #ifdef CONFIG_PTHREAD_MUTEX_TYPES - mutex->nlocks = 0; + mutex->nlocks = 0; #endif - ret = pthread_mutex_give(mutex); - } + ret = pthread_mutex_give(mutex); + } } sched_unlock(); sinfo("Returning %d\n", ret); return ret; } - - diff --git a/sched/sched/sched_foreach.c b/sched/sched/sched_foreach.c index c5df9cd5f61..24ae872bb9b 100644 --- a/sched/sched/sched_foreach.c +++ b/sched/sched/sched_foreach.c @@ -90,5 +90,3 @@ void sched_foreach(sched_foreach_t handler, FAR void *arg) leave_critical_section(flags); } } - - diff --git a/sched/sched/sched_getsockets.c b/sched/sched/sched_getsockets.c index 4ea79074150..2ccf895f851 100644 --- a/sched/sched/sched_getsockets.c +++ b/sched/sched/sched_getsockets.c @@ -72,5 +72,3 @@ FAR struct socketlist *sched_getsockets(void) return &group->tg_socketlist; } #endif - - diff --git a/sched/signal/sig_allocpendingsigaction.c b/sched/signal/sig_allocpendingsigaction.c index 29aa7c13685..1f65410073d 100644 --- a/sched/signal/sig_allocpendingsigaction.c +++ b/sched/signal/sig_allocpendingsigaction.c @@ -83,7 +83,8 @@ FAR sigq_t *nxsig_alloc_pendingsigaction(void) } /* If we were not called from an interrupt handler, then we are - * free to allocate pending signal action structures if necessary. */ + * free to allocate pending signal action structures if necessary. + */ else { diff --git a/sched/signal/sig_default.c b/sched/signal/sig_default.c index fd6d9b00ecc..8b57d9b1a3f 100644 --- a/sched/signal/sig_default.c +++ b/sched/signal/sig_default.c @@ -512,8 +512,9 @@ bool nxsig_iscatchable(int signo) if (handler == SIG_IGN) { - /* We are unsetting the default action */ - /* sigdelset() is not atomic (but neither is sigaction()) */ + /* We are unsetting the default action. NOTE that sigdelset() is not + * atomic (but neither is sigaction()). + */ flags = spin_lock_irqsave(); (void)sigdelset(&group->tg_sigdefault, signo); diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index 977de7cdfe6..6ce98ea7707 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -93,7 +93,8 @@ static int nxsig_queue_action(FAR struct tcb_s *stcb, siginfo_t *info) { /* Allocate a new element for the signal queue. NOTE: * nxsig_alloc_pendingsigaction will force a system crash if it is - * unable to allocate memory for the signal data */ + * unable to allocate memory for the signal data. + */ sigq = nxsig_alloc_pendingsigaction(); if (!sigq) diff --git a/sched/signal/sig_releasependingsigaction.c b/sched/signal/sig_releasependingsigaction.c index 7099d2c6838..b1041e06d63 100644 --- a/sched/signal/sig_releasependingsigaction.c +++ b/sched/signal/sig_releasependingsigaction.c @@ -68,7 +68,8 @@ void nxsig_release_pendingsigaction(FAR sigq_t *sigq) if (sigq->type == SIG_ALLOC_FIXED) { /* Make sure we avoid concurrent access to the free - * list from interrupt handlers. */ + * list from interrupt handlers. + */ flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingaction); @@ -82,7 +83,8 @@ void nxsig_release_pendingsigaction(FAR sigq_t *sigq) else if (sigq->type == SIG_ALLOC_IRQ) { /* Make sure we avoid concurrent access to the free - * list from interrupt handlers. */ + * list from interrupt handlers. + */ flags = enter_critical_section(); sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingirqaction); diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c index 541d7a8aee2..d7be4afde82 100644 --- a/sched/signal/sig_timedwait.c +++ b/sched/signal/sig_timedwait.c @@ -434,14 +434,14 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info, } else #endif - { - /* We were awakened by a timeout. Set EAGAIN and return an - * error. - */ + { + /* We were awakened by a timeout. Set EAGAIN and return an + * error. + */ - DEBUGASSERT(rtcb->sigunbinfo.si_signo == SIG_WAIT_TIMEOUT); - ret = -EAGAIN; - } + DEBUGASSERT(rtcb->sigunbinfo.si_signo == SIG_WAIT_TIMEOUT); + ret = -EAGAIN; + } } /* Return the signal info to the caller if so requested */ diff --git a/sched/task/task_atexit.c b/sched/task/task_atexit.c index 91c6c9c6394..6d55f086796 100644 --- a/sched/task/task_atexit.c +++ b/sched/task/task_atexit.c @@ -152,5 +152,3 @@ int atexit(void (*func)(void)) } #endif /* CONFIG_SCHED_ATEXIT */ - - diff --git a/sched/task/task_onexit.c b/sched/task/task_onexit.c index ba7db4dec81..8c29a274897 100644 --- a/sched/task/task_onexit.c +++ b/sched/task/task_onexit.c @@ -149,5 +149,3 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) } #endif /* CONFIG_SCHED_ONEXIT */ - - diff --git a/sched/wqueue/kwork_notifier.c b/sched/wqueue/kwork_notifier.c index 31796cd5a6d..706aed41275 100644 --- a/sched/wqueue/kwork_notifier.c +++ b/sched/wqueue/kwork_notifier.c @@ -324,7 +324,8 @@ void work_notifier_signal(enum work_evtype_e evtype, sched_lock(); /* Process the notification at the head of the pending list until the - * pending list is empty */ + * pending list is empty + */ for (entry = dq_peek(&g_notifier_pending); entry != NULL; diff --git a/tools/nxstyle.c b/tools/nxstyle.c index b8e78fcd56f..14c3af7ee0d 100644 --- a/tools/nxstyle.c +++ b/tools/nxstyle.c @@ -61,6 +61,38 @@ static void show_usage(char *progname, int exitcode) exit(exitcode); } +static void check_spaces_left(char *line, int lineno, int ndx) +{ + /* Unary operator should generally be preceded by a space but make also + * follow a left parenthesis at the beginning of a parthentical list or + * expression or follow a right parentheses in the case of a cast. + */ + + if (ndx > 0 && line[ndx - 1] != ' ' && line[ndx - 1] != '(' && line[ndx - 1] != ')') + { + fprintf(stderr, + "Operator/assignment must be preceded with whitespace at line %d:%d\n", + lineno, ndx); + } +} + +static void check_spaces_leftright(char *line, int lineno, int ndx1, int ndx2) +{ + if (ndx1 > 0 && line[ndx1 - 1] != ' ') + { + fprintf(stderr, + "Operator/assignment must be preceded with whitespace at line %d:%d\n", + lineno, ndx1); + } + + if (line[ndx2 + 1] != '\0' && line[ndx2 + 1] != '\n' && line[ndx2 + 1] != ' ') + { + fprintf(stderr, + "Operator/assignment must be followed with whitespace at line %d:%d\n", + lineno, ndx2); + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -876,204 +908,312 @@ int main(int argc, char **argv, char **envp) /* Check for space around various operators */ case '-': - /* -> */ + /* ->, -- */ - if (line[n + 1] == '>') + if (line[n + 1] == '>' || line[n + 1] == '-') { n++; - break; } + /* -= */ + + 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; + case '+': - /* ++, -- */ + /* ++ */ - if (line[n + 1] == line[n]) + if (line[n + 1] == '+') { n++; - break; } + /* += */ + + 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; + case '&': - /* && */ - - if (line[n] == '&' && line[n + 1] == line[n]) - { - int curr; - int next; - - curr = n; - n++; - next = n + 1; - - if (line[curr-1] != ' ') - { - fprintf(stderr, - "Operator/assignment must be preceded with whitespace at line %d:%d\n", - lineno, curr); - } - - if (line[next] != ' ' && line[next] != '\n') - { - fprintf(stderr, - "Operator/assignment needs whitespace separation at line %d:%d\n", - lineno, curr); - } - - break; - } /* & OR &() */ - else if (isalpha((int)line[n + 1]) || line[n + 1] == '_' || line[n + 1] == '(') + if (isalpha((int)line[n + 1]) || line[n + 1] == '_' || + line[n + 1] == '(') + { + } + + /* &&, &= */ + + else if (line[n + 1] == '=' || line[n + 1] == '&') + { + check_spaces_leftright(line, lineno, n, n + 1); + n++; + } + else + { + check_spaces_leftright(line, lineno, n, n); + } + + break; + + case '/': + /* C++-style comment */ + + if (line[n] == '/') + { + if (line[n - 1] == '*') + { + n++; + } + else if (line[n + 1] == '/') + { + fprintf(stderr, "C++ style comment on at %d:%d\n", + lineno, n); + n++; + } + } + + /* /= */ + + else if (line[n + 1] == '=') + { + check_spaces_leftright(line, lineno, n, n + 1); + n++; + } + else + { + check_spaces_leftright(line, lineno, n, n); + } + + break; + + case '*': + /* *\/, ** */ + + if (line[n] == '*' && + (line[n + 1] == '/' || + line[n + 1] == '*')) + { + n++; + break; + } + + /* *, *() */ + + else if (isalpha((int)line[n + 1]) || + line[n + 1] == '_' || + line[n + 1] == '(') { break; } - case '/': - { - if (line[n] == '/') - { - if (line[n - 1] == '*') - { - n++; - break; - } - else if (line[n + 1] == '/') - { - fprintf(stderr, "C++ style comment on at %d:%d\n", - lineno, n); - n++; - break; - } - } - } + /* ( *) */ - case '*': - { - /* *\/, ** */ + else if (line[n + 1] == ')') + { + /* REVISIT: This gives false alarms on syntax like *--ptr */ - if (line[n] == '*' && - (line[n + 1] == '/' || - line[n + 1] == '*')) - { - n++; - break; - } + if (line[n - 1] != ' ') + { + fprintf(stderr, + "Operator/assignment must be preceded with whitespace at line %d:%d\n", + lineno, n); + } - /* *, *() */ + break; + } - else if (isalpha((int)line[n + 1]) || - line[n + 1] == '_' || - line[n + 1] == '(') - { - break; - } + /* *= */ - /* ( *) */ + else if (line[n + 1] == '=') + { + check_spaces_leftright(line, lineno, n, n + 1); + n++; + } + else + { + /* A single '*' may be an binary operator, but + * it could also be a unary operator when used to deference + * a pointer. + */ - else if (line[n + 1] == ')') - { - /* REVISIT: This gives false alarms on syntax like *--ptr */ + check_spaces_left(line, lineno, n); + } - if (line[n - 1] != ' ') - { - fprintf(stderr, - "Operator/assignment must be preceded with whitespace at line %d:%d\n", - lineno, n); - } - - break; - } - } + break; case '%': - { - if (isalnum((int)line[n + 1])) - { - break; - } - } + /* %= */ + + if (line[n + 1] == '=') + { + check_spaces_leftright(line, lineno, n, n + 1); + n++; + } + else + { + check_spaces_leftright(line, lineno, n, n); + } + + break; case '<': + /* <=, <<, <<= */ + + 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); + } + + break; + case '>': + /* >=, >>, >>= */ + + 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); + } + + break; + case '|': + /* |=, || */ + + 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); + } + + break; + case '^': + /* ^= */ + + if (line[n + 1] == '=') + { + check_spaces_leftright(line, lineno, n, n + 1); + n++; + } + else + { + check_spaces_leftright(line, lineno, n, n); + } + + break; + case '=': - { - int curr; - int next; + /* == */ - curr = n; - if (line[curr - 1] != ' ') - { - fprintf(stderr, - "Operator/assignment must be preceded with whitespace at line %d:%d\n", - lineno, curr); - } + if (line[n + 1] == '=') + { + check_spaces_leftright(line, lineno, n, n + 1); + n++; + } + else + { + check_spaces_leftright(line, lineno, n, n); + } - next = n + 1; - - /* <<, >>, <<=, >>= */ - - if (line[curr] == '>' || line[curr] == '<') - { - if (line[next] == line[curr]) - { - next++; - n++; - } - - if (line[next] == '=') - { - next++; - n++; - } - } - else if (line[next] == '=' || line[next] == line[n]) - { - next++; - n++; - } - - /* REVISIT: This gives false alarms on syntax like *--ptr */ - - if (line[curr] != '-' && line[next] != ' ' && line[next] != '\n') - { - fprintf(stderr, - "Operator/assignment needs whitespace separation at line %d:%d\n", - lineno, curr); - } - } break; case '~': + check_spaces_left(line, lineno, n); + break; + case '!': - { - int curr; - int next; + /* != */ - curr = n; - next = n + 1; - if (line[next] == '=' || line[next] == line[n]) - { - next++; - n++; + if (line[n + 1] == '=') + { + check_spaces_leftright(line, lineno, n, n + 1); + n++; + } - if (line[next] != ' ' && line[next] != '\n') - { - fprintf(stderr, - "Operator/assignment needs whitespace separation at line %d:%d\n", - lineno, curr); - } - } + /* !! */ + + else if (line[n + 1] == '!') + { + check_spaces_left(line, lineno, n); + n++; + } + else + { + check_spaces_left(line, lineno, n); + } - if (line[curr-1] != ' ' && line[curr-1] != '(') - { - fprintf(stderr, - "Operator/assignment must be preceded with whitespace at line %d:%d\n", - lineno, curr); - } - } break; default: