convert from svn repository: remove tags directory
[lttv.git] / trunk / masters-pmf / java_speed_test / c / main.c
1 #define _LARGEFILE_SOURCE
2 #define _FILE_OFFSET_BITS 64
3
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>
11 #include <string.h>
12
13 int main(int argc, char **argv)
14 {
15 int result;
16 FILE *fp;
17 int print = 0;
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 }
31
32 if(filename == NULL) {
33 fprintf(stderr, "No trace file specified\n");
34 return 1;
35 }
36
37 fp = fopen(filename, "r");
38 if(fp == NULL) {
39 perror("fopen");
40 return 1;
41 }
42
43 while(1) {
44 unsigned long timestamp;
45 unsigned short id;
46 unsigned char arglen;
47 char *args;
48
49 fscanf(fp, "%4c", &timestamp);
50 if(feof(fp))
51 break;
52
53 fscanf(fp, "%2c", &id);
54
55 fscanf(fp, "%1c", &arglen);
56
57 args = malloc(arglen);
58
59 // manually specify length of args
60 fscanf(fp, "%15c", args);
61
62 unsigned short arg1;
63 char *arg2;
64
65 arg1 = *(unsigned short *)args;
66 arg2 = args+2;
67
68 if(print)
69 printf("timestamp %lu id %hu args=(arg1=%hu arg2=\"%s\")\n", timestamp, id, arg1, arg2);
70
71 free(args);
72
73 }
74 fclose(fp);
75
76 return 0;
77 }
This page took 0.03227 seconds and 4 git commands to generate.