tree-wide: replace strstr(a, b) == a with spa_strstartswith()

spa_strstartswith() is more immediately understandable.

Coccinelle spatch file:
	@@
	expression E1, E2;
	@@
	- strstr(E1, E2) != E1
	+ !spa_strstartswith(E1, E2)

	@@
	expression E1, E2;
	@@
	- strstr(E1, E2) == E1
	+ spa_strstartswith(E1, E2)

Applied to the tree except for alsa/acp/compat.h because it looks like
that header is still mostly as-is from PA.
This commit is contained in:
Peter Hutterer 2021-08-02 14:05:45 +10:00 committed by Wim Taymans
parent 60c510d766
commit 51a177eb6d
20 changed files with 48 additions and 48 deletions

View file

@ -2534,7 +2534,7 @@ static void registry_event_global(void *data, uint32_t id,
node_id = atoi(str); node_id = atoi(str);
if ((str = spa_dict_lookup(props, PW_KEY_PORT_EXTRA)) != NULL && if ((str = spa_dict_lookup(props, PW_KEY_PORT_EXTRA)) != NULL &&
strstr(str, "jack:flags:") == str) spa_strstartswith(str, "jack:flags:"))
flags = atoi(str+11); flags = atoi(str+11);
if ((str = spa_dict_lookup(props, PW_KEY_PORT_NAME)) == NULL) if ((str = spa_dict_lookup(props, PW_KEY_PORT_NAME)) == NULL)

View file

@ -412,9 +412,9 @@ static const struct a2dp_codec *a2dp_endpoint_to_codec(const char *endpoint)
const char *codec_name; const char *codec_name;
int i; int i;
if (strstr(endpoint, A2DP_SINK_ENDPOINT "/") == endpoint) if (spa_strstartswith(endpoint, A2DP_SINK_ENDPOINT "/"))
codec_name = endpoint + strlen(A2DP_SINK_ENDPOINT "/"); codec_name = endpoint + strlen(A2DP_SINK_ENDPOINT "/");
else if (strstr(endpoint, A2DP_SOURCE_ENDPOINT "/") == endpoint) else if (spa_strstartswith(endpoint, A2DP_SOURCE_ENDPOINT "/"))
codec_name = endpoint + strlen(A2DP_SOURCE_ENDPOINT "/"); codec_name = endpoint + strlen(A2DP_SOURCE_ENDPOINT "/");
else else
return NULL; return NULL;
@ -430,9 +430,9 @@ static const struct a2dp_codec *a2dp_endpoint_to_codec(const char *endpoint)
static int a2dp_endpoint_to_profile(const char *endpoint) static int a2dp_endpoint_to_profile(const char *endpoint)
{ {
if (strstr(endpoint, A2DP_SINK_ENDPOINT "/") == endpoint) if (spa_strstartswith(endpoint, A2DP_SINK_ENDPOINT "/"))
return SPA_BT_PROFILE_A2DP_SOURCE; return SPA_BT_PROFILE_A2DP_SOURCE;
else if (strstr(endpoint, A2DP_SOURCE_ENDPOINT "/") == endpoint) else if (spa_strstartswith(endpoint, A2DP_SOURCE_ENDPOINT "/"))
return SPA_BT_PROFILE_A2DP_SINK; return SPA_BT_PROFILE_A2DP_SINK;
else else
return SPA_BT_PROFILE_NULL; return SPA_BT_PROFILE_NULL;

View file

@ -175,7 +175,7 @@ impl_cpu_get_vm_type(void *object)
continue; continue;
for (j = 0; j < SPA_N_ELEMENTS(dmi_vendor_table); j++) { for (j = 0; j < SPA_N_ELEMENTS(dmi_vendor_table); j++) {
if (strstr(s, dmi_vendor_table[j].vendor) == s) { if (spa_strstartswith(s, dmi_vendor_table[j].vendor)) {
spa_log_debug(impl->log, "Virtualization %s found in DMI (%s)", spa_log_debug(impl->log, "Virtualization %s found in DMI (%s)",
s, dmi_vendors[i]); s, dmi_vendors[i]);
impl->vm_type = dmi_vendor_table[j].id; impl->vm_type = dmi_vendor_table[j].id;

View file

@ -679,7 +679,7 @@ handle_device(struct impl *impl, struct sm_object *obj)
pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str); pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str);
if (strstr(media_class, "Audio/") != media_class) if (!spa_strstartswith(media_class, "Audio/"))
return 0; return 0;
if (!spa_streq(str, "alsa")) if (!spa_streq(str, "alsa"))
return 0; return 0;

View file

@ -321,9 +321,9 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
priority -= atol(dev) * 16; priority -= atol(dev) * 16;
priority -= atol(subdev); priority -= atol(subdev);
if (strstr(profile, "analog-") == profile) if (spa_strstartswith(profile, "analog-"))
priority += 9; priority += 9;
else if (strstr(profile, "iec958-") == profile) else if (spa_strstartswith(profile, "iec958-"))
priority += 8; priority += 8;
if (pw_properties_get(node->props, PW_KEY_PRIORITY_DRIVER) == NULL) { if (pw_properties_get(node->props, PW_KEY_PRIORITY_DRIVER) == NULL) {
@ -356,7 +356,7 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
if ((devname = pw_properties_get(device->props, SPA_KEY_DEVICE_NAME)) == NULL) if ((devname = pw_properties_get(device->props, SPA_KEY_DEVICE_NAME)) == NULL)
devname = "unnamed-device"; devname = "unnamed-device";
if (strstr(devname, "alsa_card.") == devname) if (spa_strstartswith(devname, "alsa_card."))
devname += 10; devname += 10;
pw_properties_set(node->props, SPA_KEY_NODE_NAME, pw_properties_set(node->props, SPA_KEY_NODE_NAME,

View file

@ -616,7 +616,7 @@ handle_device(struct impl *impl, struct sm_object *obj)
pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str); pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str);
if (strstr(media_class, "Audio/") != media_class) if (!spa_strstartswith(media_class, "Audio/"))
return 0; return 0;
if (!spa_streq(str, "bluez5")) if (!spa_streq(str, "bluez5"))
return 0; return 0;

View file

@ -405,7 +405,7 @@ static int update_device_props(struct device *device)
snprintf(temp, sizeof(temp), "%d", device->id); snprintf(temp, sizeof(temp), "%d", device->id);
s = temp; s = temp;
} }
if (strstr(s, "bluez_card.") == s) if (spa_strstartswith(s, "bluez_card."))
s += strlen("bluez_card."); s += strlen("bluez_card.");
pw_properties_set(p, PW_KEY_DEVICE_NAME, pw_properties_set(p, PW_KEY_DEVICE_NAME,

View file

@ -130,14 +130,14 @@ handle_endpoint(struct impl *impl, struct sm_object *object)
ep->enabled = true; ep->enabled = true;
spa_list_append(&impl->endpoint_list, &ep->link); spa_list_append(&impl->endpoint_list, &ep->link);
if (strstr(media_class, "Stream/") == media_class) { if (spa_strstartswith(media_class, "Stream/")) {
media_class += strlen("Stream/"); media_class += strlen("Stream/");
if (strstr(media_class, "Output/") == media_class) { if (spa_strstartswith(media_class, "Output/")) {
direction = PW_DIRECTION_OUTPUT; direction = PW_DIRECTION_OUTPUT;
media_class += strlen("Output/"); media_class += strlen("Output/");
} }
else if (strstr(media_class, "Input/") == media_class) { else if (spa_strstartswith(media_class, "Input/")) {
direction = PW_DIRECTION_INPUT; direction = PW_DIRECTION_INPUT;
media_class += strlen("Input/"); media_class += strlen("Input/");
} }
@ -151,11 +151,11 @@ handle_endpoint(struct impl *impl, struct sm_object *object)
} }
else { else {
const char *media; const char *media;
if (strstr(media_class, "Audio/") == media_class) { if (spa_strstartswith(media_class, "Audio/")) {
media_class += strlen("Audio/"); media_class += strlen("Audio/");
media = "Audio"; media = "Audio";
} }
else if (strstr(media_class, "Video/") == media_class) { else if (spa_strstartswith(media_class, "Video/")) {
media_class += strlen("Video/"); media_class += strlen("Video/");
media = "Video"; media = "Video";
} }

View file

@ -294,21 +294,21 @@ handle_node(struct impl *impl, struct sm_object *object)
if (role && spa_streq(role, "DSP")) if (role && spa_streq(role, "DSP"))
node->active = node->configured = true; node->active = node->configured = true;
if (strstr(media_class, "Stream/") == media_class) { if (spa_strstartswith(media_class, "Stream/")) {
media_class += strlen("Stream/"); media_class += strlen("Stream/");
if (strstr(media_class, "Output/") == media_class) { if (spa_strstartswith(media_class, "Output/")) {
direction = PW_DIRECTION_OUTPUT; direction = PW_DIRECTION_OUTPUT;
media_class += strlen("Output/"); media_class += strlen("Output/");
} }
else if (strstr(media_class, "Input/") == media_class) { else if (spa_strstartswith(media_class, "Input/")) {
direction = PW_DIRECTION_INPUT; direction = PW_DIRECTION_INPUT;
media_class += strlen("Input/"); media_class += strlen("Input/");
} }
else else
return 0; return 0;
if (strstr(media_class, "Video") == media_class) { if (spa_strstartswith(media_class, "Video")) {
if (direction == PW_DIRECTION_OUTPUT) { if (direction == PW_DIRECTION_OUTPUT) {
if ((str = pw_properties_get(object->props, PW_KEY_NODE_PLUGGED)) != NULL) if ((str = pw_properties_get(object->props, PW_KEY_NODE_PLUGGED)) != NULL)
node->plugged = pw_properties_parse_uint64(str); node->plugged = pw_properties_parse_uint64(str);
@ -317,7 +317,7 @@ handle_node(struct impl *impl, struct sm_object *object)
} }
node->active = node->configured = true; node->active = node->configured = true;
} }
else if (strstr(media_class, "Unknown") == media_class) { else if (spa_strstartswith(media_class, "Unknown")) {
node->active = node->configured = true; node->active = node->configured = true;
} }
@ -330,11 +330,11 @@ handle_node(struct impl *impl, struct sm_object *object)
const char *media; const char *media;
bool virtual = false; bool virtual = false;
if (strstr(media_class, "Audio/") == media_class) { if (spa_strstartswith(media_class, "Audio/")) {
media_class += strlen("Audio/"); media_class += strlen("Audio/");
media = "Audio"; media = "Audio";
} }
else if (strstr(media_class, "Video/") == media_class) { else if (spa_strstartswith(media_class, "Video/")) {
media_class += strlen("Video/"); media_class += strlen("Video/");
media = "Video"; media = "Video";
node->active = node->configured = true; node->active = node->configured = true;

View file

@ -244,7 +244,7 @@ static int metadata_property(void *object, uint32_t subject,
pw_properties_clear(impl->props); pw_properties_clear(impl->props);
changed = 1; changed = 1;
} }
else if (strstr(key, PREFIX) == key) { else if (spa_strstartswith(key, PREFIX)) {
changed += pw_properties_set(impl->props, key, value); changed += pw_properties_set(impl->props, key, value);
} }
} }
@ -472,12 +472,12 @@ static void session_create(void *data, struct sm_object *object)
(media_class = pw_properties_get(object->props, PW_KEY_MEDIA_CLASS)) == NULL) (media_class = pw_properties_get(object->props, PW_KEY_MEDIA_CLASS)) == NULL)
return; return;
if (strstr(media_class, "Stream/") == media_class) { if (spa_strstartswith(media_class, "Stream/")) {
media_class += strlen("Stream/"); media_class += strlen("Stream/");
pw_log_debug(NAME " %p: add stream '%d' %s", impl, object->id, media_class); pw_log_debug(NAME " %p: add stream '%d' %s", impl, object->id, media_class);
} else if (strstr(media_class, "Audio/") == media_class && } else if (spa_strstartswith(media_class, "Audio/") &&
((routes = pw_properties_get(object->props, "device.routes")) == NULL || ((routes = pw_properties_get(object->props, "device.routes")) == NULL ||
atoi(routes) == 0)) { atoi(routes) == 0)) {
pw_log_debug(NAME " %p: add node '%d' %s", impl, object->id, media_class); pw_log_debug(NAME " %p: add node '%d' %s", impl, object->id, media_class);
} else { } else {
return; return;

View file

@ -516,16 +516,16 @@ handle_node(struct impl *impl, struct sm_object *obj)
if (media_class == NULL) if (media_class == NULL)
return 0; return 0;
if (strstr(media_class, "Stream/") != media_class) if (!spa_strstartswith(media_class, "Stream/"))
return 0; return 0;
media_class += strlen("Stream/"); media_class += strlen("Stream/");
if (strstr(media_class, "Output/") == media_class) { if (spa_strstartswith(media_class, "Output/")) {
direction = PW_DIRECTION_OUTPUT; direction = PW_DIRECTION_OUTPUT;
media_class += strlen("Output/"); media_class += strlen("Output/");
} }
else if (strstr(media_class, "Input/") == media_class) { else if (spa_strstartswith(media_class, "Input/")) {
direction = PW_DIRECTION_INPUT; direction = PW_DIRECTION_INPUT;
media_class += strlen("Input/"); media_class += strlen("Input/");
} }

View file

@ -178,8 +178,8 @@ handle_node(struct impl *impl, struct sm_object *object)
if (media_class == NULL) if (media_class == NULL)
return 0; return 0;
if (strstr(media_class, "Audio/") != media_class && if (!spa_strstartswith(media_class, "Audio/") &&
(strstr(media_class, "Video/") != media_class)) (!spa_strstartswith(media_class, "Video/")))
return 0; return 0;
node = sm_object_add_data(object, SESSION_KEY, sizeof(struct node)); node = sm_object_add_data(object, SESSION_KEY, sizeof(struct node));

View file

@ -563,7 +563,7 @@ handle_device(struct impl *impl, struct sm_object *obj)
pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str); pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str);
if (strstr(media_class, "Video/") != media_class) if (!spa_strstartswith(media_class, "Video/"))
return 0; return 0;
if (!spa_streq(str, "v4l2")) if (!spa_streq(str, "v4l2"))
return 0; return 0;

View file

@ -154,7 +154,7 @@ static struct node *v4l2_create_node(struct device *dev, uint32_t id,
str = pw_properties_get(dev->props, SPA_KEY_DEVICE_ALIAS); str = pw_properties_get(dev->props, SPA_KEY_DEVICE_ALIAS);
if (str == NULL) if (str == NULL)
str = "v4l2-device"; str = "v4l2-device";
if (strstr(str, "v4l2_device.") == str) if (spa_strstartswith(str, "v4l2_device."))
str += 12; str += 12;
if (strstr(info->factory_name, "sink") != NULL) if (strstr(info->factory_name, "sink") != NULL)

View file

@ -37,7 +37,7 @@ static inline void push_item(struct spa_pod_builder *b, const struct spa_dict_it
const char *str; const char *str;
spa_pod_builder_string(b, item->key); spa_pod_builder_string(b, item->key);
str = item->value; str = item->value;
if (strstr(str, "pointer:") == str) if (spa_strstartswith(str, "pointer:"))
str = ""; str = "";
spa_pod_builder_string(b, str); spa_pod_builder_string(b, str);
} }
@ -50,7 +50,7 @@ static inline int parse_item(struct spa_pod_parser *prs, struct spa_dict_item *i
SPA_POD_String(&item->value), SPA_POD_String(&item->value),
NULL)) < 0) NULL)) < 0)
return res; return res;
if (strstr(item->value, "pointer:") == item->value) if (spa_strstartswith(item->value, "pointer:"))
item->value = ""; item->value = "";
return 0; return 0;
} }

View file

@ -38,7 +38,7 @@ static inline void push_item(struct spa_pod_builder *b, const struct spa_dict_it
const char *str; const char *str;
spa_pod_builder_string(b, item->key); spa_pod_builder_string(b, item->key);
str = item->value; str = item->value;
if (strstr(str, "pointer:") == str) if (spa_strstartswith(str, "pointer:"))
str = ""; str = "";
spa_pod_builder_string(b, str); spa_pod_builder_string(b, str);
} }
@ -65,7 +65,7 @@ static inline int parse_item(struct spa_pod_parser *prs, struct spa_dict_item *i
SPA_POD_String(&item->value), SPA_POD_String(&item->value),
NULL)) < 0) NULL)) < 0)
return res; return res;
if (strstr(item->value, "pointer:") == item->value) if (spa_strstartswith(item->value, "pointer:"))
item->value = ""; item->value = "";
return 0; return 0;
} }

