Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_fileis 4 #ifndef tools_fileis 5 #define tools_fileis 5 #define tools_fileis 6 6 7 #include "signature" 7 #include "signature" 8 #include <cstring> 8 #include <cstring> 9 9 10 namespace tools { 10 namespace tools { 11 namespace file { 11 namespace file { 12 12 13 inline bool is_zip(const std::string& a_file,b 13 inline bool is_zip(const std::string& a_file,bool& a_is){ 14 unsigned char head[4]; 14 unsigned char head[4]; 15 {unsigned int num = 4; 15 {unsigned int num = 4; 16 if(!signature(a_file,head,num)) {a_is = fals 16 if(!signature(a_file,head,num)) {a_is = false;return false;} 17 if(num!=4) {a_is = false;return true;}} 17 if(num!=4) {a_is = false;return true;}} 18 if(head[0]!='P') {a_is = false;return true;} 18 if(head[0]!='P') {a_is = false;return true;} 19 if(head[1]!='K') {a_is = false;return true;} 19 if(head[1]!='K') {a_is = false;return true;} 20 if(head[2]!=3) {a_is = false;return true;} 20 if(head[2]!=3) {a_is = false;return true;} 21 if(head[3]!=4) {a_is = false;return true;} 21 if(head[3]!=4) {a_is = false;return true;} 22 a_is = true; 22 a_is = true; 23 return true; 23 return true; 24 } 24 } 25 25 26 inline bool is_jpeg(const std::string& a_file, 26 inline bool is_jpeg(const std::string& a_file,bool& a_is){ 27 unsigned char head[4]; 27 unsigned char head[4]; 28 {unsigned int num = 4; 28 {unsigned int num = 4; 29 if(!signature(a_file,head,num)) {a_is = fals 29 if(!signature(a_file,head,num)) {a_is = false;return false;} 30 if(num!=4) {a_is = false;return true;}} 30 if(num!=4) {a_is = false;return true;}} 31 if(head[0]!=255) {a_is = false;return true;} 31 if(head[0]!=255) {a_is = false;return true;} 32 if(head[1]!=216) {a_is = false;return true;} 32 if(head[1]!=216) {a_is = false;return true;} 33 if(head[2]!=255) {a_is = false;return true;} 33 if(head[2]!=255) {a_is = false;return true;} 34 //if(head[3]!=224) {a_is = false;return true 34 //if(head[3]!=224) {a_is = false;return true;} //LRI.jpg is 225 ! 35 a_is = true; 35 a_is = true; 36 return true; 36 return true; 37 } 37 } 38 38 39 inline bool is_ico(const std::string& a_file,b 39 inline bool is_ico(const std::string& a_file,bool& a_is){ 40 unsigned char head[4]; 40 unsigned char head[4]; 41 {unsigned int num = 4; 41 {unsigned int num = 4; 42 if(!signature(a_file,head,num)) {a_is = fals 42 if(!signature(a_file,head,num)) {a_is = false;return false;} 43 if(num!=4) {a_is = false;return true;}} 43 if(num!=4) {a_is = false;return true;}} 44 if(head[0]!=0) {a_is = false;return true;} 44 if(head[0]!=0) {a_is = false;return true;} 45 if(head[1]!=0) {a_is = false;return true;} 45 if(head[1]!=0) {a_is = false;return true;} 46 if(head[2]!=1) {a_is = false;return true;} 46 if(head[2]!=1) {a_is = false;return true;} 47 if(head[3]!=0) {a_is = false;return true;} 47 if(head[3]!=0) {a_is = false;return true;} 48 a_is = true; 48 a_is = true; 49 return true; 49 return true; 50 } 50 } 51 51 52 inline bool is_png(const std::string& a_file,b 52 inline bool is_png(const std::string& a_file,bool& a_is){ 53 unsigned char head[4]; 53 unsigned char head[4]; 54 {unsigned int num = 4; 54 {unsigned int num = 4; 55 if(!signature(a_file,head,num)) {a_is = fals 55 if(!signature(a_file,head,num)) {a_is = false;return false;} 56 if(num!=4) {a_is = false;return true;}} 56 if(num!=4) {a_is = false;return true;}} 57 if(head[0]!=137) {a_is = false;return true;} 57 if(head[0]!=137) {a_is = false;return true;} 58 if(head[1]!='P') {a_is = false;return true;} 58 if(head[1]!='P') {a_is = false;return true;} 59 if(head[2]!='N') {a_is = false;return true;} 59 if(head[2]!='N') {a_is = false;return true;} 60 if(head[3]!='G') {a_is = false;return true;} 60 if(head[3]!='G') {a_is = false;return true;} 61 a_is = true; 61 a_is = true; 62 return true; 62 return true; 63 } 63 } 64 64 65 inline bool is_root(const std::string& a_file, 65 inline bool is_root(const std::string& a_file,bool& a_is){ 66 unsigned char head[4]; 66 unsigned char head[4]; 67 {unsigned int num = 4; 67 {unsigned int num = 4; 68 if(!signature(a_file,head,num)) {a_is = fals 68 if(!signature(a_file,head,num)) {a_is = false;return false;} 69 if(num!=4) {a_is = false;return true;}} 69 if(num!=4) {a_is = false;return true;}} 70 if(head[0]!='r') {a_is = false;return true;} 70 if(head[0]!='r') {a_is = false;return true;} 71 if(head[1]!='o') {a_is = false;return true;} 71 if(head[1]!='o') {a_is = false;return true;} 72 if(head[2]!='o') {a_is = false;return true;} 72 if(head[2]!='o') {a_is = false;return true;} 73 if(head[3]!='t') {a_is = false;return true;} 73 if(head[3]!='t') {a_is = false;return true;} 74 a_is = true; 74 a_is = true; 75 return true; 75 return true; 76 } 76 } 77 77 78 inline bool is_iv(const std::string& a_file,bo 78 inline bool is_iv(const std::string& a_file,bool& a_is){ 79 unsigned char head[9]; 79 unsigned char head[9]; 80 {unsigned int num = 9; 80 {unsigned int num = 9; 81 if(!signature(a_file,head,num)) {a_is = fals 81 if(!signature(a_file,head,num)) {a_is = false;return false;} 82 if(num!=9) {a_is = false;return true;}} 82 if(num!=9) {a_is = false;return true;}} 83 if(head[0]!='#') {a_is = false;return true;} 83 if(head[0]!='#') {a_is = false;return true;} 84 if(head[1]!='I') {a_is = false;return true;} 84 if(head[1]!='I') {a_is = false;return true;} 85 if(head[2]!='n') {a_is = false;return true;} 85 if(head[2]!='n') {a_is = false;return true;} 86 if(head[3]!='v') {a_is = false;return true;} 86 if(head[3]!='v') {a_is = false;return true;} 87 if(head[4]!='e') {a_is = false;return true;} 87 if(head[4]!='e') {a_is = false;return true;} 88 if(head[5]!='n') {a_is = false;return true;} 88 if(head[5]!='n') {a_is = false;return true;} 89 if(head[6]!='t') {a_is = false;return true;} 89 if(head[6]!='t') {a_is = false;return true;} 90 if(head[7]!='o') {a_is = false;return true;} 90 if(head[7]!='o') {a_is = false;return true;} 91 if(head[8]!='r') {a_is = false;return true;} 91 if(head[8]!='r') {a_is = false;return true;} 92 a_is = true; 92 a_is = true; 93 return true; 93 return true; 94 } 94 } 95 95 96 inline bool is_wrl(const std::string& a_file,b 96 inline bool is_wrl(const std::string& a_file,bool& a_is){ 97 unsigned char head[5]; 97 unsigned char head[5]; 98 {unsigned int num = 5; 98 {unsigned int num = 5; 99 if(!signature(a_file,head,num)) {a_is = fals 99 if(!signature(a_file,head,num)) {a_is = false;return false;} 100 if(num!=5) {a_is = false;return true;}} 100 if(num!=5) {a_is = false;return true;}} 101 if(head[0]!='#') {a_is = false;return true;} 101 if(head[0]!='#') {a_is = false;return true;} 102 if(head[1]!='V') {a_is = false;return true;} 102 if(head[1]!='V') {a_is = false;return true;} 103 if(head[2]!='R') {a_is = false;return true;} 103 if(head[2]!='R') {a_is = false;return true;} 104 if(head[3]!='M') {a_is = false;return true;} 104 if(head[3]!='M') {a_is = false;return true;} 105 if(head[4]!='L') {a_is = false;return true;} 105 if(head[4]!='L') {a_is = false;return true;} 106 a_is = true; 106 a_is = true; 107 return true; 107 return true; 108 } 108 } 109 109 110 inline bool is_fog(const std::string& a_file,b 110 inline bool is_fog(const std::string& a_file,bool& a_is){ 111 unsigned char head[256]; 111 unsigned char head[256]; 112 {unsigned int num = 256; 112 {unsigned int num = 256; 113 if(!signature(a_file,head,num)) {a_is = fals 113 if(!signature(a_file,head,num)) {a_is = false;return false;} 114 if(num!=256) {a_is = false;return true;}} 114 if(num!=256) {a_is = false;return true;}} 115 head[255] = 0; //to have a C string. 115 head[255] = 0; //to have a C string. 116 a_is = ::strstr((const char*)head,"#nb super 116 a_is = ::strstr((const char*)head,"#nb super-volumes")?true:false; 117 return true; 117 return true; 118 } 118 } 119 119 120 inline bool is_dot(const std::string& a_file,b 120 inline bool is_dot(const std::string& a_file,bool& a_is){ 121 unsigned char head[8]; 121 unsigned char head[8]; 122 {unsigned int num = 7; 122 {unsigned int num = 7; 123 if(!signature(a_file,head,num)) {a_is = fals 123 if(!signature(a_file,head,num)) {a_is = false;return false;} 124 if(num!=7) {a_is = false;return true;}} 124 if(num!=7) {a_is = false;return true;}} 125 head[7] = 0; //to have a C string. 125 head[7] = 0; //to have a C string. 126 a_is = ::strcmp((const char*)head,"digraph") 126 a_is = ::strcmp((const char*)head,"digraph")?false:true; 127 return true; 127 return true; 128 } 128 } 129 129 130 inline bool is_dcm(const std::string& a_file,b 130 inline bool is_dcm(const std::string& a_file,bool& a_is){ 131 unsigned char head[132]; 131 unsigned char head[132]; 132 {unsigned int num = 132; 132 {unsigned int num = 132; 133 if(!signature(a_file,head,num)) {a_is = fals 133 if(!signature(a_file,head,num)) {a_is = false;return false;} 134 if(num!=132) {a_is = false;return true;}} 134 if(num!=132) {a_is = false;return true;}} 135 if(head[128]!='D') {a_is = false;return true 135 if(head[128]!='D') {a_is = false;return true;} 136 if(head[129]!='I') {a_is = false;return true 136 if(head[129]!='I') {a_is = false;return true;} 137 if(head[130]!='C') {a_is = false;return true 137 if(head[130]!='C') {a_is = false;return true;} 138 if(head[131]!='M') {a_is = false;return true 138 if(head[131]!='M') {a_is = false;return true;} 139 a_is = true; 139 a_is = true; 140 return true; 140 return true; 141 } 141 } 142 142 143 inline bool is_gdml(const std::string& a_file, 143 inline bool is_gdml(const std::string& a_file,bool& a_is){ 144 //NOTE : it assumes that the file is not com 144 //NOTE : it assumes that the file is not compressed. 145 unsigned char head[1024]; 145 unsigned char head[1024]; 146 {unsigned int num = 1024; 146 {unsigned int num = 1024; 147 if(!signature(a_file,head,num)) {a_is = fals 147 if(!signature(a_file,head,num)) {a_is = false;return false;} 148 if(num!=1024) {a_is = false;return true;}} 148 if(num!=1024) {a_is = false;return true;}} 149 head[1023] = 0; //to have a C string. 149 head[1023] = 0; //to have a C string. 150 a_is = ::strstr((const char*)head,"<gdml")?t 150 a_is = ::strstr((const char*)head,"<gdml")?true:false; 151 return true; 151 return true; 152 } 152 } 153 153 154 inline bool is_exsg(unsigned int a_sz,const ch 154 inline bool is_exsg(unsigned int a_sz,const char* a_buffer){ 155 if(a_sz<5) return false; 155 if(a_sz<5) return false; 156 if(a_buffer[0]!='<') return false; 156 if(a_buffer[0]!='<') return false; 157 if(a_buffer[1]!='e') return false; 157 if(a_buffer[1]!='e') return false; 158 if(a_buffer[2]!='x') return false; 158 if(a_buffer[2]!='x') return false; 159 if(a_buffer[3]!='s') return false; 159 if(a_buffer[3]!='s') return false; 160 if(a_buffer[4]!='g') return false; 160 if(a_buffer[4]!='g') return false; 161 return true; 161 return true; 162 } 162 } 163 163 164 inline bool is_exsg(const std::string& a_file, 164 inline bool is_exsg(const std::string& a_file,bool& a_is){ 165 unsigned char head[5]; 165 unsigned char head[5]; 166 {unsigned int num = 5; 166 {unsigned int num = 5; 167 if(!signature(a_file,head,num)) {a_is = fals 167 if(!signature(a_file,head,num)) {a_is = false;return false;} 168 if(num!=5) {a_is = false;return true;}} 168 if(num!=5) {a_is = false;return true;}} 169 a_is = is_exsg(5,(const char*)head); 169 a_is = is_exsg(5,(const char*)head); 170 return true; 170 return true; 171 } 171 } 172 172 173 inline bool is_bsg(unsigned int a_sz,const cha 173 inline bool is_bsg(unsigned int a_sz,const char* a_buffer){ 174 if(a_sz<7) return false; 174 if(a_sz<7) return false; 175 if(a_buffer[0]!='i') return false; 175 if(a_buffer[0]!='i') return false; 176 if(a_buffer[1]!='n') return false; 176 if(a_buffer[1]!='n') return false; 177 if(a_buffer[2]!='e') return false; 177 if(a_buffer[2]!='e') return false; 178 if(a_buffer[3]!='x') return false; 178 if(a_buffer[3]!='x') return false; 179 if(a_buffer[4]!='b') return false; 179 if(a_buffer[4]!='b') return false; 180 if(a_buffer[5]!='s') return false; 180 if(a_buffer[5]!='s') return false; 181 if(a_buffer[6]!='g') return false; 181 if(a_buffer[6]!='g') return false; 182 return true; 182 return true; 183 } 183 } 184 184 185 inline bool is_bsg(const std::string& a_file,b 185 inline bool is_bsg(const std::string& a_file,bool& a_is){ 186 unsigned char head[7]; 186 unsigned char head[7]; 187 {unsigned int num = 7; 187 {unsigned int num = 7; 188 if(!signature(a_file,head,num)) {a_is = fals 188 if(!signature(a_file,head,num)) {a_is = false;return false;} 189 if(num!=7) {a_is = false;return true;}} 189 if(num!=7) {a_is = false;return true;}} 190 a_is = is_bsg(7,(const char*)head); 190 a_is = is_bsg(7,(const char*)head); 191 return true; 191 return true; 192 } 192 } 193 193 194 inline bool is_scenarios(const std::string& a_ 194 inline bool is_scenarios(const std::string& a_file,bool& a_is){ 195 unsigned char head[10]; 195 unsigned char head[10]; 196 {unsigned int num = 10; 196 {unsigned int num = 10; 197 if(!signature(a_file,head,num)) {a_is = fals 197 if(!signature(a_file,head,num)) {a_is = false;return false;} 198 if(num!=10) {a_is = false;return true;}} 198 if(num!=10) {a_is = false;return true;}} 199 if(head[0]!='<') {a_is = false;return true;} 199 if(head[0]!='<') {a_is = false;return true;} 200 if(head[1]!='s') {a_is = false;return true;} 200 if(head[1]!='s') {a_is = false;return true;} 201 if(head[2]!='c') {a_is = false;return true;} 201 if(head[2]!='c') {a_is = false;return true;} 202 if(head[3]!='e') {a_is = false;return true;} 202 if(head[3]!='e') {a_is = false;return true;} 203 if(head[4]!='n') {a_is = false;return true;} 203 if(head[4]!='n') {a_is = false;return true;} 204 if(head[5]!='a') {a_is = false;return true;} 204 if(head[5]!='a') {a_is = false;return true;} 205 if(head[6]!='r') {a_is = false;return true;} 205 if(head[6]!='r') {a_is = false;return true;} 206 if(head[7]!='i') {a_is = false;return true;} 206 if(head[7]!='i') {a_is = false;return true;} 207 if(head[8]!='o') {a_is = false;return true;} 207 if(head[8]!='o') {a_is = false;return true;} 208 if(head[9]!='s') {a_is = false;return true;} 208 if(head[9]!='s') {a_is = false;return true;} 209 a_is = true; 209 a_is = true; 210 return true; 210 return true; 211 } 211 } 212 212 213 inline bool is_slides(const std::string& a_fil 213 inline bool is_slides(const std::string& a_file,bool& a_is){ 214 unsigned char head[7]; 214 unsigned char head[7]; 215 {unsigned int num = 7; 215 {unsigned int num = 7; 216 if(!signature(a_file,head,num)) {a_is = fals 216 if(!signature(a_file,head,num)) {a_is = false;return false;} 217 if(num!=7) {a_is = false;return true;}} 217 if(num!=7) {a_is = false;return true;}} 218 if(head[0]!='<') {a_is = false;return true;} 218 if(head[0]!='<') {a_is = false;return true;} 219 if(head[1]!='s') {a_is = false;return true;} 219 if(head[1]!='s') {a_is = false;return true;} 220 if(head[2]!='l') {a_is = false;return true;} 220 if(head[2]!='l') {a_is = false;return true;} 221 if(head[3]!='i') {a_is = false;return true;} 221 if(head[3]!='i') {a_is = false;return true;} 222 if(head[4]!='d') {a_is = false;return true;} 222 if(head[4]!='d') {a_is = false;return true;} 223 if(head[5]!='e') {a_is = false;return true;} 223 if(head[5]!='e') {a_is = false;return true;} 224 if(head[6]!='s') {a_is = false;return true;} 224 if(head[6]!='s') {a_is = false;return true;} 225 a_is = true; 225 a_is = true; 226 return true; 226 return true; 227 } 227 } 228 228 229 inline bool is_fits(const std::string& a_file, 229 inline bool is_fits(const std::string& a_file,bool& a_is){ 230 unsigned char head[6]; 230 unsigned char head[6]; 231 {unsigned int num = 6; 231 {unsigned int num = 6; 232 if(!signature(a_file,head,num)) {a_is = fals 232 if(!signature(a_file,head,num)) {a_is = false;return false;} 233 if(num!=6) {a_is = false;return true;}} 233 if(num!=6) {a_is = false;return true;}} 234 if(head[0]!='S') {a_is = false;return true;} 234 if(head[0]!='S') {a_is = false;return true;} 235 if(head[1]!='I') {a_is = false;return true;} 235 if(head[1]!='I') {a_is = false;return true;} 236 if(head[2]!='M') {a_is = false;return true;} 236 if(head[2]!='M') {a_is = false;return true;} 237 if(head[3]!='P') {a_is = false;return true;} 237 if(head[3]!='P') {a_is = false;return true;} 238 if(head[4]!='L') {a_is = false;return true;} 238 if(head[4]!='L') {a_is = false;return true;} 239 if(head[5]!='E') {a_is = false;return true;} 239 if(head[5]!='E') {a_is = false;return true;} 240 a_is = true; 240 a_is = true; 241 return true; 241 return true; 242 } 242 } 243 243 244 inline bool is_hdf(const std::string& a_file,b 244 inline bool is_hdf(const std::string& a_file,bool& a_is){ 245 unsigned char head[4]; 245 unsigned char head[4]; 246 {unsigned int num = 4; 246 {unsigned int num = 4; 247 if(!signature(a_file,head,num)) {a_is = fals 247 if(!signature(a_file,head,num)) {a_is = false;return false;} 248 if(num!=4) {a_is = false;return true;}} 248 if(num!=4) {a_is = false;return true;}} 249 if(head[0]!=137) {a_is = false;return true;} 249 if(head[0]!=137) {a_is = false;return true;} 250 if(head[1]!='H') {a_is = false;return true;} 250 if(head[1]!='H') {a_is = false;return true;} 251 if(head[2]!='D') {a_is = false;return true;} 251 if(head[2]!='D') {a_is = false;return true;} 252 if(head[3]!='F') {a_is = false;return true;} 252 if(head[3]!='F') {a_is = false;return true;} 253 a_is = true; 253 a_is = true; 254 return true; 254 return true; 255 } 255 } 256 256 257 inline bool is_ps(const std::string& a_file,bo 257 inline bool is_ps(const std::string& a_file,bool& a_is){ 258 unsigned char head[4]; 258 unsigned char head[4]; 259 {unsigned int num = 4; 259 {unsigned int num = 4; 260 if(!signature(a_file,head,num)) {a_is = fals 260 if(!signature(a_file,head,num)) {a_is = false;return false;} 261 if(num!=4) {a_is = false;return true;}} 261 if(num!=4) {a_is = false;return true;}} 262 if(head[0]!='%') {a_is = false;return true;} 262 if(head[0]!='%') {a_is = false;return true;} 263 if(head[1]!='!') {a_is = false;return true;} 263 if(head[1]!='!') {a_is = false;return true;} 264 if(head[2]!='P') {a_is = false;return true;} 264 if(head[2]!='P') {a_is = false;return true;} 265 if(head[3]!='S') {a_is = false;return true;} 265 if(head[3]!='S') {a_is = false;return true;} 266 a_is = true; 266 a_is = true; 267 return true; 267 return true; 268 } 268 } 269 269 270 inline bool is_simbad(const std::string& a_fil 270 inline bool is_simbad(const std::string& a_file,bool& a_is){ 271 unsigned char head[10]; 271 unsigned char head[10]; 272 {unsigned int num = 10; 272 {unsigned int num = 10; 273 if(!signature(a_file,head,num)) {a_is = fals 273 if(!signature(a_file,head,num)) {a_is = false;return false;} 274 if(num!=10) {a_is = false;return true;}} 274 if(num!=10) {a_is = false;return true;}} 275 if(head[0]!=':') {a_is = false;return true;} 275 if(head[0]!=':') {a_is = false;return true;} 276 if(head[1]!=':') {a_is = false;return true;} 276 if(head[1]!=':') {a_is = false;return true;} 277 if(head[2]!='s') {a_is = false;return true;} 277 if(head[2]!='s') {a_is = false;return true;} 278 if(head[3]!='c') {a_is = false;return true;} 278 if(head[3]!='c') {a_is = false;return true;} 279 if(head[4]!='r') {a_is = false;return true;} 279 if(head[4]!='r') {a_is = false;return true;} 280 if(head[5]!='i') {a_is = false;return true;} 280 if(head[5]!='i') {a_is = false;return true;} 281 if(head[6]!='p') {a_is = false;return true;} 281 if(head[6]!='p') {a_is = false;return true;} 282 if(head[7]!='t') {a_is = false;return true;} 282 if(head[7]!='t') {a_is = false;return true;} 283 if(head[8]!=':') {a_is = false;return true;} 283 if(head[8]!=':') {a_is = false;return true;} 284 if(head[9]!=':') {a_is = false;return true;} 284 if(head[9]!=':') {a_is = false;return true;} 285 a_is = true; 285 a_is = true; 286 return true; 286 return true; 287 } 287 } 288 288 289 }} 289 }} 290 290 291 #include "fsize" 291 #include "fsize" 292 292 293 namespace tools { 293 namespace tools { 294 namespace file { 294 namespace file { 295 295 296 inline bool is_aida(const std::string& a_file, 296 inline bool is_aida(const std::string& a_file,bool& a_is){ 297 long sz; 297 long sz; 298 if(!size(a_file,sz)) {a_is = false;return fa 298 if(!size(a_file,sz)) {a_is = false;return false;} 299 299 300 //NOTE : it assumes that the file is not com 300 //NOTE : it assumes that the file is not compressed. 301 unsigned char head[1024]; 301 unsigned char head[1024]; 302 {unsigned int num = 1024; 302 {unsigned int num = 1024; 303 if(!signature(a_file,head,num)) {a_is = fals 303 if(!signature(a_file,head,num)) {a_is = false;return false;} 304 if(num!=1024) {a_is = false;return true;}} 304 if(num!=1024) {a_is = false;return true;}} 305 head[1023] = 0; //to have a C string. 305 head[1023] = 0; //to have a C string. 306 a_is = ::strstr((const char*)head,"<aida")?t 306 a_is = ::strstr((const char*)head,"<aida")?true:false; 307 return true; 307 return true; 308 } 308 } 309 309 310 inline bool is_jive(const std::string& a_file, 310 inline bool is_jive(const std::string& a_file,bool& a_is){ 311 long sz; 311 long sz; 312 if(!size(a_file,sz)) {a_is = false;return fa 312 if(!size(a_file,sz)) {a_is = false;return false;} 313 313 314 //NOTE : it assumes that the file is not com 314 //NOTE : it assumes that the file is not compressed. 315 unsigned char head[1024]; 315 unsigned char head[1024]; 316 {unsigned int num = 1024; 316 {unsigned int num = 1024; 317 if(!signature(a_file,head,num)) {a_is = fals 317 if(!signature(a_file,head,num)) {a_is = false;return false;} 318 if(num!=1024) {a_is = false;return true;}} 318 if(num!=1024) {a_is = false;return true;}} 319 head[1023] = 0; //to have a C string. 319 head[1023] = 0; //to have a C string. 320 if(::strstr((const char*)head,"<?ATLAS")) {a 320 if(::strstr((const char*)head,"<?ATLAS")) {a_is = true;return true;} 321 a_is = ::strstr((const char*)head,"<!DOCTYPE 321 a_is = ::strstr((const char*)head,"<!DOCTYPE Event")?true:false; 322 return true; 322 return true; 323 } 323 } 324 324 325 inline bool is_heprep(const std::string& a_fil 325 inline bool is_heprep(const std::string& a_file,bool& a_is){ 326 long sz; 326 long sz; 327 if(!size(a_file,sz)) {a_is = false;return fa 327 if(!size(a_file,sz)) {a_is = false;return false;} 328 328 329 //NOTE : it assumes that the file is not com 329 //NOTE : it assumes that the file is not compressed. 330 unsigned char head[1024]; 330 unsigned char head[1024]; 331 {unsigned int num = 1024; 331 {unsigned int num = 1024; 332 if(!signature(a_file,head,num)) {a_is = fals 332 if(!signature(a_file,head,num)) {a_is = false;return false;} 333 if(num!=1024) {a_is = false;return true;}} 333 if(num!=1024) {a_is = false;return true;}} 334 head[1023] = 0; //to have a C string. 334 head[1023] = 0; //to have a C string. 335 a_is = ::strstr((const char*)head,"<heprep") 335 a_is = ::strstr((const char*)head,"<heprep")?true:false; 336 return true; 336 return true; 337 } 337 } 338 338 339 }} 339 }} 340 340 341 #include <climits> 341 #include <climits> 342 342 343 namespace tools { 343 namespace tools { 344 namespace file { 344 namespace file { 345 345 346 inline bool is_shp(const std::string& a_file,b 346 inline bool is_shp(const std::string& a_file,bool& a_is){ 347 long sz; 347 long sz; 348 if(!size(a_file,sz)) {a_is = false;return fa 348 if(!size(a_file,sz)) {a_is = false;return false;} 349 // below logic from shapelib-1.5.0/shpopen.c 349 // below logic from shapelib-1.5.0/shpopen.c. 350 unsigned char head[100]; 350 unsigned char head[100]; 351 {unsigned int num = 100; 351 {unsigned int num = 100; 352 if(!signature(a_file,head,num)) {a_is = fals 352 if(!signature(a_file,head,num)) {a_is = false;return false;} 353 if(num!=100) {a_is = false;return true;}} 353 if(num!=100) {a_is = false;return true;}} 354 unsigned int _sz = (static_cast<unsigned int 354 unsigned int _sz = (static_cast<unsigned int>(head[24])<<24)|(head[25]<<16)|(head[26]<<8)|head[27]; 355 if(_sz<(UINT_MAX/2)) _sz *= 2; 355 if(_sz<(UINT_MAX/2)) _sz *= 2; 356 else _sz = (UINT_MAX/2)*2; 356 else _sz = (UINT_MAX/2)*2; 357 a_is = sz==long(_sz)?true:false; 357 a_is = sz==long(_sz)?true:false; 358 return true; 358 return true; 359 } 359 } 360 360 361 }} 361 }} 362 362 363 #endif 363 #endif