Use C++ style comments consistently in SDL source code

Implemented using this script:

find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
    core/linux/SDL_evdev_kbd_default_keymap.h \
    events/imKStoUCS.* \
    hidapi \
    joystick/controller_type.c \
    joystick/controller_type.h \
    joystick/hidapi/steam/controller_constants.h \
    joystick/hidapi/steam/controller_structs.h \
    joystick/SDL_gamepad_db.h \
    libm \
    render/*/*Shader*.h \
    render/vitagxm/SDL_render_vita_gxm_shaders.h \
    render/metal/SDL_shaders_metal_*.h \
    stdlib/SDL_malloc.c \
    stdlib/SDL_qsort.c \
    stdlib/SDL_strtokr.c \
    test/ \
    video/directx/SDL_d3d12_xbox_cmacros.h \
    video/directx/d3d12.h \
    video/directx/d3d12sdklayers.h \
    video/khronos \
    video/x11/edid-parse.c \
    video/x11/xsettings-client.* \
    video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
This commit is contained in:
Sam Lantinga
2024-08-22 10:30:45 -07:00
parent 658fc3db0f
commit 6501e90018
743 changed files with 11882 additions and 11882 deletions

View File

@@ -78,7 +78,7 @@ char *convert_filters(const SDL_DialogFileFilter *filters, int nfilters,
SDL_free(converted);
}
/* If the filter list is empty, put the suffix */
// If the filter list is empty, put the suffix
if (!filters->name || !filters->pattern) {
new_length = SDL_strlen(combined) + SDL_strlen(suffix) + 1;
@@ -117,7 +117,7 @@ char *convert_filter(const SDL_DialogFileFilter filter, NameTransform ntf,
if (ntf) {
name_filtered = ntf(filter.name);
} else {
/* Useless strdup, but easier to read and maintain code this way */
// Useless strdup, but easier to read and maintain code this way
name_filtered = SDL_strdup(filter.name);
}
@@ -161,10 +161,10 @@ char *convert_ext_list(const char *list, const char *prefix,
}
total_length =
SDL_strlen(list) - semicolons /* length of list contents */
+ semicolons * SDL_strlen(separator) /* length of separators */
+ SDL_strlen(prefix) + SDL_strlen(suffix) /* length of prefix/suffix */
+ 1; /* terminating null byte */
SDL_strlen(list) - semicolons // length of list contents
+ semicolons * SDL_strlen(separator) // length of separators
+ SDL_strlen(prefix) + SDL_strlen(suffix) // length of prefix/suffix
+ 1; // terminating null byte
converted = (char *) SDL_malloc(total_length);

View File

@@ -30,8 +30,8 @@
as "|" with Zenity). */
typedef char *(NameTransform)(const char * name);
/* Converts all the filters into a single string. */
/* <prefix>[filter]{<separator>[filter]...}<suffix> */
// Converts all the filters into a single string.
// <prefix>[filter]{<separator>[filter]...}<suffix>
char *convert_filters(const SDL_DialogFileFilter *filters, int nfilters,
NameTransform ntf, const char *prefix,
const char *separator, const char *suffix,
@@ -39,20 +39,20 @@ char *convert_filters(const SDL_DialogFileFilter *filters, int nfilters,
const char *filt_suffix, const char *ext_prefix,
const char *ext_separator, const char *ext_suffix);
/* Converts one filter into a single string. */
/* <prefix>[filter name]<separator>[filter extension list]<suffix> */
// Converts one filter into a single string.
// <prefix>[filter name]<separator>[filter extension list]<suffix>
char *convert_filter(const SDL_DialogFileFilter filter, NameTransform ntf,
const char *prefix, const char *separator,
const char *suffix, const char *ext_prefix,
const char *ext_separator, const char *ext_suffix);
/* Converts the extenstion list of a filter into a single string. */
/* <prefix>[extension]{<separator>[extension]...}<suffix> */
// Converts the extenstion list of a filter into a single string.
// <prefix>[extension]{<separator>[extension]...}<suffix>
char *convert_ext_list(const char *list, const char *prefix,
const char *separator, const char *suffix);
/* Must be used if convert_* functions aren't used */
/* Returns an error message if there's a problem, NULL otherwise */
// Returns an error message if there's a problem, NULL otherwise
const char *validate_filters(const SDL_DialogFileFilter *filters,
int nfilters);

View File

@@ -25,7 +25,7 @@
void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location, SDL_bool allow_many)
{
if (!Android_JNI_OpenFileDialog(callback, userdata, filters, nfilters, SDL_FALSE, allow_many)) {
/* SDL_SetError is already called when it fails */
// SDL_SetError is already called when it fails
callback(userdata, NULL, -1);
}
}
@@ -33,7 +33,7 @@ void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void *userd
void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location)
{
if (!Android_JNI_OpenFileDialog(callback, userdata, filters, nfilters, SDL_TRUE, SDL_FALSE)) {
/* SDL_SetError is already called when it fails */
// SDL_SetError is already called when it fails
callback(userdata, NULL, -1);
}
}

