Skip to content

Commit

Permalink
module.c: Allow modulerefs command to match without .so suffix.
Browse files Browse the repository at this point in the history
For months, I've been trying to use this command by specifying module
names without their file extension (.so). Turns out, the command
as written only matched full module names, including the extension.
Update it so that it will work with both names that do and don't
include the extension suffix.

LBBS-3 #close
  • Loading branch information
InterLinked1 committed Dec 23, 2024
1 parent fb59950 commit a1e12c2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
37 changes: 26 additions & 11 deletions bbs/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,20 @@ static int log_module_ref(struct bbs_module *mod, int pair, void *refmod, const
size_t fflen = filelen + strlen(func) + 2;

r = calloc(1, sizeof(*r) + fflen);
if (ALLOC_SUCCESS(r)) {
strcpy(r->data, file); /* Safe */
r->file = r->data;
strcpy(r->data + filelen + 1, func); /* Safe */
r->func = r->data + filelen + 1;
r->line = line;
r->refmod = refmod;
r->pair = pair;
RWLIST_INSERT_HEAD(&mod->refs, r, entry); /* Head insert absolutely makes perfect sense */
if (ALLOC_FAILURE(r)) {
/* Allocation of the module reference structure failed.
* It's still being used regardless, so we won't decrement usecount in response. */
RWLIST_UNLOCK(&mod->refs);
return -1;
}
strcpy(r->data, file); /* Safe */
r->file = r->data;
strcpy(r->data + filelen + 1, func); /* Safe */
r->func = r->data + filelen + 1;
r->line = line;
r->refmod = refmod;
r->pair = pair;
RWLIST_INSERT_HEAD(&mod->refs, r, entry); /* Head insert absolutely makes perfect sense */
} else { /* Unref */
RWLIST_TRAVERSE_SAFE_BEGIN(&mod->refs, r, entry) {
if (r->pair == pair && !strcmp(r->file, file)) { /* Pair IDs are only unique within a source file */
Expand Down Expand Up @@ -1351,11 +1355,22 @@ static int list_modulerefs(int fd, const char *name)
{
struct bbs_module *mod;
int i = 0;
size_t compchars = 0;

bbs_dprintf(fd, "%-30s %3s %2s %-30s %s\n", "Module", "#", "PR", "Reffing Module", "Ref Location");

/* Allow comparison without the .so suffix. */
if (!strlen_zero(name)) {
char *period = strchr(name, '.');
if (period) {
compchars = (size_t) (period - name);
} else {
compchars = strlen(name);
}
}

RWLIST_TRAVERSE(&modules, mod, entry) {
if (!name || !strcasecmp(name, mod->name)) {
if (!name || !strncasecmp(name, mod->name, compchars)) {
int c = 0;
struct bbs_module_reference *r;
/* Dump refs */
Expand All @@ -1376,7 +1391,7 @@ static int list_modulerefs(int fd, const char *name)
}
}
if (name && !mod) {
bbs_dprintf(fd, "Module '%s' not found\n", name);
bbs_dprintf(fd, "No module references found for '%s'\n", name);
return -1;
} else if (!name) {
bbs_dprintf(fd, "%d total reference%s\n", i, ESS(i));
Expand Down
3 changes: 3 additions & 0 deletions modules/mod_sysop.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ static void *sysop_handler(void *varg)
bbs_dprintf(sysopfdout, "/");
awaitcmd:
my_set_stdout_logging(sysopfdout, 0); /* Disable logging so other stuff isn't trying to write to STDOUT at the same time. */
/* One downside of this approach is if the user hits UP to retrieve a command from history,
* we're not yet in "edit move", so the user can't start typing to append to it.
* However, BACKSPACE will enter edit mode, after which characters can be appended. */
bbs_buffer_input(sysopfdin, 1);
res = poll(pfds, console->remote ? 1 : 2, 300000);
if (res < 0) {
Expand Down

0 comments on commit a1e12c2

Please sign in to comment.