Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
Cahute 0.6
Logo
Cahute 0.6
  • Installation guides
    • Installing Cahute on Linux distributions
    • Installing Cahute on macOS / OS X
    • Installing Cahute on Microsoft Windows
    • Installing Cahute on AmigaOS
  • Build from source guides
    • Building Cahute for Linux distributions
    • Building Cahute for macOS / OS X
    • Building Cahute for Microsoft Windows
    • Building Cahute for AmigaOS
  • Contribution guides
    • Contributing to Cahute
    • Reporting a bug or vulnerability
    • Requesting a feature
    • Packaging Cahute
    • Creating a merge request
  • Command line user guides
    • Getting information regarding a calculator
    • Sending a file to a calculator’s storage memory
    • Getting a file from the calculator’s storage memory
    • Displaying the screen from a calculator
  • Developer guides
    • Building with the Cahute library
    • Using device detection
      • Listing calculators connected by USB
      • Listing available serial ports
    • Using links
      • Opening a link to a calculator connected by USB
      • Opening a generic link to a calculator connected by serial
    • Reading and writing files
      • Guessing the type of a file
    • Using text conversion utilities
      • Converting text from an encoding to another
  • Miscellaneous guides
    • Getting started with Cahute in Visual Studio
    • Capturing USB communications on Windows using Wireshark
  • Data formats
    • Number formats
    • Picture formats
    • Text encodings
    • File formats
      • fx-CG add-ins
      • fx-9860G add-ins
      • Calculator Text Format (CTF)
      • CASIOLINK archives
      • casrc configuration file
      • Catalog files (CAT)
      • e-Activity files
      • fx-CG f-key files
      • fx-9860G f-key files
      • FX Program (FXP)
      • GraphCard file format
      • fx-CG language files
      • fx-9860G language files
      • Main memory archives
      • fx-CG picture
      • fx-CP picture
  • Communication protocols
    • Rationales behind the communication protocols
    • Transport medium and protocols
    • USB detection for CASIO calculators
    • CASIOLINK protocols – Serial protocols used by pre fx-9860G calculators
    • CAS40 protocol – Serial protocol used by pre-1996 calculators
      • CAS40 packet format
      • CAS40 data types
      • CAS40 flows
    • CAS50 protocol – Serial protocol used by calculators from 1996 to 2004
      • CAS50 packet format
      • CAS50 data types
      • CAS50 flows
    • CAS100 protocol – Serial protocol used by AFX / Graph 100
      • CAS100 packet format
      • CAS100 data types
      • CAS100 flows
    • CAS300 – Serial and USB protocol used by Classpad 300 / 330 (+)
      • CAS300 packet format
      • CAS300 commands
      • CAS300 flows
    • Protocol 7.00 – Serial and USB protocol used by post fx-9860G calculators
      • Specific formats for Protocol 7.00
      • Protocol 7.00 packet format
      • Protocol 7.00 communication flows
      • Known Protocol 7.00 commands by CASIO
      • Known Protocol 7.00 command extensions in fxRemote
      • Protocol 7.00 use cases
      • Known hardware identifiers for Protocol 7.00
    • Protocol 7.00 Screenstreaming – fx-9860G and fx-CG screenstreaming
      • Protocol 7.00 Screenstreaming packet format
      • Protocol 7.00 Screenstreaming communication flows
    • USB Mass Storage (UMS)
  • Cahute features
    • System compatibility
    • Contexts
    • Links and mediums
    • Files
    • Main memory data
    • Logging facilities
  • Cahute internals
    • Internal compatibility utilities
    • Links and medium internals
    • File internals
    • Characters, encodings and conversions
  • Command line reference
    • CaS command-line reference
    • p7 command line reference
    • p7os command line reference
    • p7screen command line reference
    • xfer9860 command line reference
  • Header reference
    • <cahute.h> – Main header for Cahute
      • <cahute/cdefs.h> – Basic definitions for Cahute
      • <cahute/config.h> – Cahute configuration details
      • <cahute/context.h> – Context management for Cahute
      • <cahute/data.h> – Calculator data resource and methods for Cahute
      • <cahute/detection.h> – Device detection for Cahute
      • <cahute/error.h> – Error definitions for Cahute
      • <cahute/file.h> – File related utilities for Cahute
      • <cahute/link.h> – Calculator link resource and methods for Cahute
      • <cahute/logging.h> – Logging control for Cahute
      • <cahute/path.h> – Path related utilities for Cahute
      • <cahute/picture.h> – Picture format related utilities for Cahute
      • <cahute/text.h> – Text encoding related utilities for Cahute
  • CMake setting reference
  • Project management
    • Project governance
    • Git and release versioning
    • Community feedback
    • Contribution style
    • Coding style
