Skip to content

Commit

Permalink
Some changes in the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jacketizer committed Mar 18, 2016
1 parent 90c798b commit d5165de
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -82,7 +82,7 @@ To parse an NMEA sentence string, use `nmea_parse()`:
```C
// Sentence string to be parsed
char *sentence = strdup("$GPGLL,4916.45,N,12311.12,W,225444,A,*1D\n\n");
char sentence[] = "$GPGLL,4916.45,N,12311.12,W,225444,A,*1D\n\n";
// Pointer to struct containing the parsed data
nmea_s *data;
Expand Down
3 changes: 1 addition & 2 deletions examples/minimum.c
Expand Up @@ -11,7 +11,7 @@ int
main(void)
{
// Sentence string to be parsed
char *sentence = strdup("$GPGLL,4916.45,N,12311.12,W,225444,A\n\n");
char sentence[] = "$GPGLL,4916.45,N,12311.12,W,225444,A\n\n";

printf("Parsing NMEA sentence: %s", sentence);

Expand All @@ -36,7 +36,6 @@ main(void)
}

nmea_free(data);
free(sentence);

return 0;
}
15 changes: 5 additions & 10 deletions examples/parse_stdin.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand All @@ -10,7 +11,7 @@
#include <nmea/gpgga.h>
#include <nmea/gprmc.h>

char *buffer;
char buffer[4096];
int gps_fd;

/**
Expand All @@ -23,7 +24,6 @@ void
sig_quit(int signum)
{
close(gps_fd);
free(buffer);
exit(EXIT_SUCCESS);
}

Expand Down Expand Up @@ -58,11 +58,6 @@ main(void)
char *start, *end;
sigset_t block_mask;

buffer = malloc(4096);
if (NULL == buffer) {
perror("malloc buffer");
exit(EXIT_FAILURE);
}

gps_fd = 0; // stdin

Expand All @@ -78,6 +73,9 @@ main(void)
}

while (1) {
char buf[255];
nmea_s *data;

/* Unlock signal */
sigprocmask(SIG_UNBLOCK, &block_mask, NULL);

Expand Down Expand Up @@ -109,9 +107,6 @@ main(void)
}

/* handle data */
char buf[255];
nmea_s *data;

data = nmea_parse(start, end - start + 1, 0);
if (NULL != data) {
if (0 < data->errors) {
Expand Down
16 changes: 5 additions & 11 deletions tests/systest.c
Expand Up @@ -2,6 +2,7 @@
// Should be used together with valgrind to check for memory leaks.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand All @@ -14,20 +15,17 @@
int
main(void)
{
char *buffer;
char buffer[4096];
int gps_fd = 0; // stdin
int read_bytes = 0;
int total_bytes = 0;
char *start, *end;
sigset_t block_mask;

buffer = malloc(4096);
if (NULL == buffer) {
perror("malloc buffer");
exit(EXIT_FAILURE);
}

while (1) {
char buf[255];
nmea_s *data;

read_bytes = read(gps_fd, buffer + total_bytes, 20);
if (-1 == read_bytes) {
perror("read stdin");
Expand All @@ -53,9 +51,6 @@ main(void)
}

/* handle data */
char buf[255];
nmea_s *data;

data = nmea_parse(start, end - start + 1, 0);
if (NULL != data) {
if (0 < data->errors) {
Expand Down Expand Up @@ -103,6 +98,5 @@ main(void)
total_bytes -= end - buffer;
}

free(buffer);
return 0;
}

0 comments on commit d5165de

Please sign in to comment.