View File

@@ -53,7 +53,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
return;
}
/* NSOpenPanel inherits from NSSavePanel */
// NSOpenPanel inherits from NSSavePanel
NSSavePanel *dialog;
NSOpenPanel *dialog_as_open;
@@ -120,7 +120,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
}
}
/* Keep behavior consistent with other platforms */
// Keep behavior consistent with other platforms
[dialog setAllowsOtherFileTypes:YES];
if (default_location) {

View File

@@ -165,19 +165,19 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m
const char **path;
dbus->message_iter_init(msg, &signal_iter);
/* Check if the parameters are what we expect */
// Check if the parameters are what we expect
if (dbus->message_iter_get_arg_type(&signal_iter) != DBUS_TYPE_UINT32)
goto not_our_signal;
dbus->message_iter_get_basic(&signal_iter, &result);
if (result == 1 || result == 2) {
/* cancelled */
// cancelled
const char *result_data[] = { NULL };
signal_data->callback(signal_data->userdata, result_data, -1); /* TODO: Set this to the last selected filter */
signal_data->callback(signal_data->userdata, result_data, -1); // TODO: Set this to the last selected filter
goto handled;
}
else if (result) {
/* some error occurred */
// some error occurred
signal_data->callback(signal_data->userdata, NULL, -1);
goto handled;
}
@@ -199,7 +199,7 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m
dbus->message_iter_get_basic(&array_entry, &method);
if (!SDL_strcmp(method, "uris")) {
/* we only care about the selected file paths */
// we only care about the selected file paths
break;
}
@@ -239,8 +239,8 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m
dbus->message_iter_get_basic(&uri_entry, &uri);
/* https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.FileChooser.html */
/* Returned paths will always start with 'file://'; SDL_URIToLocal() truncates it. */
// https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.FileChooser.html
// Returned paths will always start with 'file://'; SDL_URIToLocal() truncates it.
char *decoded_uri = SDL_malloc(SDL_strlen(uri) + 1);
if (SDL_URIToLocal(uri, decoded_uri)) {
path[current] = decoded_uri;
@@ -255,7 +255,7 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m
++current;
}
path[length - 1] = NULL;
signal_data->callback(signal_data->userdata, path, -1); /* TODO: Fetch the index of the filter that was used */
signal_data->callback(signal_data->userdata, path, -1); // TODO: Fetch the index of the filter that was used
cleanup:
dbus->connection_remove_filter(conn, &DBus_MessageFilter, signal_data);
@@ -326,14 +326,14 @@ static void DBus_OpenDialog(const char *method, const char *method_title, SDL_Di
} else {
const Uint64 xid = (Uint64)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
if (xid) {
const size_t len = sizeof(X11_HANDLE_PREFIX) + 24; /* A 64-bit number can be 20 characters max. */
const size_t len = sizeof(X11_HANDLE_PREFIX) + 24; // A 64-bit number can be 20 characters max.
handle_str = SDL_malloc(len * sizeof(char));
if (!handle_str) {
callback(userdata, NULL, -1);
return;
}
/* The portal wants X11 window ID numbers in hex. */
// The portal wants X11 window ID numbers in hex.
SDL_snprintf(handle_str, len, "%s%" SDL_PRIx64, X11_HANDLE_PREFIX, xid);
}
}
@@ -448,7 +448,7 @@ int SDL_Portal_detect(void)
DBusMessageIter reply_iter;
static int portal_present = -1;
/* No need for this if the result is cached. */
// No need for this if the result is cached.
if (portal_present != -1) {
return portal_present;
}
@@ -460,7 +460,7 @@ int SDL_Portal_detect(void)
return 0;
}
/* Use introspection to get the available services. */
// Use introspection to get the available services.
msg = dbus->message_new_method_call(PORTAL_DESTINATION, PORTAL_PATH, "org.freedesktop.DBus.Introspectable", "Introspect");
if (!msg) {
goto done;
@@ -485,7 +485,7 @@ int SDL_Portal_detect(void)
*/
dbus->message_iter_get_basic(&reply_iter, &reply_str);
if (SDL_strstr(reply_str, PORTAL_INTERFACE)) {
portal_present = 1; /* Found it! */
portal_present = 1; // Found it!
}
done:
@@ -498,7 +498,7 @@ done:
#else
/* Dummy implementation to avoid compilation problems */
// Dummy implementation to avoid compilation problems
void SDL_Portal_ShowOpenFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const SDL_DialogFileFilter *filters, int nfilters, const char* default_location, SDL_bool allow_many)
{
@@ -523,4 +523,4 @@ int SDL_Portal_detect(void)
return 0;
}
#endif /* SDL_USE_LIBDBUS */
#endif // SDL_USE_LIBDBUS