Back to top

<cahute/path.h> – Path related utilities for Cahute¶

Macro definitions¶

CAHUTE_PATH_TYPE_* are constants representing the type of the path representation.

CAHUTE_PATH_TYPE_CLI¶

Alias for the path type assumed to be passed via command-line. This is portable for all officially supported platforms.

CAHUTE_PATH_TYPE_POSIX¶

POSIX path, as used by standard POSIX file APIs.

This path representation has the following properties:

  • Is terminated by a single NUL byte (\0);

  • Path components are separated by a single-byte / (U+002F) separator regardless of the locale;

  • Uses an ASCII, UTF-8 or other multibyte character encoding based on the user’s locale;

  • There is no device at the start of the path.

Example paths using this type are the following:

/usr/bin/p7

Absolute path using ASCII / UTF-8.

mydir/myfile.ext

Relative path using ASCII / UTF-8.

CAHUTE_PATH_TYPE_DOS¶

DOS path, as used by MS-DOS or ROM-DOS (used by the AFX / Graph 100).

This path representation has the following properties:

  • Is terminated by a single NUL byte (\0);

  • Path components are separated by a single-byte \ (U+005C) separator regardless of the locale;

  • Path components must observe the 8:3 rule, i.e. respect the following regular expression: [^.]{1,8}(\.[^.]{1,3});

  • Uses an ASCII or ISO-8859-* encoding based on the user’s locale;

  • Path may be prefixed by a single-character device name followed by a single-byte : (U+003A), being an uppercase latin letter from A to Z.

Example paths using this type are the following:

\mydir\myfile.ext

Absolute path on the current device.

A:\mydir\myfile.ext

Absolute path on device A:.

mydir\myfile.ext

Relative path on the current device.

A:mydir\myfile.ext

Path relative to the working directory on device A:.

Warning

For security, when validating, legacy devices, i.e. special names with any extension, must be forbidden. As described in Naming Files, Paths and Namespaces, the list is the following:

CON, PRN, AUX, NUL, COM0, COM1, COM2, COM3, COM4, COM5, COM6, COM7,
COM8, COM9, COM¹, COM², COM³, LPT0, LPT1, LPT2, LPT3, LPT4, LPT5,
LPT6, LPT7, LPT8, LPT9, LPT¹, LPT², and LPT³

Note that 8-bit superscript digits ¹, ², and ³ are treated as digits and, thus, can identify legacy DOS devices.

CAHUTE_PATH_TYPE_WIN32_ANSI¶

Win32 / Windows NT path, including UNC paths, as used natively under Windows 2000 or above.

If using UNC, i.e. if the path starts with \\ (two U+005C bytes), this path representation has the following properties:

  • Is terminated by a single NUL byte (\0);

  • Path components are separated by a single-byte \ (U+005C) or / (U+002F) separator, used interchangeably;

  • Uses an ASCII, UTF-8 or other multibyte character encoding based on the user’s locale;

  • The path starts with \\([^\]+)\([^\]+), in which the capturing groups represent both the

