summaryrefslogtreecommitdiff
path: root/score.c (follow)
Commit message (Collapse)AuthorAge
* Merge topic branch t/spdx into masterAndre Noll2026-03-26
|\ | | | | | | | | | | | | | | | | | | | | Switch to SPDX licence identifiers A single patch which replaces the first comment line of most .c and .h files containing the copyright notice by standardized SPDX (Software/System Package Data Exchange) nomenclature. * t/spdx: Switch to SPDX identifiers.
| * Switch to SPDX identifiers.Andre Noll2026-03-17
| | | | | | | | | | | | | | | | Generated with sed -i 's|Copyright.*Andre Noll.*|SPDX-License-Identifier: GPL-2.0 */|g' *.c *.h followed by manually tweaking the result a bit. No license change intended.
* | Improve selector loop.Andre Noll2026-03-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently code outside of score.c needs to deal with two types of osl table rows: rows of the audio file table and rows of the score table. This foils type safety because the row pointers to different tables have the same type. We currently expose score rows to functions outside of score.c because the code in aft.c loops over the score table, and the osl loop callback receives a pointer to the current row as its first argument. This commit implements the static call_callback() in score.c, used as the osl callback, to avoid exposing the score row. The new function decodes the cells of the row to obtain the aft row and the score. These two values are then passed to the callback function passed to score_loop().
* | Rename get_score_and_aft_row() -> score_get().Andre Noll2026-03-17
| | | | | | | | It corresponds to the ->get() selector method.
* | Implement selector abstraction.Andre Noll2026-03-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently mood.c and playlist.c contain similar public functions. For example, there is mood_load() and playlist_load(), mood_loop() and playlist_loop(). Introduce struct selector_ops which contains methods such as ->load() and loop(). We define two instances of the new structure, one for the mood selector and one for the playlist selector. The structures can be constant, but need to be public. The methods can be static. The score table is now regarded as owned by the mood or playlist. It is no longer listed in afs_tables[] and afs_table_operations can go away. We don't need the global score_table variable anymore because all public functions of score.c now take a pointer to the table to operate on. Similarly, current_mood and current_playlist can be removed.
* | Avoid double lookup on score row deletion.Andre Noll2026-03-17
| | | | | | | | | | | | | | | | | | | | | | | | The way mood.c and playlist.c call score_delete() ends up looking up the row in the score table twice. The problem is that score_delete() returns negative if the given row does not belong to the score table. All call sites handle this by first calling row_belongs_to_score_table(), which results in an additional lookup. Change score_delete() to return zero in the "row does not belong to the score table" case, and one if the row did exist (and was removed successfully). This not only avoids the double lookup but also simplifies the callers a bit.
* | Simplify and rename score_update().Andre Noll2026-03-17
|/ | | | | | We no longer need the percent parameter since the only remaining caller passes zero. Rename the function to score_move_to_end() since this it what it now does.
* Kill OSL_ERRNO_TO_PARA_ERROR.Andre Noll2025-07-13
| | | | | The users outside of error.h may as well call osl(), which leaves only a single caller in error.h. Open-code the macro there and remove it.
* Include regex.h from para.h.Andre Noll2025-05-19
| | | | Every .c file includes it anyway.
* Implement ls --admissible=m/foo.Andre Noll2023-05-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | Currently there can be only one score table at a time because the functions of score.c refer to the global score_table variable. To implement the new feature, we need to overcome this restriction so that the callback of the ls command can populate an independent score table to print its output without interfering with the score table that is currently active. This commit changes most functions of score.c to receive an additional table pointer argument. All current users of the score table pass a NULL pointer to instruct the functions to operate on the global score table as before. However, if the ls command is invoked with an optional mood argument to -a. the callback calls mood_load(), followed by mood_loop() and mood_unload(). The former returns an opaque handle which is then passed to the other two functions to instruct them to operate on the temporary score table instead of the global one. To make the feature work for playlists as well, analogous functionality is implemented in playlist.c. The new mop_loop() of aft.c performs the disambiguation in a similar way as the activate_mood_or_playlist() does. It is a bit simpler though, since the ls command does not have to deal with NULL arguments and does not need to fall back to the dummy mood.
* Assume that score_open() and score_clear() always succeed.Andre Noll2022-10-17
| | | | | | | | | Since the score table has only volatile columns, the only possible error is memory exhaustion, in which case we can only abort anyway. This patch changes score_open() to abort if osl_open() fails. This allows us to let score_clear() return void. We can't get rid of the return value of score_open(), however, since a pointer to this function is stored the afs table operations structure.
* afs: Replace ->init of afs tables by table operations.Andre Noll2022-10-17
| | | | | | This is simpler, avoids the run-time initialization, and allows us to mark the instances of the operations structures constant. Improve the documentation a bit while at it.
* Simplify row_belongs_to_score_table().Andre Noll2022-10-17
| | | | | | | | | | | | | This function was over-engineered because only one caller passed a non-NULL rank pointer without actually using the rank for anything other than printing it in a log message. So drop the rank parameter and adjust the callers and the log message accordingly. Moreover, the function returned int rather than bool to be able to also return an error code in case the osl lookup function fails. This should never happen though, because the only possible errors are invalid row or table pointers, and these indicate a bug. So abort in this case and let the function return bool.
* Rename admissible_file_loop() -> score_loop().Andre Noll2022-10-17
| | | | | | | | | The function simply iterates the entries of the score table. The new name is shorter, more to the point, and indicates that the function is implemented in score.c. Streamline the documentation while at it and swap the arguments, as the reversed order is more natural.
* Remove get_num_admissible_files().Andre Noll2022-10-17
| | | | | | | | | This public function had only one caller outside of score.c and this caller already knows the number of admissible files because this number is also stored in the afs statistics structure. Open-coding the remaining caller in score.c allows us to remove the public function.
* score.c: Remove event handler.Andre Noll2022-10-17
| | | | | Event handlers are optional, and the one for the score table did not do anything, so..
* score.c: Merge score_add into score_update().Andre Noll2022-10-17
| | | | The function is simple and has only one caller.
* score.c: Remove pointless assignment.Andre Noll2022-10-17
| | | | | The value is NULL anyway because the score table description was declared as a global static variable.
* string: Rename para_malloc() -> alloc().Andre Noll2022-07-29
| | | | | | | Just because it's shorter and matches the naming of the new allocators we are about to introduce. The bulk of this patch was created with sed -i 's/para_malloc/alloc/g' *.c *.h yy/mp.y
* score.c: Don't try to document possible error codes.Andre Noll2022-03-24
| | | | Every single one of these was incomplete or outdated.
* score.c: Remove pointless comments.Andre Noll2022-03-24
| | | | | Static functions don't need doxygen comments. The two comments removed by this commit did not add any value anyway.
* score.c: Improve documentation of score_compare().Andre Noll2022-03-24
| | | | | Reword the text to focus on why we dance twice. Also put it on dedox because it is static.
* score.c: Shorten documentation of get_score_of_row().Andre Noll2022-03-24
| | | | | This function is static, and its implementation is shorter than its documentation, which mostly consists of pointless boilerplate text.
* Shorten copyright notice.Andre Noll2017-09-22
| | | | | | | | | | | | | | | | | | | | | The GPLv2 line does not add any additional information, so drop it. This leaves a single line of legalese text for most files, which is about the amount of screen real estate it deserves. This patch was created with the following script (plus some manual fixups): awk '{ if (NR <= 5) { gs = gensub(/.*Copyright.* ([0-9]+).*Andre Noll.*/, "\\1", "g") if (gs != $0) year = gs next } if (NR == 6 && year != "") printf("/* Copyright (C) %s Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */\n", year) print }'
* doxygen: Add \ref to references.Andre Noll2017-06-25
| | | | | This way doxygen issues a warning if the file/function/structure no longer exists and a stale reference remains.
* doxygen: Don't refer to libosl functions.Andre Noll2017-06-25
| | | | | They are not part of the tree, and there is no dedicated man page for them.
* server: Convert com_lsatt() to lopsub.Andre Noll2017-03-26
| | | | | | | | | | | | | | | | | | | | This is the first afs subcommand which needs to pass a pattern list to its callback. The new send_lls_callback_request() provides this functionality. It serializes the parse result into a buffer and passes this buffer to the callback. Since there are non-lopsub commands which also pass a pattern list, action_if_pattern_matches() is patched to receive the pattern list either from the serialized parse result or in the old way via pmd->data. To achieve this, a parse result pointer is added to struct pattern_match_data. If this pointer is not NULL, we are dealing with a subcommand that has been converted. Since the ls subcommand has not been converted yet, lopsub will regard "ls" as a uniqe abbreviation of the lsatt command, which breaks t0004. To work around this, we deactivate prefix matching by only accepting exact matches in run_command(). This workaround can be removed after com_ls() has been converted.
* score.c: Add OSL_UNIQUE to storage flags of score column.Andre Noll2015-01-18
| | | | | The comparator for this column never returns 0 unless the objects being compared coincide.
* Update year in copyright headers.Andre Noll2015-01-12
| | | | | | | | | | | | | | | | Done with files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2014\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2014 Andre Noll/Copyright (C) \1 Andre Noll/1' $files In previous years we ran a similar script to set the second year in the range to the current year. This is kind of silly, so let's get rid of this useless information. This commit replaces "Copyright (C) A-B" by "Copyright (C) A" in all file headers, i.e. only the first year (A) is left in. Accurate information including time stamps for each change can be obtained from the git history.
* score.c: Remove unused admissible_file_loop_reverse().Andre Noll2015-01-12
| | | | Found by cppcheck.
* doc: Change email address to maan@tuebingen.mpg.deAndre Noll2014-08-18
| | | | | | | | | | | | | | The mail server on systemlinux.org was down for more than a week lately, so let's use an alternative official address. This commit changes all maan@systemlinux.org addresses to maan@tuebingen.mpg.de. Most .c and .h files contain the email address in the copyright header, so they must all be patched. Three other files contain the address for a different reason: * README lists email and git, gitweb and home page URLs * configure.ac needs it for configure -h * version.c contains it for the -V option of all commands
* Change copyright year to 2014.Andre Noll2014-02-22
| | | | | | | | | This year, we're really on time. The changes in this patch were created by the following silly script: files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2013\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2013 Andre Noll/Copyright (C) \1-2014 Andre Noll/1' $files sed --in-place= -e 's/Copyright (C) 2013 Andre Noll/Copyright (C) 2013-2014 Andre Noll/1' $files
* score: Improve documentation of score_update().Andre Noll2013-09-04
| | | | | Remove a stray "and" and the list of possible errors, which is not very useful and possibly incomplete.
* Change copyright year to 2013.Andre Noll2013-03-25
| | | | Better late than never.
* Change year in copyright message to 2012.Andre Noll2012-01-07
|
* score: Fix use of uninitialized memory on 64 bit machines.Andre Noll2011-03-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The score of an audio file in the score table is defined as a quantity which is sizeof(long) bytes large, i.e. 4 bytes on 32bit systems and 8 bytes on 64 bit systems. This is not a problem per se because the score column lives only in memory, so we do not have to worry about incompatibilities of the on-disk layout. However, at several places in score.c we cast the pointer to the osl object to (int *) rather than (long *). When writing to the object on a 64 bit machine, this will only set 4 out of the 8 allocated bytes, the other four bytes stay uninitialized. The "ls" command uses the correct cast to (long *) and reads the full 8 bytes. This causes valgrind to complain: ==5433== Conditional jump or move depends on uninitialised value(s) ==5433== at 0x4164F4: prepare_ls_row (aft.c:1334) ==5433== by 0x4E2F421: osl_rbtree_loop (osl.c:1457) ==5433== by 0x418935: admissible_file_loop (score.c:255) ==5433== by 0x41601A: com_ls_callback (aft.c:1363) ==5433== by 0x411FDE: command_post_select (afs.c:842) ==5433== by 0x41B67A: schedule (sched.c:76) ==5433== by 0x411ACF: afs_init (afs.c:986) ==5433== by 0x408863: main (server.c:451) ==5433== ==5433== Conditional jump or move depends on uninitialised value(s) ==5433== at 0x41650A: prepare_ls_row (aft.c:1334) ==5433== by 0x4E2F421: osl_rbtree_loop (osl.c:1457) ==5433== by 0x418935: admissible_file_loop (score.c:255) ==5433== by 0x41601A: com_ls_callback (aft.c:1363) ==5433== by 0x411FDE: command_post_select (afs.c:842) ==5433== by 0x41B67A: schedule (sched.c:76) ==5433== by 0x411ACF: afs_init (afs.c:986) ==5433== by 0x408863: main (server.c:451) Fix this bug by always casting to (long *).
* Replace 2010 in copyright message by 2011.Andre Noll2011-01-17
|
* Change year in COPYRIGHT to 2010.Andre Noll2010-04-05
| | | | Hey, this is earlier than last year :)
* Introduce para_regcomp.Andre Noll2009-07-08
| | | | | | | | | | | | | A wrapper for regcomp() that logs an error message if the regcomp() failed and uses a return value according to the paraslash rules. Currently there is only one user of regular expressions, is_v4_dot_quad(), which is converted to para_regex(), but new callers will be added soon. Unfortunately, this change made it necessary to include regex.h in all .c files that use string.h. Clean up the order in which headers are included a bit while we're at it. Maybe I should rethink the rule "Only .c files shall include header files"...
* Fix para_strerror() and use osl() wrapper for osl library calls.Andre Noll2009-06-12
|
* First draft of the libosl patch series.Andre Noll2009-06-12
|
* Change year of copyright from 2008 to 2009.Andre Noll2009-01-10
|
* score_update(): Don't return an error if file is not admissible.Andre Noll2008-07-07
| | | | | | | This function is called whenever the afs_info struct changed, for example if the user executed a touch command. Simply ignore the request to update the score in case the file is not contained in the score table.
* Change year in Copyright comment from 2007 to 2008.Andre Noll2008-01-08
|
* Turn PARA_STRERROR into an inline function.Andre Noll2007-12-28
| | | | Add documentation and an assertion for (num > 0).
* Avoid some gcc warnings.Andre Noll2007-11-11
|
* score.c: Use the new OSL_DONT_FREE flag for the aft column.Andre Noll2007-11-02
| | | | | | | | | The score tables stores in one of its columns a pointer to a row in the audio file table. This means for each admissible file we're allocating space for a void* pointer to store the aft pointer. It's simpler and probably faster to store the afs pointer directly, but of course that pointer must not be freed by the osl.
* Doxygen fixes.Andre Noll2007-10-25
|
* Complete afs event handling.Andre Noll2007-10-21
| | | | | | | | | | | Add blob event handling. This definitely needs some more fine-tuning, but that can be changed gradually thanks to the generic event handling code. In playlist mode there's nothing to do, as we're not interested in any blob events. So install only a dummy handler for the scoring system and decide whether to reload the score table in mood.c.
* Implement afs events.Andre Noll2007-10-18
|