View File

@@ -44,7 +44,7 @@ static void set_callback(void)
}
}
/* Returns non-zero on success, 0 on failure */
// Returns non-zero on success, 0 on failure
static int detect_available_methods(const char *value)
{
const char *driver = value ? value : SDL_GetHint(SDL_HINT_FILE_DIALOG_DRIVER);
@@ -75,9 +75,9 @@ static int detect_available_methods(const char *value)
void SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const SDL_DialogFileFilter *filters, int nfilters, const char* default_location, SDL_bool allow_many)
{
/* Call detect_available_methods() again each time in case the situation changed */
// Call detect_available_methods() again each time in case the situation changed
if (!detected_open && !detect_available_methods(NULL)) {
/* SetError() done by detect_available_methods() */
// SetError() done by detect_available_methods()
callback(userdata, NULL, -1);
return;
}
@@ -87,9 +87,9 @@ void SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL
void SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const SDL_DialogFileFilter *filters, int nfilters, const char* default_location)
{
/* Call detect_available_methods() again each time in case the situation changed */
// Call detect_available_methods() again each time in case the situation changed
if (!detected_save && !detect_available_methods(NULL)) {
/* SetError() done by detect_available_methods() */
// SetError() done by detect_available_methods()
callback(userdata, NULL, -1);
return;
}
@@ -99,9 +99,9 @@ void SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL
void SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const char* default_location, SDL_bool allow_many)
{
/* Call detect_available_methods() again each time in case the situation changed */
// Call detect_available_methods() again each time in case the situation changed
if (!detected_folder && !detect_available_methods(NULL)) {
/* SetError() done by detect_available_methods() */
// SetError() done by detect_available_methods()
callback(userdata, NULL, -1);
return;
}

View File

@@ -73,7 +73,7 @@ char *zenity_clean_name(const char *name)
there aren't others. TODO: find something better. */
for (char *c = newname; *c; c++) {
if (*c == '|') {
/* Zenity doesn't support escaping with \ */
// Zenity doesn't support escaping with '\'
*c = '/';
}
}
@@ -93,7 +93,7 @@ static char** generate_args(const zenityArgs* info)
int nextarg = 0;
char **argv = NULL;
/* ARGC PASS */
// ARGC PASS
if (info->flags & ZENITY_MULTIPLE) {
argc++;
}
@@ -128,7 +128,7 @@ static char** generate_args(const zenityArgs* info)
argv[nextarg++] = SDL_strdup("--separator=\n");
CHECK_OOM()
/* ARGV PASS */
// ARGV PASS
if (info->flags & ZENITY_MULTIPLE) {
argv[nextarg++] = SDL_strdup("--multiple");
CHECK_OOM()
@@ -185,7 +185,7 @@ void free_args(char **argv)
SDL_free(argv);
}
/* TODO: Zenity survives termination of the parent */
// TODO: Zenity survives termination of the parent
static void run_zenity(zenityArgs* arg_struct)
{
@@ -207,7 +207,7 @@ static void run_zenity(zenityArgs* arg_struct)
char **args = generate_args(arg_struct);
if (!args) {
/* SDL_SetError will have been called already */
// SDL_SetError will have been called already
callback(userdata, NULL, -1);
return;
}
@@ -223,7 +223,7 @@ static void run_zenity(zenityArgs* arg_struct)
return;
} else if (process == 0){
dup2(out[1], STDOUT_FILENO);
close(STDERR_FILENO); /* Hide errors from Zenity to stderr */
close(STDERR_FILENO); // Hide errors from Zenity to stderr
close(out[0]);
close(out[1]);
@@ -286,7 +286,7 @@ static void run_zenity(zenityArgs* arg_struct)
for (int i = 0; i < bytes_read; i++) {
if (container[i] == '\n') {
container[i] = '\0';
/* Reading from a process often leaves a trailing \n, so ignore the last one */
// Reading from a process often leaves a trailing \n, so ignore the last one
if (i < bytes_read - 1) {
array[narray] = container + i + 1;
narray++;
@@ -303,7 +303,7 @@ static void run_zenity(zenityArgs* arg_struct)
}
}
/* 0 = the user chose one or more files, 1 = the user canceled the dialog */
// 0 = the user chose one or more files, 1 = the user canceled the dialog
if (status == 0 || status == 1) {
callback(userdata, (const char * const*) array, -1);
} else {
@@ -418,7 +418,7 @@ int SDL_Zenity_detect(void)
SDL_SetError("Could not fork process: %s", strerror(errno));
return 0;
} else if (process == 0){
/* Disable output */
// Disable output
close(STDERR_FILENO);
close(STDOUT_FILENO);
execl("/usr/bin/env", "/usr/bin/env", "zenity", "--version", NULL);

View File

@@ -27,7 +27,7 @@
#include "../../core/windows/SDL_windows.h"
#include "../../thread/SDL_systhread.h"
/* If this number is too small, selecting too many files will give an error */
// If this number is too small, selecting too many files will give an error
#define SELECTLIST_SIZE 65536
typedef struct
@@ -56,7 +56,7 @@ int getFilterIndex(int as_reported_by_windows)
return as_reported_by_windows - 1;
}
/* TODO: The new version of file dialogs */
// TODO: The new version of file dialogs
void windows_ShowFileDialog(void *ptr)
{
winArgs *args = (winArgs *) ptr;
@@ -104,14 +104,14 @@ void windows_ShowFileDialog(void *ptr)
window = (HWND) SDL_GetPointerProperty(SDL_GetWindowProperties(parent), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
}
wchar_t *filebuffer; /* lpstrFile */
wchar_t initfolder[MAX_PATH] = L""; /* lpstrInitialDir */
wchar_t *filebuffer; // lpstrFile
wchar_t initfolder[MAX_PATH] = L""; // lpstrInitialDir
/* If SELECTLIST_SIZE is too large, putting filebuffer on the stack might
cause an overflow */
filebuffer = (wchar_t *) SDL_malloc(SELECTLIST_SIZE * sizeof(wchar_t));
/* Necessary for the return code below */
// Necessary for the return code below
SDL_memset(filebuffer, 0, SELECTLIST_SIZE * sizeof(wchar_t));
if (default_file) {
@@ -151,8 +151,8 @@ void windows_ShowFileDialog(void *ptr)
wchar_t *filter_wchar = NULL;
if (filters) {
/* '\x01' is used in place of a null byte */
/* suffix needs two null bytes in case the filter list is empty */
// '\x01' is used in place of a null byte
// suffix needs two null bytes in case the filter list is empty
char *filterlist = convert_filters(filters, nfilters, NULL, "", "",
"\x01\x01", "", "\x01", "\x01",
"*.", ";*.", "");
@@ -206,7 +206,7 @@ void windows_ShowFileDialog(void *ptr)
dialog.lCustData = 0;
dialog.lpfnHook = NULL;
dialog.lpTemplateName = NULL;
/* Skipped many mac-exclusive and reserved members */
// Skipped many mac-exclusive and reserved members
dialog.FlagsEx = 0;
BOOL result = pGetAnyFileName(&dialog);
@@ -215,7 +215,7 @@ void windows_ShowFileDialog(void *ptr)
if (result) {
if (!(flags & OFN_ALLOWMULTISELECT)) {
/* File is a C string stored in dialog.lpstrFile */
// File is a C string stored in dialog.lpstrFile
char *chosen_file = WIN_StringToUTF8W(dialog.lpstrFile);
const char* opts[2] = { chosen_file, NULL };
callback(userdata, opts, getFilterIndex(dialog.nFilterIndex));
@@ -306,7 +306,7 @@ void windows_ShowFileDialog(void *ptr)
}
}
/* If the user chose only one file, it's all just one string */
// If the user chose only one file, it's all just one string
if (nfiles == 0) {
nfiles++;
char **new_cfl = (char **) SDL_realloc(chosen_files_list, sizeof(char*) * (nfiles + 1));
@@ -340,7 +340,7 @@ void windows_ShowFileDialog(void *ptr)
}
} else {
DWORD error = pCommDlgExtendedError();
/* Error code 0 means the user clicked the cancel button. */
// Error code 0 means the user clicked the cancel button.
if (error == 0) {
/* Unlike SDL's handling of errors, Windows does reset the error
code to 0 after calling GetOpenFileName if another Windows
@@ -399,7 +399,7 @@ void windows_ShowFolderDialog(void* ptr)
BROWSEINFOW dialog;
dialog.hwndOwner = parent;
dialog.pidlRoot = NULL;
/* Windows docs say this is `LPTSTR` - apparently it's actually `LPWSTR`*/
// Windows docs say this is `LPTSTR` - apparently it's actually `LPWSTR`
dialog.pszDisplayName = buffer;
dialog.lpszTitle = NULL;
dialog.ulFlags = BIF_USENEWUI;