Otherwise, this path representation has the same properties as for CAHUTE_PATH_TYPE_DOS, except that it does not have the 8:3 path component limitation.

Example paths using this type are the following:

\mydir\myfile.ext

Absolute path on the current device.

A:\mydir\myfile.ext

Absolute path on device A:.

mydir\myfile.ext

Relative path on the current device.

A:mydir\myfile.ext

Path relative to the working directory on device A:.

\\myhostname\myshare\mydir\myfile.ext

Absolute path on share myshare of server myhostname.

\\.\A:\mydir\myfile.ext

Absolute path on device A:.

\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\mydir\myfile.ext

Absolute path on device Volume{b75e2c83-0000-0000-0000-602f00000000}.

\\?\A:\mydir\myfile.ext

Absolute path on device A:.

Warning

When normalizing, DOS devices must be detected and forbidden. This includes their DOS form, e.g. mydir\COM1.txt\myfile.ext, or their UNC form, e.g. \\.\COM1 or \\?\COM1.

CAHUTE_PATH_TYPE_WIN32_UNICODE¶

Win32 / Windows NT path, including UNC paths, as used natively under Windows 2000 or above.

This is equivalent to CAHUTE_PATH_TYPE_WIN32_UNICODE, except the character encoding is fixed to UTF-16 using the system’s endianness.

CAHUTE_PATH_TYPE_CASIOWIN¶

CASIOWIN path using variable-size encoding, as used by CASIOWIN on fx-9860G, fx-CP, fx-CG and derivatives.

This path representation has the following properties:

  • Is terminated by a single NUL byte (\0);

  • Path components are separated by a single-byte \ (U+005C) separator;

  • Path components must observe the 8:3 rule, i.e. respect the following regular expression: [^.]{1,8}(\.[^.]{1,3});

  • Uses Variable width encoding for both the device and path components;

  • The path may start with \\([^\]+), which represents the device on which the file is located, e.g. \\fls0.

Example paths of this type are the following:

mydir\myfile.ext

Relative path.

\mydir\myfile.ext

Absolute path on current device.

\\fls0\mydir\myfile.ext

Absolute path on device fls0.

CAHUTE_PATH_TYPE_CASIOWIN_16¶

CASIOWIN path using fixed-width encoding, as used by CASIOWIN’s SDK on fx-9860G, fx-CP, fx-CG and derivatives.

This is equivalent to CAHUTE_PATH_TYPE_CASIOWIN, except the character encoding is fixed to Fixed-width encoding using the system’s endianness instead of Variable width encoding.

Function declarations¶

int cahute_find_path_extension(cahute_context *context, char *buf, size_t buf_size, void const *path, int path_type)¶

Find the extension, in ASCII lowercase, of the file designated by the provided path.

Note that in the case of extensions known as “modifiers”, e.g. .bz2 or .gz, the function will attempt at including the extension found before, in order to obtain e.g. tar.gz or g1m.bz2.

An example usage of this function is the following:

char buf[10];

cahute_find_path_extension(
    context,
    buf,
    sizeof(buf),
    "/home/david/ARCHIVE.G1M",
    CAHUTE_PATH_TYPE_POSIX
);

printf("Extension: %s\n", buf); /* "Extension: g1m" */
Parameters:
  • context – Context in which to run the function.

  • buf – Buffer in which to place the extension, in ASCII lowercase.

  • buf_size – Capacity / size of the buffer to write into, including the NUL terminator.

  • path – Path to find the extension in.

  • path_type – Type of the path.

Returns:

Error, or 0 if successful.

Next
<cahute/picture.h> – Picture format related utilities for Cahute
Previous
<cahute/logging.h> – Logging control for Cahute
Copyright © 2024, Thomas Touhey
Made with Sphinx and @pradyunsg's Furo
On this page
  • <cahute/path.h> – Path related utilities for Cahute
    • Macro definitions
    • Function declarations