LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cnvlog.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <string.h>
3 
4 #define ULONG unsigned int
5 #define UBYTE unsigned char
6 
7 int main(int argc,char *argv[])
8 {
9  FILE *pFileIn;
10  FILE *pFileOut;
11  char Buffer[255];
12  int State;
13  int Datas;
14  int Data;
15  int Bytes;
16  ULONG Result;
17  float *pData;
18  UBYTE Byte;
19 
20 
21  if (argc > 2)
22  {
23  pFileIn = fopen(argv[1],"rb");
24  if (pFileIn != NULL)
25  {
26  pFileOut = fopen(argv[2],"wb");
27  if (pFileOut != NULL)
28  {
29  State = 0;
30  while (fread(&Byte,1,1,pFileIn) == 1)
31  {
32  switch (State)
33  {
34  case 0 :
35  {
36  fwrite(&Byte,1,1,pFileOut);
37  if (Byte == '\n')
38  {
39  Datas = 0;
40  State++;
41  }
42  }
43  break;
44 
45  case 1 :
46  {
47  fwrite(&Byte,1,1,pFileOut);
48  if (Byte == '\t')
49  {
50  Datas++;
51  }
52  if (Byte == '\n')
53  {
54  Datas++;
55  Data = 0;
56  Bytes = 0;
57  State++;
58  }
59  }
60  break;
61 
62  default :
63  {
64  if (Bytes == 0)
65  {
66  Result = (ULONG)Byte;
67  }
68  else
69  {
70  Result |= (ULONG)Byte << (8 * Bytes);
71  }
72  if (++Bytes >= 4)
73  {
74  if (Result != 0xFFFFFFFF)
75  {
76  pData = (float*)&Result;
77  if (Data == 0)
78  {
79  sprintf(Buffer,"%08.0f",*pData);
80  }
81  else
82  {
83  sprintf(Buffer,"%.1f",*pData);
84  }
85  fwrite(Buffer,strlen(Buffer),1,pFileOut);
86  if (++Data >= Datas)
87  {
88  fwrite("\r\n",2,1,pFileOut);
89  Data = 0;
90  }
91  else
92  {
93  fwrite("\t",1,1,pFileOut);
94  }
95  }
96  else
97  {
98  if (++Data >= 2)
99  {
100  fwrite("******************************************************************************************\r\n",92,1,pFileOut);
101  State = 0;
102  }
103  }
104  Bytes = 0;
105  }
106  }
107  break;
108 
109  }
110  }
111  fclose(pFileOut);
112  }
113  fclose(pFileIn);
114  }
115  }
116  else
117  {
118  printf("\r\nUsage cnvlog filein fileout\r\n\n");
119  }
120  return (0);
121 }
#define ULONG
Definition: cnvlog.c:4
unsigned int ULONG
Basic Type used to symbolise 32 bit unsigned values.
Definition: lmstypes.h:31
int main(int argc, char *argv[])
Definition: cnvlog.c:7
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
Definition: lmstypes.h:29
char Buffer[1024]
Definition: c_wifi.c:102
#define NULL