convert from svn repository: remove tags directory
[lttv.git] / trunk / masters-pmf / java_speed_test / c / main.c
CommitLineData
4ef69136 1#define _LARGEFILE_SOURCE
2#define _FILE_OFFSET_BITS 64
3
f65716cf 4#include <sys/types.h>
5#include <sys/stat.h>
6#include <fcntl.h>
7#include <unistd.h>
8
9#include <stdio.h>
10#include <stdlib.h>
ce68a724 11#include <string.h>
f65716cf 12
ce68a724 13int main(int argc, char **argv)
f65716cf 14{
15 int result;
4ef69136 16 FILE *fp;
ce68a724 17 int print = 0;
7d1dd76a 18 int i;
19 char *filename = NULL;
20
21 if(argc > 1) {
22 for(i=1; i<argc; i++) {
23 if(!strcmp(argv[i], "-p")) {
24 print = 1;
25 }
26 else {
27 filename = argv[i];
28 }
29 }
30 }
ce68a724 31
7d1dd76a 32 if(filename == NULL) {
33 fprintf(stderr, "No trace file specified\n");
34 return 1;
35 }
f65716cf 36
7d1dd76a 37 fp = fopen(filename, "r");
4ef69136 38 if(fp == NULL) {
39 perror("fopen");
f65716cf 40 return 1;
41 }
42
43 while(1) {
44 unsigned long timestamp;
45 unsigned short id;
46 unsigned char arglen;
47 char *args;
48
4ef69136 49 fscanf(fp, "%4c", &timestamp);
50 if(feof(fp))
f65716cf 51 break;
4ef69136 52
53 fscanf(fp, "%2c", &id);
54
55 fscanf(fp, "%1c", &arglen);
f65716cf 56
57 args = malloc(arglen);
58
4ef69136 59 // manually specify length of args
60 fscanf(fp, "%15c", args);
f65716cf 61
62 unsigned short arg1;
63 char *arg2;
64
65 arg1 = *(unsigned short *)args;
66 arg2 = args+2;
67
ce68a724 68 if(print)
69 printf("timestamp %lu id %hu args=(arg1=%hu arg2=\"%s\")\n", timestamp, id, arg1, arg2);
f65716cf 70
71 free(args);
4ef69136 72
f65716cf 73 }
4ef69136 74 fclose(fp);
f65716cf 75
76 return 0;
77}
This page took 0.026691 seconds and 4 git commands to generate.