summaryrefslogtreecommitdiffstats
path: root/runtime/stpd/stp_dump.c
blob: 74dbc01290c0aac4b97fc15510aee2ad98373fa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * stp_dump.c - stp data dump program
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Copyright (C) Redhat Inc, 2005
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

static void usage (char *prog)
{
	fprintf(stderr, "%s input_file \n", prog);
	exit(1);
}

#define TIMESTAMP_SIZE 11

int main (int argc, char *argv[])
{
	char buf[32];
	int c, seq, lastseq = 0;
	FILE *fp;

	if (argc != 2)
	  usage(argv[0]);

	fp = fopen(argv[1], "r");
	if (!fp) {
	  fprintf(stderr, "ERROR: couldn't open input file %s: errcode = %s\n",
		  argv[1], strerror(errno));
	  return -1;
	}
	
	while (1) {
	  int numbytes = 0;

	  if (fread (buf, TIMESTAMP_SIZE, 1, fp))
	    seq = strtoul (buf, NULL, 10);
	  else
	    break;

	  if (seq < lastseq)
	    fprintf(stderr, "WARNING: seq %d followed by %d\n", lastseq, seq);
	  lastseq = seq;

	  while (1) {
	    c = fgetc_unlocked(fp);
	    if (c == 0 || c == EOF)
	      break;
	    numbytes++;
	  }
	  printf ("<%d><%d BYTES>", seq, numbytes);
	  if (c == 0)
	    printf ("<0>\n");
	  else {
	    printf ("<EOF>\n");
	    break;
	  }
	}

	printf ("DONE\n");
	fclose (fp);
	return 0;
}