MCPcopy Create free account
hub / github.com/NetHack/NetHack / get_sound_effect_filename

Function get_sound_effect_filename

src/sounds.c:1994–2080  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1992}
1993
1994char *
1995get_sound_effect_filename(
1996 int32_t seidint,
1997 char *buf,
1998 size_t bufsz,
1999 int32_t approach)
2000{
2001 static const char prefix[] = "se_", suffix[] = ".wav";
2002 size_t consumes = 0, baselen = 0, existinglen = 0;
2003/* enum sound_effect_entries seid = (enum sound_effect_entries) seidint; */
2004 char *ourdir = sounddir; /* sounddir would get set in files.c */
2005 char *cp = buf;
2006 boolean needslash = TRUE;
2007
2008 if (!buf || (!ourdir && approach == sff_default))
2009 return (char *) 0;
2010
2011 if (!basenames_initialized) {
2012 initialize_semap_basenames();
2013 basenames_initialized = TRUE;
2014 }
2015
2016 if (semap_basenames[seidint])
2017 baselen = strlen(semap_basenames[seidint]);
2018
2019 consumes = (sizeof prefix - 1) + baselen;
2020 if (approach == sff_default) {
2021 consumes += (sizeof suffix - 1) + strlen(ourdir) + 1; /* 1 for '/' */
2022 } else if (approach == sff_havedir_append_rest) {
2023 /* consumes += (sizeof suffix - 1); */
2024 existinglen = strlen(buf);
2025 if (existinglen > 0) {
2026 cp = buf + existinglen; /* points at trailing NUL */
2027 cp--; /* points at last character */
2028 if (*cp == '/' || *cp == '\\')
2029 needslash = FALSE;
2030 cp++; /* points back at trailing NUL */
2031 }
2032 if (needslash)
2033 consumes++; /* for '/' */
2034 consumes += existinglen;
2035 consumes += (sizeof suffix - 1);
2036 }
2037 consumes += 1; /* for trailing NUL */
2038 /* existinglen could be >= bufsz if caller didn't initialize buf
2039 * to properly include a trailing NUL */
2040 if (baselen <= 0 || consumes > bufsz || existinglen >= bufsz)
2041 return (char *) 0;
2042
2043#if 0
2044 if (approach == sff_default) {
2045 Strcpy(buf, ourdir);
2046 Strcat(buf, "/");
2047 } else if (approach == sff_havdir_append_rest) {
2048 if (needslash)
2049 Strcat(buf, "/");
2050 } else if (approach == sff_base_only) {
2051 buf[0] = '\0';

Callers 1

windsound_soundeffectFunction · 0.85

Calls 1

Tested by

no test coverage detected