| 12
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 
 |  
 
//Variables
public: 
	typedef struct
	{
		wchar_t* id;
		wchar_t* txt_translate; 
		wchar_t* txt_comment;
	} S_LANG_ELEMENTS;
 
public:	
	wchar_t* file_buffer; // file data
	long lSize;
#ifdef C_STYLE
	S_LANG_ELEMENTS *gl_arr;
#else
	S_LANG_ELEMENTS S_L_E; 
	vector<S_LANG_ELEMENTS> LANG_VECTOR;
#endif
	int cnt_line;	
 
//Init variables	
		lSize		= 0; //size of file
		cnt_line	= 0;
		file_buffer = NULL;
 
#ifdef C_STYLE
		gl_arr = (S_LANG_ELEMENTS*)calloc(2000, sizeof(S_LANG_ELEMENTS)); //ALLOCATION STATIQUE
#else
		; //dynamique , voir code
#endif		
 
 
//CODE		
		char* filename="fichier.txt";
		FILE* streaminit=NULL;
		int file_manip=1;
 
		if((streaminit = fopen(file_name, "rb"))==NULL)
		{                            
			return -1;                                                               
		} 
 
		fseek (streaminit , 0 , SEEK_END);
		lSize = ftell (streaminit);
		file_manip= fseek(streaminit,0L,0);
 
		if(file_buffer!=NULL) { free(file_buffer); }
		file_buffer =(wchar_t*) calloc ( lSize+100 , sizeof (wchar_t));
 
		file_manip=fseek(streaminit, 2L, SEEK_SET);
 
		fread (file_buffer,1,lSize,streaminit);
		fclose(streaminit);
 
		//display
		char *p= setlocale( LC_ALL, "" ); //Pour que wprintf puisse afficher 
										  //tout le contenu du fichier car ne reconnait pas le ¦
		printf("\n<Contain of file_buffer>\n");
		wprintf(L"%ls",file_buffer); 
		printf("\n</Contain of file_buffer>\n\n");
 
		//PARSING
		int cnt_field=0;	
		int count_little=0;
		bool start_of_line =true;
		bool front_of_line=false;
		bool with_comment=false;
 
		for(unsigned int count_char =0; count_char<(unsigned int)lSize; count_char++)
		{
 
				count_little++;
				if((file_buffer[count_char]==0x23)) // #
				{
					while(file_buffer[count_char]!=0x0A)
					{
						count_char++;
					}
					cnt_field =0;
					count_little=0;
					file_buffer[count_char] =0;
					start_of_line=true; 
					with_comment=true;
				}
				if((file_buffer[count_char]==0x2551)&& ((count_little==0)||(count_little==1))) // minimum id_number character is 1 //2C (comma) => 7C (pipe) => BA (double pipe)
				{
					while(file_buffer[count_char]!=0x0A)
					{
						count_char++;
					}
					cnt_field =0;
					file_buffer[count_char] =0;
					count_little=0;
					start_of_line=true;
					with_comment=true;
				}
				else if((file_buffer[count_char]==0x2551)/*&&((file_buffer[count_char+1]==0xAB)||(file_buffer[count_char-1]==0xBB))*/) // xxxx,xxxx //2C (comma) => 7C (pipe) => BA (double pipe)
				{
					file_buffer[count_char] =0;
 
					if(cnt_field==0)
					{
	#ifdef C_STYLE
						gl_arr[cnt_line].txt_translate = &file_buffer[count_char+1]; //
	#else
						S_L_E.txt_translate =  &file_buffer[count_char+1]; //
						//LANG_VECTOR.push_back(S_L_E);
	#endif
						printf("1) count_char=%d \n", count_char);					
					}
					if(cnt_field==1)
					{
						file_buffer[count_char] =0;//
	#ifdef C_STYLE
						gl_arr[cnt_line].txt_comment = &file_buffer[count_char+1]; 
	#else
						S_L_E.txt_comment =  &file_buffer[count_char+1];
						//LANG_VECTOR.push_back(S_L_E);
	#endif
						printf("2) count_char=%d \n", :ccool:count_char);
					}
 
					++cnt_field;
					start_of_line=false; 
				}
 
				if((start_of_line==true)&&((count_little==0)||(count_little==1)||(count_little==2))) // first id_number
				{
					cnt_field =0;
 
					if(with_comment==true)
					{
	#ifdef C_STYLE
						gl_arr[cnt_line].id = &file_buffer[count_char+1];
	#else
						S_L_E.id =  &file_buffer[count_char+1];
						//LANG_VECTOR.push_back(S_L_E);
	#endif
					}
					else
					{
	#ifdef C_STYLE
						gl_arr[cnt_line].id = &file_buffer[count_char];
	#else
						S_L_E.id =  &file_buffer[count_char];
						//LANG_VECTOR.push_back(S_L_E);
	#endif
 
					}
					start_of_line=false;
 
				}
				else if((front_of_line==true)&&((count_little==0)||(count_little==1))) // id_number
				{
					//LANG_VECTOR.push_back(S_L_E); //HERE
					cnt_field =0;
	#ifdef C_STYLE
					gl_arr[cnt_line].id = &file_buffer[count_char];
	#else
					S_L_E.id =  &file_buffer[count_char];
					//LANG_VECTOR.push_back(S_L_E);
	#endif
					front_of_line=false;
 
				}
 
				if((file_buffer[count_char]==0x0A)&&(!(count_little<=2))) // LF
				{
					cnt_field =0;
					++cnt_line;
 
					file_buffer[count_char-1] =0; // disable because single only for translate
					file_buffer[count_char] =0;
	#ifdef C_STYLE
					gl_arr[cnt_line].id = &file_buffer[count_char+1];
	#else	
					S_L_E.id =  &file_buffer[count_char+1];
					LANG_VECTOR.push_back(S_L_E);//HERE ONLY
	#endif	
					count_little=0 ; 
					front_of_line=true;
					printf("0) count_char=%d\n", count_char);
					printf("\n");
				}
				else if((file_buffer[count_char]==0x0A)) // LF
				{
					cnt_field =0;
					count_little=0 ; 
					front_of_line=true;
				}
 
				if((file_buffer[count_char]==0x09)&&(count_little<=2)) // TAB
				{
 
					while(file_buffer[count_char]!=0x0A)
					{
						count_char++;
					}
 
					file_buffer[count_char] =0;
					cnt_field =0;
					count_little=0 ; 
					front_of_line=true;
				}
		}
 
			//display
			wprintf(L"lignes comptees =%d\n", cnt_line);
 
#ifdef C_STYLE	
			printf("Display en C style (tableau de char)\n");
			printf("-------------\n");
 
			for(int line=0;line<cnt_line;++line)
			{	
				wprintf(L"  ");
				wprintf(L"	id=%-8s ",  gl_arr[line].id);
				wprintf(L"	txt=%-10s ", gl_arr[line].txt_translate);
				wprintf(L"	cmt=%-10s ", gl_arr[line].txt_comment);
				wprintf(L"\n");
			}
			printf("-------------\n");
#else
			printf("Display en C++ (vector)\n");
			printf("-------------\n");
			std::vector<S_LANG_ELEMENTS>::const_iterator is;
 
			if (LANG_VECTOR.empty()) // Si le vector est vide
			{
				std::cout << "Il n'y a pas d'elements." << endl;
			}
 
			for (is = LANG_VECTOR.begin() ; is != LANG_VECTOR.end() ; ++is)
			{
				std::cout<<"id=";
				std::wcout<<is->id;
				std::cout<<"   translate=";
				std::wcout<<is->txt_translate;
				std::cout<<"   com=";
				std::wcout<<is->txt_comment;
				std::cout<<endl;
			} 
			printf("-------------\n");	
 
#endif | 
Partager