[5f4d9c3] | 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 | |
---|
| 13 | inline |
---|
| 14 | int 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 |
---|
| 31 | int 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 |
---|
| 58 | inline |
---|
| 59 | int 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 |
---|
| 65 | inline |
---|
| 66 | int 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 | |
---|
| 71 | inline |
---|
| 72 | int 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 |
---|
| 78 | inline |
---|
| 79 | int 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 | |
---|
| 84 | inline |
---|
| 85 | int 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 |
---|
| 91 | inline |
---|
| 92 | int 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 | |
---|
| 97 | inline |
---|
| 98 | int 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 |
---|
| 104 | inline |
---|
| 105 | int 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 | } |
---|