@@ -26,6 +26,9 @@ enum FileType
2626enum FileType getType (const cxxopts::ParseResult& options, const string& filename, const string& option);
2727bool isFlashType (const TIVarType& type);
2828bool isFlashExtension (const string& extension);
29+ bool isEvoVarExtension (const string& extension);
30+ bool isLegacyVarExtension (const string& extension);
31+ string extensionOf (const string& path);
2932string lowercase (string value);
3033
3134int main (int argc, char ** argv)
@@ -250,6 +253,10 @@ int main(int argc, char** argv)
250253 return 1 ;
251254 }
252255 }
256+ else if (oformat == VARFILE && isEvoVarExtension (extensionOf (opath)))
257+ {
258+ requestedModel = TIModel{" 84Evo" };
259+ }
253260
254261 TIVarFile file = iformat == VARFILE
255262 ? TIVarFile::loadFromFile (ipath)
@@ -263,7 +270,15 @@ int main(int argc, char** argv)
263270 }
264271 if (result.count (" calc" ))
265272 {
266- file.setCalcModel (requestedModel);
273+ file.convertToModel (requestedModel);
274+ }
275+ else if (oformat == VARFILE && isEvoVarExtension (extensionOf (opath)) && !file.isEvoFormat ())
276+ {
277+ file.convertToModel (TIModel{" 84Evo" });
278+ }
279+ else if (oformat == VARFILE && isLegacyVarExtension (extensionOf (opath)) && file.isEvoFormat ())
280+ {
281+ file.convertToModel (TIModel{" 84+CE" });
267282 }
268283 }
269284
@@ -411,6 +426,16 @@ string lowercase(string value)
411426 return value;
412427}
413428
429+ string extensionOf (const string& path)
430+ {
431+ const auto pos = path.find_last_of (' .' );
432+ if (pos == string::npos)
433+ {
434+ return " " ;
435+ }
436+ return lowercase (path.substr (pos + 1 ));
437+ }
438+
414439bool isFlashExtension (const string& extension)
415440{
416441 const string lowered = lowercase (extension);
@@ -424,6 +449,40 @@ bool isFlashExtension(const string& extension)
424449 return false ;
425450}
426451
452+ bool isEvoVarExtension (const string& extension)
453+ {
454+ const string lowered = lowercase (extension);
455+ if (!TIVarTypes::isValidName (lowered))
456+ {
457+ return false ;
458+ }
459+
460+ const TIVarType type{lowered};
461+ const auto & exts = type.getExts ();
462+ return exts.size () > 9 && lowercase (exts[9 ]) == lowered;
463+ }
464+
465+ bool isLegacyVarExtension (const string& extension)
466+ {
467+ const string lowered = lowercase (extension);
468+ if (!TIVarTypes::isValidName (lowered))
469+ {
470+ return false ;
471+ }
472+
473+ const TIVarType type{lowered};
474+ const auto & exts = type.getExts ();
475+ const size_t legacyExtCount = std::min<size_t >(9 , exts.size ());
476+ for (size_t i = 0 ; i < legacyExtCount; i++)
477+ {
478+ if (!exts[i].empty () && lowercase (exts[i]) == lowered)
479+ {
480+ return true ;
481+ }
482+ }
483+ return false ;
484+ }
485+
427486static unordered_map<string, FileType> const fileTypes = {
428487 {" raw" , RAW},
429488 {" readable" , READABLE},
0 commit comments