mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 07:12:54 +08:00
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.
This commit is contained in:
@@ -903,15 +903,24 @@ o pthreads (sched/pthreads libs/libc/pthread)
|
|||||||
|
|
||||||
1. The Use is not fully verified. How are these interfaces
|
1. The Use is not fully verified. How are these interfaces
|
||||||
used? How should they be tested?
|
used? How should they be tested?
|
||||||
|
|
||||||
2. These interfaces depend on architecture specific support
|
2. These interfaces depend on architecture specific support
|
||||||
support fraom each architecture that support is not be
|
support fraom each architecture that support is not be
|
||||||
fully available to the pthread library in all cases.
|
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
|
3. It is also restricted to CONFIG_BUILD_FLAT because the
|
||||||
critical test and set function (up_testset()) as
|
critical test and set function (up_testset()) as
|
||||||
prototyped in include/nuttx/spinlock() does not permit an
|
prototyped in include/nuttx/spinlock() does not permit an
|
||||||
inline function or macro to be used in user-mode
|
inline function or macro to be used in user-mode
|
||||||
application space.
|
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.
|
For these reasons, the selection is marked EXPERIMENTAL.
|
||||||
Status: Open
|
Status: Open
|
||||||
Priority: Low. These are new interfaces and not yet in wide use. The
|
Priority: Low. These are new interfaces and not yet in wide use. The
|
||||||
|
|||||||
@@ -51,7 +51,10 @@
|
|||||||
|
|
||||||
/* 23 * (month + 1) / 9, month = 0..11 */
|
/* 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
|
* Public Functions
|
||||||
|
|||||||
@@ -293,7 +293,9 @@ void clock_synchronize(void)
|
|||||||
#if defined(CONFIG_RTC) && !defined(CONFIG_SCHED_TICKLESS)
|
#if defined(CONFIG_RTC) && !defined(CONFIG_SCHED_TICKLESS)
|
||||||
void clock_resynchronize(FAR struct timespec *rtc_diff)
|
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;
|
struct timespec rtc_diff_tmp;
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int32_t carry;
|
int32_t carry;
|
||||||
|
|||||||
@@ -137,6 +137,3 @@ int env_dup(FAR struct task_group_s *group)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_DISABLE_ENVIRON */
|
#endif /* CONFIG_DISABLE_ENVIRON */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -114,6 +114,3 @@ errout:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_DISABLE_ENVIRON */
|
#endif /* CONFIG_DISABLE_ENVIRON */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,3 @@ void env_release(FAR struct task_group_s *group)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_DISABLE_ENVIRON */
|
#endif /* CONFIG_DISABLE_ENVIRON */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -115,6 +115,3 @@ int env_removevar(FAR struct task_group_s *group, FAR char *pvar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_DISABLE_ENVIRON */
|
#endif /* CONFIG_DISABLE_ENVIRON */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,3 @@ int unsetenv(FAR const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_DISABLE_ENVIRON */
|
#endif /* CONFIG_DISABLE_ENVIRON */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Is this worth making a configuration option? */
|
/* Is this worth making a configuration option? */
|
||||||
|
|
||||||
#define GROUP_REALLOC_MEMBERS 4
|
#define GROUP_REALLOC_MEMBERS 4
|
||||||
|
|||||||
@@ -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;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,5 +121,3 @@ int pthread_cond_broadcast(FAR pthread_cond_t *cond)
|
|||||||
sinfo("Returning %d\n", ret);
|
sinfo("Returning %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -113,5 +113,3 @@ int pthread_cond_signal(FAR pthread_cond_t *cond)
|
|||||||
sinfo("Returning %d\n", ret);
|
sinfo("Returning %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -211,6 +211,3 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex)
|
|||||||
sinfo("Returning %d\n", ret);
|
sinfo("Returning %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -239,5 +239,3 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
|
|||||||
sinfo("Returning %d\n", ret);
|
sinfo("Returning %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -90,5 +90,3 @@ void sched_foreach(sched_foreach_t handler, FAR void *arg)
|
|||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,5 +72,3 @@ FAR struct socketlist *sched_getsockets(void)
|
|||||||
return &group->tg_socketlist;
|
return &group->tg_socketlist;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ FAR sigq_t *nxsig_alloc_pendingsigaction(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If we were not called from an interrupt handler, then we are
|
/* 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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -512,8 +512,9 @@ bool nxsig_iscatchable(int signo)
|
|||||||
|
|
||||||
if (handler == SIG_IGN)
|
if (handler == SIG_IGN)
|
||||||
{
|
{
|
||||||
/* We are unsetting the default action */
|
/* We are unsetting the default action. NOTE that sigdelset() is not
|
||||||
/* sigdelset() is not atomic (but neither is sigaction()) */
|
* atomic (but neither is sigaction()).
|
||||||
|
*/
|
||||||
|
|
||||||
flags = spin_lock_irqsave();
|
flags = spin_lock_irqsave();
|
||||||
(void)sigdelset(&group->tg_sigdefault, signo);
|
(void)sigdelset(&group->tg_sigdefault, signo);
|
||||||
|
|||||||
@@ -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:
|
/* Allocate a new element for the signal queue. NOTE:
|
||||||
* nxsig_alloc_pendingsigaction will force a system crash if it is
|
* 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();
|
sigq = nxsig_alloc_pendingsigaction();
|
||||||
if (!sigq)
|
if (!sigq)
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ void nxsig_release_pendingsigaction(FAR sigq_t *sigq)
|
|||||||
if (sigq->type == SIG_ALLOC_FIXED)
|
if (sigq->type == SIG_ALLOC_FIXED)
|
||||||
{
|
{
|
||||||
/* Make sure we avoid concurrent access to the free
|
/* Make sure we avoid concurrent access to the free
|
||||||
* list from interrupt handlers. */
|
* list from interrupt handlers.
|
||||||
|
*/
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingaction);
|
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)
|
else if (sigq->type == SIG_ALLOC_IRQ)
|
||||||
{
|
{
|
||||||
/* Make sure we avoid concurrent access to the free
|
/* Make sure we avoid concurrent access to the free
|
||||||
* list from interrupt handlers. */
|
* list from interrupt handlers.
|
||||||
|
*/
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingirqaction);
|
sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingirqaction);
|
||||||
|
|||||||
@@ -152,5 +152,3 @@ int atexit(void (*func)(void))
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_SCHED_ATEXIT */
|
#endif /* CONFIG_SCHED_ATEXIT */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -149,5 +149,3 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_SCHED_ONEXIT */
|
#endif /* CONFIG_SCHED_ONEXIT */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -324,7 +324,8 @@ void work_notifier_signal(enum work_evtype_e evtype,
|
|||||||
sched_lock();
|
sched_lock();
|
||||||
|
|
||||||
/* Process the notification at the head of the pending list until the
|
/* 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);
|
for (entry = dq_peek(&g_notifier_pending);
|
||||||
entry != NULL;
|
entry != NULL;
|
||||||
|
|||||||
+239
-99
@@ -61,6 +61,38 @@ static void show_usage(char *progname, int exitcode)
|
|||||||
exit(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
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -876,80 +908,112 @@ int main(int argc, char **argv, char **envp)
|
|||||||
/* Check for space around various operators */
|
/* Check for space around various operators */
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
/* -> */
|
/* ->, -- */
|
||||||
|
|
||||||
if (line[n + 1] == '>')
|
if (line[n + 1] == '>' || line[n + 1] == '-')
|
||||||
{
|
{
|
||||||
n++;
|
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 '+':
|
case '+':
|
||||||
/* ++, -- */
|
/* ++ */
|
||||||
|
|
||||||
if (line[n + 1] == line[n])
|
if (line[n + 1] == '+')
|
||||||
{
|
{
|
||||||
n++;
|
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 '&':
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* &<variable> OR &(<expression>) */
|
/* &<variable> OR &(<expression>) */
|
||||||
|
|
||||||
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] == '(')
|
||||||
{
|
{
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case '/':
|
/* &&, &= */
|
||||||
|
|
||||||
|
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] == '/')
|
||||||
{
|
{
|
||||||
if (line[n - 1] == '*')
|
if (line[n - 1] == '*')
|
||||||
{
|
{
|
||||||
n++;
|
n++;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else if (line[n + 1] == '/')
|
else if (line[n + 1] == '/')
|
||||||
{
|
{
|
||||||
fprintf(stderr, "C++ style comment on at %d:%d\n",
|
fprintf(stderr, "C++ style comment on at %d:%d\n",
|
||||||
lineno, n);
|
lineno, n);
|
||||||
n++;
|
n++;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case '*':
|
/* /= */
|
||||||
|
|
||||||
|
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] == '*' &&
|
if (line[n] == '*' &&
|
||||||
@@ -984,96 +1048,172 @@ int main(int argc, char **argv, char **envp)
|
|||||||
|
|
||||||
break;
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
check_spaces_left(line, lineno, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case '%':
|
case '%':
|
||||||
|
/* %= */
|
||||||
|
|
||||||
|
if (line[n + 1] == '=')
|
||||||
{
|
{
|
||||||
if (isalnum((int)line[n + 1]))
|
check_spaces_leftright(line, lineno, n, n + 1);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
|
check_spaces_leftright(line, lineno, n, n);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case '<':
|
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 '>':
|
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 '|':
|
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 '^':
|
case '^':
|
||||||
|
/* ^= */
|
||||||
|
|
||||||
|
if (line[n + 1] == '=')
|
||||||
|
{
|
||||||
|
check_spaces_leftright(line, lineno, n, n + 1);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
check_spaces_leftright(line, lineno, n, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case '=':
|
case '=':
|
||||||
{
|
/* == */
|
||||||
int curr;
|
|
||||||
int next;
|
|
||||||
|
|
||||||
curr = n;
|
if (line[n + 1] == '=')
|
||||||
if (line[curr - 1] != ' ')
|
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
check_spaces_leftright(line, lineno, n, n + 1);
|
||||||
"Operator/assignment must be preceded with whitespace at line %d:%d\n",
|
|
||||||
lineno, curr);
|
|
||||||
}
|
|
||||||
|
|
||||||
next = n + 1;
|
|
||||||
|
|
||||||
/* <<, >>, <<=, >>= */
|
|
||||||
|
|
||||||
if (line[curr] == '>' || line[curr] == '<')
|
|
||||||
{
|
|
||||||
if (line[next] == line[curr])
|
|
||||||
{
|
|
||||||
next++;
|
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (line[next] == '=')
|
|
||||||
{
|
{
|
||||||
next++;
|
check_spaces_leftright(line, lineno, n, n);
|
||||||
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;
|
break;
|
||||||
|
|
||||||
case '~':
|
case '~':
|
||||||
|
check_spaces_left(line, lineno, n);
|
||||||
|
break;
|
||||||
|
|
||||||
case '!':
|
case '!':
|
||||||
{
|
/* != */
|
||||||
int curr;
|
|
||||||
int next;
|
|
||||||
|
|
||||||
curr = n;
|
if (line[n + 1] == '=')
|
||||||
next = n + 1;
|
|
||||||
if (line[next] == '=' || line[next] == line[n])
|
|
||||||
{
|
{
|
||||||
next++;
|
check_spaces_leftright(line, lineno, n, n + 1);
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
if (line[next] != ' ' && line[next] != '\n')
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"Operator/assignment needs whitespace separation at line %d:%d\n",
|
|
||||||
lineno, curr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line[curr-1] != ' ' && line[curr-1] != '(')
|
/* !! */
|
||||||
|
|
||||||
|
else if (line[n + 1] == '!')
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
check_spaces_left(line, lineno, n);
|
||||||
"Operator/assignment must be preceded with whitespace at line %d:%d\n",
|
n++;
|
||||||
lineno, curr);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
check_spaces_left(line, lineno, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user