Commit 703e1325 authored by Alessandro Rubini's avatar Alessandro Rubini

tools: turn the all-inline header into tools-util.c

The header was a quick hack. This doesn't change anything in external
behaviour, but makes the inline functions into real function in
a library-like header linkerd in by all tools.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 79a7ebc5
......@@ -19,11 +19,14 @@ all modules: $(hostprogs-y)
clean:
rm -f $(hostprogs-y) *.o *~
$(hostprogs-y): tools-common.h $(wildcard ../lib/*.[ch])
$(hostprogs-y): tools-util.o tools-common.h $(wildcard ../lib/*.[ch])
# make nothing for modules_install, but avoid errors
modules_install install:
# we need this as we are out of the kernel
%: %.c
$(HOSTCC) $(HOST_EXTRACFLAGS) -O2 -Wall $*.c -L../lib -lfdelay -o $@
%: %.c $(wildcard *.h)
$(HOSTCC) $(HOST_EXTRACFLAGS) -O2 -Wall $*.c tools-util.o \
-L../lib -lfdelay -o $@
%.o: %.c $(wildcard *.h)
$(HOSTCC) $(HOST_EXTRACFLAGS) -O2 -Wall -c $*.c -o $@
......@@ -8,7 +8,7 @@
#include "tools-common.h"
static void help(char *name)
void help(char *name)
{
fprintf(stderr, "fmc-fdelay-board-time: a tool for manipulating the FMC Fine Delay time base.\n");
......
......@@ -11,7 +11,7 @@
#include "tools-common.h"
static void help(char *name)
void help(char *name)
{
fprintf(stderr, "%s: Use \"%s [-i <index>] [-d <dev>] [<opts>]\n",
name, name);
......
......@@ -9,7 +9,7 @@
#include "tools-common.h"
static void help(char *name)
void help(char *name)
{
fprintf(stderr, "%s: Lists boards, takes no arguments\n", name);
exit(1);
......
......@@ -12,7 +12,7 @@
#include "tools-common.h"
static void help(char *name)
void help(char *name)
{
fprintf(stderr, "%s: Use \"%s [-i <index>] [-d <dev>] [<opts>]\n",
name, name);
......
......@@ -8,7 +8,7 @@
#include "tools-common.h"
static void help(char *name)
void help(char *name)
{
fprintf(stderr, "fmc-fdelay-status: reports channel programming\n");
......
......@@ -8,7 +8,7 @@
#include "tools-common.h"
static void help(char *name)
void help(char *name)
{
fprintf(stderr, "%s: Use \"%s [-i <index>] [-d <dev>] [on|off]\n",
name, name);
......
......@@ -2,71 +2,10 @@
* Simple code that is repeated over several tools
*/
static void help(char *name); /* This is mandatory in all tools */
extern void tools_getopt_d_i(int argc, char **argv,
int *dev, int *index);
extern int tools_need_help(int argc, char **argv);
extern void report_time(char *name, struct fdelay_time *t);
extern void tools_report_action(int channel, struct fdelay_pulse *p);
static inline void tools_getopt_d_i(int argc, char **argv,
int *dev, int *index)
{
char *rest;
int opt;
while ((opt = getopt(argc, argv, "d:i:h")) != -1) {
switch (opt) {
case 'i':
*index = strtol(optarg, &rest, 0);
if (rest && *rest) {
fprintf(stderr, "%s: Not a number \"%s\"\n",
argv[0], optarg);
exit(1);
}
break;
case 'd':
*dev = strtol(optarg, &rest, 0);
if (rest && *rest) {
fprintf(stderr, "%s: Not a number \"%s\"\n",
argv[0], optarg);
exit(1);
}
break;
case 'h':
help(argv[0]);
}
}
}
static inline int tools_need_help(int argc, char **argv)
{
if (argc != 2)
return 0;
if (!strcmp(argv[1], "--help"))
return 1;
return 0;
}
static inline void report_time(char *name, struct fdelay_time *t)
{
printf(" %s utc %10lli, coarse %9li, frac %9li\n",
name, (long long)t->utc, (long)t->coarse, (long)t->frac);
}
static inline void tools_report_action(int channel, struct fdelay_pulse *p)
{
char *mode;
char s[80];
if (p->mode == FD_OUT_MODE_DISABLED) mode = "disable";
else if (p->mode == FD_OUT_MODE_PULSE) mode = "pulse";
else if (p->mode == FD_OUT_MODE_DELAY) mode = "delay";
else if (p->mode == 0x80) mode = "already-triggered";
else {
sprintf(s, "%i (0x%04x)", p->mode, p->mode);
mode = s;
}
printf("Channel %i, mode %s, repeat %i %s\n",
FDELAY_OUTPUT_HW_TO_USER(channel), mode,
p->rep, p->rep == -1 ? "(infinite)" : "");
report_time("start", &p->start);
report_time("end ", &p->end);
report_time("loop ", &p->loop);
}
extern void help(char *name); /* This is mandatory in all tools */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "fdelay-lib.h"
#include "tools-common.h"
extern void help(char *name); /* This is mandatory in all tools */
void tools_getopt_d_i(int argc, char **argv,
int *dev, int *index)
{
char *rest;
int opt;
while ((opt = getopt(argc, argv, "d:i:h")) != -1) {
switch (opt) {
case 'i':
*index = strtol(optarg, &rest, 0);
if (rest && *rest) {
fprintf(stderr, "%s: Not a number \"%s\"\n",
argv[0], optarg);
exit(1);
}
break;
case 'd':
*dev = strtol(optarg, &rest, 0);
if (rest && *rest) {
fprintf(stderr, "%s: Not a number \"%s\"\n",
argv[0], optarg);
exit(1);
}
break;
case 'h':
help(argv[0]);
}
}
}
int tools_need_help(int argc, char **argv)
{
if (argc != 2)
return 0;
if (!strcmp(argv[1], "--help"))
return 1;
return 0;
}
void report_time(char *name, struct fdelay_time *t)
{
printf(" %s utc %10lli, coarse %9li, frac %9li\n",
name, (long long)t->utc, (long)t->coarse, (long)t->frac);
}
void tools_report_action(int channel, struct fdelay_pulse *p)
{
char *mode;
char s[80];
if (p->mode == FD_OUT_MODE_DISABLED) mode = "disable";
else if (p->mode == FD_OUT_MODE_PULSE) mode = "pulse";
else if (p->mode == FD_OUT_MODE_DELAY) mode = "delay";
else if (p->mode == 0x80) mode = "already-triggered";
else {
sprintf(s, "%i (0x%04x)", p->mode, p->mode);
mode = s;
}
printf("Channel %i, mode %s, repeat %i %s\n",
FDELAY_OUTPUT_HW_TO_USER(channel), mode,
p->rep, p->rep == -1 ? "(infinite)" : "");
report_time("start", &p->start);
report_time("end ", &p->end);
report_time("loop ", &p->loop);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment