source: src/lib/iotools.h @ 5f4d9c3

Last change on this file since 5f4d9c3 was 5f4d9c3, checked in by Maciej Prill <mprill@…>, 12 years ago

Rewritten the build system, added lem UTF-8 version.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1#include "const.h"
2#include <cstring>
3#include <cstdio>
4#include <cstring>
5#include <cstdlib>
6#include <cwchar>
7#include <iostream>
8#include <sstream>
9
10// napisy zostaj na miejscu (w line), tylko wskazniki sa ustawian
11// i zara dopisywane zera s dopisywane
12
13inline
14int parsetok(char* line, int* a, int* b, char** c, char** d, char** e, char** f)
15{
16  char* field;
17  if((field=strtok(line,FIELD_SEP))!=NULL)
18    *a=atoi(field); // nie sprawdzana poprawnosc
19  else
20    return 0;
21  if((field=strtok(NULL,FIELD_SEP))!=NULL)
22    *b=atoi(field); // nie sprawdzana poprawnosc
23  else return 1;
24  if((*c=strtok(NULL,FIELD_SEP))==NULL) return 2;
25  if((*d=strtok(NULL,FIELD_SEP))==NULL) return 3;
26  if((*e=strtok(NULL,FIELD_SEP))==NULL) return 4;
27  if((*f=strtok(NULL,FIELD_SEP))==NULL) return 6;
28  return 6;
29}
30// wchar_t version
31int parsetok(wchar_t* line, int* a, int* b, wchar_t** c, wchar_t** d, wchar_t** e, wchar_t** f)
32{
33  wchar_t* field;
34  if((field=wcstok(line,WFIELD_SEP,NULL))!=NULL)
35  {
36    std::wistringstream s(field);
37    int i = 0;
38    s >> i;
39    *a=i; // nie sprawdzana poprawnosc
40  }
41  else
42    return 0;
43  if((field=wcstok(NULL,WFIELD_SEP,NULL))!=NULL)
44  {
45    std::wistringstream k(field);
46    int j = 0;
47    k >> j;
48    *b=j; // nie sprawdzana poprawnosc
49  }
50  else return 1;
51  if((*c=wcstok(NULL,WFIELD_SEP,NULL))==NULL) return 2;
52  if((*d=wcstok(NULL,WFIELD_SEP,NULL))==NULL) return 3;
53  if((*e=wcstok(NULL,WFIELD_SEP,NULL))==NULL) return 4;
54  if((*f=wcstok(NULL,WFIELD_SEP,NULL))==NULL) return 6;
55  return 6;
56}
57// napisy s kopiowane
58inline
59int scantok(const char* line, int* a, int* b, char* c, char* d, char* e=NULL, char* f=NULL)
60{
61  return sscanf(line," %d %d %s %s %s %s", a, b, c, d, e, f);
62}
63
64// wchar_t version
65inline
66int scantok(const wchar_t* line, int* a, int* b, wchar_t* c, wchar_t* d, wchar_t* e=NULL, wchar_t* f=NULL)
67{
68  return swscanf(line,L" %d %d %ls %ls %ls %ls", a, b, c, d, e, f);
69}
70
71inline
72int printtok(char* line, int a, int b, char* c, char* d, char* e, char* f, char* parms)
73{
74  sprintf(line,"%04d %02d %s %s %s %s `%s\n", a, b, c, d, e, f, parms);
75}
76
77// wchar_t version
78inline
79int printtok(wchar_t* line, int a, int b, wchar_t* c, wchar_t* d, wchar_t* e, wchar_t* f, wchar_t* parms)
80{
81  swprintf(line,MAX_LINE,L"%04d %02d %ls %ls %ls %ls `%ls\n", a, b, c, d, e, f, parms);
82}
83
84inline
85int printtok(char* line, int a, int b, char* c, char* d, char* e, char* f)
86{
87  sprintf(line,"%04d %02d %s %s %s %s\n", a, b, c, d, e, f);
88}
89
90// wchar_t version
91inline
92int printtok(wchar_t* line, int a, int b, wchar_t* c, wchar_t* d, wchar_t* e, wchar_t* f)
93{
94  swprintf(line,MAX_LINE,L"%04d %02d %ls %ls %ls %ls\n", a, b, c, d, e, f);
95}
96
97inline
98int printtok(char* line, int a, int b, char* c, char* d)
99{
100  sprintf(line,"%04d %02d %s %s\n", a, b, c, d);
101}
102
103// wchar_t version
104inline
105int printtok(wchar_t* line, int a, int b, wchar_t* c, wchar_t* d)
106{
107  swprintf(line,MAX_LINE,L"%04d %02d %ls %ls\n", a, b, c, d);
108}
Note: See TracBrowser for help on using the repository browser.