wxMaxima
Loading...
Searching...
No Matches
Functions
FileOpenKind.cpp File Reference

Decides whether wxMaxima can open a file it was handed, and how. More...

#include "FileOpenKind.h"
#include <wx/file.h>
#include <wx/intl.h>
#include <wx/log.h>
#include <algorithm>
#include <array>
#include <cstring>
#include <string_view>
Include dependency graph for FileOpenKind.cpp:

Functions

FileOpenKind wxm::ClassifyFileForOpening (const wxString &file)
 Which kind of file this is, judged by its name alone.
 
bool wxm::FileLooksBinary (const wxString &file)
 True if the start of the file looks like binary data rather than text.
 
wxString wxm::WhyFileCannotBeOpened (const wxString &file)
 Why wxMaxima won't open this file, or an empty string if it will.
 
wxString wxm::MaximaStringLiteral (const wxString &str)
 A file name as a Maxima string literal, quotes included.
 
wxString wxm::WriteDataCommand (const wxString &data, const wxString &file, const wxString &separator)
 The write_data() command the "Export Matrix/List to CSV" wizards send.
 

Detailed Description

Decides whether wxMaxima can open a file it was handed, and how.

Function Documentation

◆ ClassifyFileForOpening()

FileOpenKind wxm::ClassifyFileForOpening ( const wxString &  file)

Which kind of file this is, judged by its name alone.

A "#uuid" suffix, by which a cell in a worksheet can be addressed, is ignored.

◆ FileLooksBinary()

bool wxm::FileLooksBinary ( const wxString &  file)

True if the start of the file looks like binary data rather than text.

Looks at the first few kilobytes: a NUL byte, or the signature of a Windows, Linux or macOS executable, counts as binary. A file that can't be read counts as not binary; opening it will report that properly.

◆ MaximaStringLiteral()

wxString wxm::MaximaStringLiteral ( const wxString &  str)

A file name as a Maxima string literal, quotes included.

For building commands like load("file"). A file name on Linux and macOS may contain a double quote, which used to end the string early: importing a CSV file named data.csv"),system("... ran a shell command. A backslash is a Maxima escape character too, so an unescaped Windows path lost all of its backslashes.

◆ WhyFileCannotBeOpened()

wxString wxm::WhyFileCannotBeOpened ( const wxString &  file)

Why wxMaxima won't open this file, or an empty string if it will.

Combines ClassifyFileForOpening() with FileLooksBinary() for the kinds that are text. The file has to exist for the content check; whether it exists is not checked here.

◆ WriteDataCommand()

wxString wxm::WriteDataCommand ( const wxString &  data,
const wxString &  file,
const wxString &  separator 
)

The write_data() command the "Export Matrix/List to CSV" wizards send.

data is Maxima code naming what to write, separator the separator as Maxima code ('comma, 'tab, ...). The file name goes through MaximaStringLiteral(): it used to be pasted between plain quotes, so a quote in it could inject Maxima code, and every backslash of a Windows path was lost.