Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
promise
OpenXG-RAN
Commits
fe808cc3
Commit
fe808cc3
authored
Mar 15, 2016
by
Cedric Roux
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a database of groups to, well, group IDs
parent
75b827f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
224 additions
and
2 deletions
+224
-2
tracer/Makefile
tracer/Makefile
+1
-1
tracer/defs.h
tracer/defs.h
+4
-0
tracer/main.c
tracer/main.c
+6
-1
tracer/t_data.c
tracer/t_data.c
+213
-0
No files found.
tracer/Makefile
View file @
fe808cc3
...
...
@@ -8,7 +8,7 @@ CFLAGS += -DT_USE_SHARED_MEMORY
LIBS
+=
-lrt
PROG
=
tracer
OBJS
=
main.o plot.o
OBJS
=
main.o plot.o
t_data.o
$(PROG)
:
$(OBJS)
$(CC)
$(CFLAGS)
-o
$(PROG)
$(OBJS)
$(LIBS)
...
...
tracer/defs.h
View file @
fe808cc3
...
...
@@ -5,4 +5,8 @@ void *make_plot(int width, int height, int bufsize);
void
plot_set
(
void
*
plot
,
float
*
data
,
int
len
,
int
pos
);
void
iq_plot_set
(
void
*
plot
,
short
*
data
,
int
len
,
int
pos
);
/* returns an opaque pointer - truly a 'database *', see t_data.c */
void
*
parse_database
(
char
*
filename
);
void
dump_database
(
void
*
database
);
#endif
/* _TRACER_DEFS_H_ */
tracer/main.c
View file @
fe808cc3
...
...
@@ -257,11 +257,16 @@ void init_shm(void)
#endif
/* T_USE_SHARED_MEMORY */
int
main
(
void
)
int
main
(
int
n
,
char
**
v
)
{
void
*
database
;
int
s
;
int
l
;
char
t
;
database
=
parse_database
(
"../T_messages.txt"
);
dump_database
(
database
);
#ifdef T_USE_SHARED_MEMORY
init_shm
();
#endif
...
...
tracer/t_data.c
0 → 100644
View file @
fe808cc3
#include "defs.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
typedef
struct
{
char
*
name
;
char
*
desc
;
}
id
;
typedef
struct
{
char
*
name
;
char
**
ids
;
int
size
;
}
group
;
typedef
struct
{
id
*
i
;
int
isize
;
group
*
g
;
int
gsize
;
}
database
;
typedef
struct
{
char
*
data
;
int
size
;
int
maxsize
;
}
buffer
;
typedef
struct
{
buffer
name
;
buffer
value
;
}
parser
;
void
put
(
buffer
*
b
,
int
c
)
{
if
(
b
->
size
==
b
->
maxsize
)
{
b
->
maxsize
+=
256
;
b
->
data
=
realloc
(
b
->
data
,
b
->
maxsize
);
if
(
b
->
data
==
NULL
)
{
printf
(
"memory allocation error
\n
"
);
exit
(
1
);
}
}
b
->
data
[
b
->
size
]
=
c
;
b
->
size
++
;
}
void
smash_spaces
(
FILE
*
f
)
{
int
c
;
while
(
1
)
{
c
=
fgetc
(
f
);
if
(
isspace
(
c
))
continue
;
if
(
c
==
' '
)
continue
;
if
(
c
==
'\t'
)
continue
;
if
(
c
==
'\n'
)
continue
;
if
(
c
==
10
||
c
==
13
)
continue
;
if
(
c
==
'#'
)
{
while
(
1
)
{
c
=
fgetc
(
f
);
if
(
c
==
'\n'
||
c
==
EOF
)
break
;
}
continue
;
}
break
;
}
if
(
c
!=
EOF
)
ungetc
(
c
,
f
);
}
void
get_line
(
parser
*
p
,
FILE
*
f
,
char
**
name
,
char
**
value
)
{
int
c
;
p
->
name
.
size
=
0
;
p
->
value
.
size
=
0
;
*
name
=
NULL
;
*
value
=
NULL
;
smash_spaces
(
f
);
c
=
fgetc
(
f
);
while
(
!
(
c
==
'='
||
isspace
(
c
)
||
c
==
EOF
))
{
put
(
&
p
->
name
,
c
);
c
=
fgetc
(
f
);
}
if
(
c
==
EOF
)
return
;
put
(
&
p
->
name
,
0
);
while
(
!
(
c
==
EOF
||
c
==
'='
))
c
=
fgetc
(
f
);
if
(
c
==
EOF
)
return
;
smash_spaces
(
f
);
c
=
fgetc
(
f
);
while
(
!
(
c
==
10
||
c
==
13
||
c
==
EOF
))
{
put
(
&
p
->
value
,
c
);
c
=
fgetc
(
f
);
}
put
(
&
p
->
value
,
0
);
if
(
p
->
name
.
size
<=
1
)
return
;
if
(
p
->
value
.
size
<=
1
)
return
;
*
name
=
p
->
name
.
data
;
*
value
=
p
->
value
.
data
;
}
void
add_id
(
database
*
r
,
char
*
id
)
{
if
((
r
->
isize
&
1023
)
==
0
)
{
r
->
i
=
realloc
(
r
->
i
,
(
r
->
isize
+
1024
)
*
sizeof
(
id
));
if
(
r
->
i
==
NULL
)
{
printf
(
"out of memory
\n
"
);
exit
(
1
);
}
}
r
->
i
[
r
->
isize
].
name
=
strdup
(
id
);
if
(
r
->
i
[
r
->
isize
].
name
==
NULL
)
{
printf
(
"out of memory
\n
"
);
exit
(
1
);
}
r
->
isize
++
;
}
int
group_cmp
(
const
void
*
_p1
,
const
void
*
_p2
)
{
const
group
*
p1
=
_p1
;
const
group
*
p2
=
_p2
;
return
strcmp
(
p1
->
name
,
p2
->
name
);
}
group
*
get_group
(
database
*
r
,
char
*
group_name
)
{
group
gsearch
;
group
*
ret
;
gsearch
.
name
=
group_name
;
ret
=
bsearch
(
&
gsearch
,
r
->
g
,
r
->
gsize
,
sizeof
(
group
),
group_cmp
);
if
(
ret
!=
NULL
)
return
ret
;
if
((
r
->
gsize
&
1023
)
==
0
)
{
r
->
g
=
realloc
(
r
->
g
,
(
r
->
gsize
+
1024
)
*
sizeof
(
group
));
if
(
r
->
g
==
NULL
)
abort
();
}
r
->
g
[
r
->
gsize
].
name
=
strdup
(
group_name
);
if
(
r
->
g
[
r
->
gsize
].
name
==
NULL
)
abort
();
r
->
g
[
r
->
gsize
].
ids
=
NULL
;
r
->
g
[
r
->
gsize
].
size
=
0
;
r
->
gsize
++
;
qsort
(
r
->
g
,
r
->
gsize
,
sizeof
(
group
),
group_cmp
);
return
bsearch
(
&
gsearch
,
r
->
g
,
r
->
gsize
,
sizeof
(
group
),
group_cmp
);
}
void
group_add_id
(
group
*
g
,
char
*
id
)
{
if
((
g
->
size
&
1023
)
==
0
)
{
g
->
ids
=
realloc
(
g
->
ids
,
(
g
->
size
+
1024
)
*
sizeof
(
char
*
));
if
(
g
->
ids
==
NULL
)
abort
();
}
g
->
ids
[
g
->
size
]
=
id
;
g
->
size
++
;
}
void
add_groups
(
database
*
r
,
char
*
groups
)
{
group
*
g
;
while
(
1
)
{
char
*
start
=
groups
;
char
*
end
=
start
;
while
(
!
isspace
(
*
end
)
&&
*
end
!=
':'
&&
*
end
!=
0
)
end
++
;
if
(
end
==
start
)
{
printf
(
"bad group line: groups are seperated by ':'
\n
"
);
abort
();
}
if
(
*
end
==
0
)
end
=
NULL
;
else
*
end
=
0
;
g
=
get_group
(
r
,
start
);
group_add_id
(
g
,
r
->
i
[
r
->
isize
-
1
].
name
);
if
(
end
==
NULL
)
break
;
end
++
;
while
((
isspace
(
*
end
)
||
*
end
==
':'
)
&&
*
end
!=
0
)
end
++
;
if
(
*
end
==
0
)
break
;
groups
=
end
;
}
}
void
*
parse_database
(
char
*
filename
)
{
FILE
*
in
;
parser
p
;
database
*
r
;
char
*
name
,
*
value
;
r
=
calloc
(
1
,
sizeof
(
*
r
));
if
(
r
==
NULL
)
abort
();
memset
(
&
p
,
0
,
sizeof
(
p
));
in
=
fopen
(
filename
,
"r"
);
if
(
in
==
NULL
)
{
perror
(
filename
);
abort
();
}
while
(
1
)
{
get_line
(
&
p
,
in
,
&
name
,
&
value
);
if
(
name
==
NULL
)
break
;
printf
(
"%s %s
\n
"
,
name
,
value
);
if
(
!
strcmp
(
name
,
"ID"
))
add_id
(
r
,
value
);
if
(
!
strcmp
(
name
,
"GROUP"
))
add_groups
(
r
,
value
);
}
fclose
(
in
);
free
(
p
.
name
.
data
);
free
(
p
.
value
.
data
);
return
r
;
}
void
dump_database
(
void
*
_d
)
{
database
*
d
=
_d
;
int
i
;
printf
(
"database: %d IDs, %d GROUPs
\n
"
,
d
->
isize
,
d
->
gsize
);
for
(
i
=
0
;
i
<
d
->
isize
;
i
++
)
printf
(
"ID %s [%s]
\n
"
,
d
->
i
[
i
].
name
,
d
->
i
[
i
].
desc
);
for
(
i
=
0
;
i
<
d
->
gsize
;
i
++
)
{
int
j
;
printf
(
"GROUP %s [size %d]
\n
"
,
d
->
g
[
i
].
name
,
d
->
g
[
i
].
size
);
for
(
j
=
0
;
j
<
d
->
g
[
i
].
size
;
j
++
)
printf
(
" ID %s
\n
"
,
d
->
g
[
i
].
ids
[
j
]);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment