chromium/third_party/libwebp/src/examples/unicode.h

// Copyright 2018 Google Inc. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the COPYING file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
// -----------------------------------------------------------------------------
//
// Unicode support for Windows. The main idea is to maintain an array of Unicode
// arguments (wargv) and use it only for file paths. The regular argv is used
// for everything else.
//
// Author: Yannis Guyon ([email protected])

#ifndef WEBP_EXAMPLES_UNICODE_H_
#define WEBP_EXAMPLES_UNICODE_H_

#include <stdio.h>

#if defined(_WIN32) && defined(_UNICODE)

// wchar_t is used instead of TCHAR because we only perform additional work when
// Unicode is enabled and because the output of CommandLineToArgvW() is wchar_t.

#include <fcntl.h>
#include <io.h>
#include <wchar.h>
#include <windows.h>
#include <shellapi.h>

// Create a wchar_t array containing Unicode parameters.
#define INIT_WARGV

// Use this to get a Unicode argument (e.g. file path).
#define GET_WARGV
// For cases where argv is shifted by one compared to wargv.
#define GET_WARGV_SHIFTED
#define GET_WARGV_OR_NULL

// Release resources. LocalFree() is needed after CommandLineToArgvW().
#define FREE_WARGV
#define LOCAL_FREE

#define W_CHAR
#define TO_W_CHAR

#define WFOPEN

#define WFPRINTF
#define WPRINTF

#define WSTRLEN
#define WSTRCMP
#define WSTRRCHR
#define WSNPRINTF

#else

#include <string.h>

// Unicode file paths work as is on Unix platforms, and no extra work is done on
// Windows either if Unicode is disabled.

#define INIT_WARGV(ARGC, ARGV)

#define GET_WARGV(ARGV, C)
#define GET_WARGV_SHIFTED(ARGV, C)
#define GET_WARGV_OR_NULL()

#define FREE_WARGV()
#define LOCAL_FREE(WARGV)

#define W_CHAR
#define TO_W_CHAR(STR)

#define WFOPEN(ARG, OPT)

#define WPRINTF(STR, ...)
#define WFPRINTF(STREAM, STR, ...)

#define WSTRLEN(FILENAME)
#define WSTRCMP(FILENAME, STR)
#define WSTRRCHR(FILENAME, STR)
#define WSNPRINTF(A, B, STR, ...)

#endif  // defined(_WIN32) && defined(_UNICODE)

// Don't forget to free wargv before returning (e.g. from main).
#define FREE_WARGV_AND_RETURN(VALUE)

#endif  // WEBP_EXAMPLES_UNICODE_H_