View file

@ -132,7 +132,7 @@ static inline void push_item(struct spa_pod_builder *b, const struct spa_dict_it
const char *str; const char *str;
spa_pod_builder_string(b, item->key); spa_pod_builder_string(b, item->key);
str = item->value; str = item->value;
if (strstr(str, "pointer:") == str) if (spa_strstartswith(str, "pointer:"))
str = ""; str = "";
spa_pod_builder_string(b, str); spa_pod_builder_string(b, str);
} }
@ -159,7 +159,7 @@ static inline int parse_item(struct spa_pod_parser *prs, struct spa_dict_item *i
SPA_POD_String(&item->value), SPA_POD_String(&item->value),
NULL)) < 0) NULL)) < 0)
return res; return res;
if (strstr(item->value, "pointer:") == item->value) if (spa_strstartswith(item->value, "pointer:"))
item->value = ""; item->value = "";
return 0; return 0;
} }

View file

@ -63,9 +63,9 @@ static int key_from_name(const char *name, char *key, size_t maxlen)
{ {
const char *media_class, *select, *str; const char *media_class, *select, *str;
if (strstr(name, "sink-input-") == name) if (spa_strstartswith(name, "sink-input-"))
media_class = "Output/Audio"; media_class = "Output/Audio";
else if (strstr(name, "source-output-") == name) else if (spa_strstartswith(name, "source-output-"))
media_class = "Input/Audio"; media_class = "Input/Audio";
else else
return -1; return -1;
@ -100,9 +100,9 @@ static int key_to_name(const char *key, char *name, size_t maxlen)
{ {
const char *type, *select, *str; const char *type, *select, *str;
if (strstr(key, "restore.stream.Output/Audio.") == key) if (spa_strstartswith(key, "restore.stream.Output/Audio."))
type = "sink-input"; type = "sink-input";
else if (strstr(key, "restore.stream.Input/Audio.") == key) else if (spa_strstartswith(key, "restore.stream.Input/Audio."))
type = "source-output"; type = "source-output";
else else
type = "stream"; type = "stream";

View file

@ -634,7 +634,7 @@ static struct server *create_server(struct impl *impl, const char *address)
spa_list_init(&server->client_list); spa_list_init(&server->client_list);
spa_list_append(&impl->server_list, &server->link); spa_list_append(&impl->server_list, &server->link);
if (strstr(address, "tcp:") == address) { if (spa_strstartswith(address, "tcp:")) {
fd = make_inet_socket(server, address+4); fd = make_inet_socket(server, address+4);
} else { } else {
fd = -EINVAL; fd = -EINVAL;

View file

@ -159,7 +159,7 @@ static int update_properties(struct pw_impl_client *client, const struct spa_dic
for (i = 0; i < dict->n_items; i++) { for (i = 0; i < dict->n_items; i++) {
if (filter) { if (filter) {
if (strstr(dict->items[i].key, "pipewire.") == dict->items[i].key && if (spa_strstartswith(dict->items[i].key, "pipewire.") &&
(old = pw_properties_get(client->properties, dict->items[i].key)) != NULL && (old = pw_properties_get(client->properties, dict->items[i].key)) != NULL &&
(dict->items[i].value == NULL || !spa_streq(old, dict->items[i].value))) { (dict->items[i].value == NULL || !spa_streq(old, dict->items[i].value))) {
pw_log_warn(NAME" %p: refuse property update '%s' from '%s' to '%s'", pw_log_warn(NAME" %p: refuse property update '%s' from '%s' to '%s'",