<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
img {
max-width: 100%;
height: auto;
}
p.details {
font-style:italic;
color:#777
}
.footer p {
font-size:small;
color:#777
}
pre.commit-message {
white-space: pre-wrap;
}
.file-stats a {
text-decoration: none;
}
.file-stats .new-file {
color: #090;
}
.file-stats .deleted-file {
color: #B00;
}
</style>
<body>
<div class='content'>
<h3>Andrew Price pushed to branch master at <a href="https://projects.sucs.org/arthur/mw">Justin Mitchell / mw</a></h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d">a4e85793</a></strong>
<div>
<span>by Andrew Price</span>
<i>at 2015-11-08T23:56:19Z</i>
</div>
<pre class='commit-message'>Tidy up some alias list-related clutter
Also make the alias type not-a-pointer to improve readability and
allocate all of the memory required for an alias in one go.</pre>
</li>
</ul>
<h4>11 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
src/client/Parse.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
src/client/alias.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-2'>
src/client/alias.h
</a>
</li>
<li class='file-stats'>
<a href='#diff-3'>
src/client/incoming.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-4'>
src/client/init.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-5'>
src/client/js.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-6'>
src/client/main.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-7'>
src/client/newmain.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-8'>
src/client/script.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-9'>
src/client/script_inst.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-10'>
src/client/talker.c
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-0'>
<strong>
src/client/Parse.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/Parse.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/Parse.c
</span><span style="color: #aaaaaa">@@ -8,14 +8,12 @@
</span> #include "user.h"
#include "talker_privs.h"
#include "userio.h"
<span style="color: #000000;background-color: #ddffdd">+#include "alias.h"
</span>
extern unsigned long rights;
extern CommandList chattable[];
extern struct user * const user;
<span style="color: #000000;background-color: #ffdddd">-#include "alias.h"
-extern Alias alias_list;
-
</span> static void shuffle_up(char *bp)
{
/* The strlen is right its the length of bp, which is the length
<span style="color: #aaaaaa">@@ -108,7 +106,7 @@ int DoCommand(char *input, CommandList *cm)
</span> CommandList *found=NULL, *exact=NULL, *backup;
int count=0, ecount=0;
int c;
<span style="color: #000000;background-color: #ffdddd">- Alias al;
</span><span style="color: #000000;background-color: #ddffdd">+ alias *al;
</span> const char *dowhat;
char *text;
char *args = NULL, *ptr, *p2, *tmp;
</code></pre>
<br>
</li>
<li id='diff-1'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-1'>
<strong>
src/client/alias.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/alias.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/alias.c
</span><span style="color: #aaaaaa">@@ -11,77 +11,52 @@
</span> #include "userio.h"
#include "alias.h"
<span style="color: #000000;background-color: #ffdddd">-Alias alias_list=NULL;
-Alias bind_list=NULL;
-Alias rpc_list=NULL;
-Alias event_list=NULL;
-Alias onoff_list=NULL;
-Alias ipc_list=NULL;
-Alias force_list=NULL;
-Alias shutdown_list=NULL;
-Alias eventin_list=NULL;
</span><span style="color: #000000;background-color: #ddffdd">+alias *alias_list = NULL;
+alias *bind_list = NULL;
+alias *rpc_list = NULL;
+alias *event_list = NULL;
+alias *onoff_list = NULL;
+alias *ipc_list = NULL;
+alias *force_list = NULL;
+alias *shutdown_list = NULL;
+alias *eventin_list = NULL;
</span>
/* completely destroys the given list */
<span style="color: #000000;background-color: #ffdddd">-void DestroyAllLinks(Alias *list)
</span><span style="color: #000000;background-color: #ddffdd">+void DestroyAllLinks(alias **list)
</span> {
<span style="color: #000000;background-color: #ffdddd">- Alias free_me;
-
- while (*list!=NULL)
- {
- free((*list)->from);
- free((*list)->to);
- free_me = *list;
- *list = (*list)->next;
- free(free_me);
</span><span style="color: #000000;background-color: #ddffdd">+ for (alias *node = *list; node != NULL; node = *list) {
+ *list = node->next;
+ free(node);
</span> }
}
/* removes the link given by 'name' in the list */
<span style="color: #000000;background-color: #ffdddd">-int DestroyLink(Alias *list, const char *name)
</span><span style="color: #000000;background-color: #ddffdd">+int DestroyLink(alias **list, const char *name)
</span> {
<span style="color: #000000;background-color: #ffdddd">- Alias prev, aptr;
- int found = 0;
-
- aptr = *list;
- prev=NULL;
- while (aptr!=NULL)
- {
- if (!strcasecmp(aptr->from, name))
- {
- found = 1;
- free(aptr->from);
- free(aptr->to);
- if (prev == NULL)
- {
- /* first */
- *list = aptr->next;
- }
- else if (aptr->next == NULL)
- {
- /* last */
- prev->next = NULL;
- }
- else
- {
- /* middle */
- prev->next = aptr->next;
- }
- free(aptr);
- break;
- }
- prev = aptr;
- aptr = aptr->next;
</span><span style="color: #000000;background-color: #ddffdd">+ alias **prevnext = list;
+ alias *entry = *list;
+
+ while (entry != NULL) {
+ if (!strcasecmp(entry->from, name))
+ break;
+ prevnext = &entry->next;
+ entry = entry->next;
</span> }
<span style="color: #000000;background-color: #ffdddd">- return(found);
</span><span style="color: #000000;background-color: #ddffdd">+ if (entry == NULL)
+ return 0; /* Not found or empty */
+
+ *prevnext = entry->next;
+ free(entry);
+ return 1;
</span> }
/* adds the 'from/to' node to the given list, or redefines if in existance */
<span style="color: #000000;background-color: #ffdddd">-int AddLink(Alias *list, const char *from, const char *to)
</span><span style="color: #000000;background-color: #ddffdd">+int AddLink(alias **list, const char *from, const char *to)
</span> {
<span style="color: #000000;background-color: #ffdddd">- Alias new;
</span><span style="color: #000000;background-color: #ddffdd">+ alias *new = *list;
</span> int redefine = 0;
<span style="color: #000000;background-color: #ddffdd">+ size_t size, fromsize;
</span>
<span style="color: #000000;background-color: #ffdddd">- new=*list;
</span> while (new!=NULL && strcasecmp(new->from, from))
new=new->next;
<span style="color: #aaaaaa">@@ -91,22 +66,24 @@ int AddLink(Alias *list, const char *from, const char *to)
</span> redefine = 1;
}
<span style="color: #000000;background-color: #ffdddd">- new=(Alias)malloc(sizeof(struct alias_record));
- new->from=malloc(sizeof(char) * (strlen(from) + 1));
- new->to=malloc(sizeof(char) * (strlen(to) + 1));
</span><span style="color: #000000;background-color: #ddffdd">+ fromsize = strlen(from) + 1;
+ size = sizeof(*new) + (strlen(to) + 1) + fromsize;
+ new = calloc(1, size);
+ new->from = (char *)(new + 1);
+ new->to = new->from + fromsize;
</span> strcpy(new->from,from);
strcpy(new->to,to);
<span style="color: #000000;background-color: #ffdddd">- new->next=*list;
- *list=new;
</span><span style="color: #000000;background-color: #ddffdd">+ new->next = *list;
+ *list = new;
</span>
<span style="color: #000000;background-color: #ffdddd">- return (redefine);
</span><span style="color: #000000;background-color: #ddffdd">+ return redefine;
</span> }
/* displays the list */
<span style="color: #000000;background-color: #ffdddd">-void ShowLinks(Alias list, const char *prompt, const char *link, int count)
</span><span style="color: #000000;background-color: #ddffdd">+void ShowLinks(alias *list, const char *prompt, const char *link, int count)
</span> {
char buff[10];
<span style="color: #000000;background-color: #ffdddd">- Alias al;
</span><span style="color: #000000;background-color: #ddffdd">+ alias *al;
</span> int max;
int screen_height = screen_h();
<span style="color: #aaaaaa">@@ -159,25 +136,23 @@ void ShowLinks(Alias list, const char *prompt, const char *link, int count)
</span> }
}
<span style="color: #000000;background-color: #ffdddd">-char *FindLinks(Alias list, const char *from)
</span><span style="color: #000000;background-color: #ddffdd">+char *FindLinks(alias *list, const char *from)
</span> {
<span style="color: #000000;background-color: #ffdddd">- Alias al;
</span><span style="color: #000000;background-color: #ddffdd">+ alias *al = list;
</span>
<span style="color: #000000;background-color: #ffdddd">- al = list;
- while (al!=NULL && strcasecmp(from, al->from))
- {
- al=al->next;
- }
- if (al==NULL)
- return(NULL);
- else
- return(strdup(al->to));
</span><span style="color: #000000;background-color: #ddffdd">+ while (al != NULL && strcasecmp(from, al->from))
+ al = al->next;
+
+ if (al == NULL)
+ return NULL;
+
+ return strdup(al->to);
</span> }
/* bind listing autocompletion for scripts and tab-completion */
char *list_bind(const char *text, int state)
{
<span style="color: #000000;background-color: #ffdddd">- static Alias bind;
</span><span style="color: #000000;background-color: #ddffdd">+ static alias *bind;
</span> static int len;
char *name;
<span style="color: #aaaaaa">@@ -201,7 +176,7 @@ char *list_bind(const char *text, int state)
</span> /* bind listing autocompletion for readline */
char *list_bind_rl(const char *text, int state)
{
<span style="color: #000000;background-color: #ffdddd">- static Alias bind;
</span><span style="color: #000000;background-color: #ddffdd">+ static alias *bind;
</span> static int len;
char *name;
<span style="color: #aaaaaa">@@ -224,11 +199,8 @@ char *list_bind_rl(const char *text, int state)
</span> return NULL;
}
<span style="color: #000000;background-color: #ffdddd">-char *NextLink(Alias list, char *prev)
</span><span style="color: #000000;background-color: #ddffdd">+char *NextLink(alias *al, char *prev)
</span> {
<span style="color: #000000;background-color: #ffdddd">- Alias al;
-
- al = list;
</span> if (prev)
{
while(al && strcasecmp(al->from, prev)) al = al->next;
</code></pre>
<br>
</li>
<li id='diff-2'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-2'>
<strong>
src/client/alias.h
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/alias.h
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/alias.h
</span><span style="color: #aaaaaa">@@ -1,20 +1,29 @@
</span> #ifndef ALIAS_H
#define ALIAS_H
<span style="color: #000000;background-color: #ffdddd">-typedef struct alias_record
-{
</span><span style="color: #000000;background-color: #ddffdd">+typedef struct alias {
</span> char *from;
char *to;
<span style="color: #000000;background-color: #ffdddd">- struct alias_record *next;
-} *Alias;
</span><span style="color: #000000;background-color: #ddffdd">+ struct alias *next;
+} alias;
</span>
<span style="color: #000000;background-color: #ffdddd">-void DestroyAllLinks(Alias *list);
-int DestroyLink(Alias *list, const char *name);
-int AddLink(Alias *list, const char *from, const char *to);
-void ShowLinks(Alias list, const char *prompt, const char *link, int count);
-char *FindLinks(Alias list, const char *from);
</span><span style="color: #000000;background-color: #ddffdd">+void DestroyAllLinks(alias **list);
+int DestroyLink(alias **list, const char *name);
+int AddLink(alias **list, const char *from, const char *to);
+void ShowLinks(alias *list, const char *prompt, const char *link, int count);
+char *FindLinks(alias *list, const char *from);
</span> char *list_bind(const char *text, int state);
char *list_bind_rl(const char *text, int state);
<span style="color: #000000;background-color: #ffdddd">-char *NextLink(Alias list, char *prev);
</span><span style="color: #000000;background-color: #ddffdd">+char *NextLink(alias *list, char *prev);
+
+extern alias *alias_list;
+extern alias *bind_list;
+extern alias *rpc_list;
+extern alias *event_list;
+extern alias *onoff_list;
+extern alias *ipc_list;
+extern alias *force_list;
+extern alias *shutdown_list;
+extern alias *eventin_list;
</span>
#endif /* ALIAS_H */
</code></pre>
<br>
</li>
<li id='diff-3'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-3'>
<strong>
src/client/incoming.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/incoming.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/incoming.c
</span><span style="color: #aaaaaa">@@ -31,10 +31,6 @@
</span> #include <jansson.h>
#include <str_util.h>
<span style="color: #000000;background-color: #ffdddd">-extern Alias rpc_list;
-extern Alias event_list;
-extern Alias onoff_list;
-extern Alias ipc_list;
</span> extern struct user * const user;
extern int quietmode;
extern ipc_connection_t *ipcsock;
</code></pre>
<br>
</li>
<li id='diff-4'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-4'>
<strong>
src/client/init.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/init.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/init.c
</span><span style="color: #aaaaaa">@@ -19,16 +19,6 @@
</span> #include "js.h"
#include "init.h"
#include "user.h"
<span style="color: #000000;background-color: #ffdddd">-
-extern Alias alias_list;
-extern Alias bind_list;
-extern Alias rpc_list;
-extern Alias event_list;
-extern Alias onoff_list;
-extern Alias ipc_list;
-extern Alias force_list;
-extern Alias shutdown_list;
-
</span> #include "script.h"
#include "frl.h"
</code></pre>
<br>
</li>
<li id='diff-5'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-5'>
<strong>
src/client/js.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/js.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/js.c
</span><span style="color: #aaaaaa">@@ -38,16 +38,6 @@
</span> #include "user.h"
#include "sqlite.h"
<span style="color: #000000;background-color: #ffdddd">-extern Alias alias_list;
-extern Alias bind_list;
-extern Alias rpc_list;
-extern Alias event_list;
-extern Alias onoff_list;
-extern Alias ipc_list;
-extern Alias force_list;
-extern Alias shutdown_list;
-extern Alias eventin_list;
-
</span> extern struct user * const user;
extern unsigned long rights;
extern int busy;
</code></pre>
<br>
</li>
<li id='diff-6'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-6'>
<strong>
src/client/main.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/main.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/main.c
</span><span style="color: #aaaaaa">@@ -50,15 +50,6 @@
</span> #include "userio.h"
#include "who.h"
#include "alias.h"
<span style="color: #000000;background-color: #ffdddd">-extern Alias bind_list;
-extern Alias alias_list;
-extern Alias rpc_list;
-extern Alias event_list;
-extern Alias onoff_list;
-extern Alias ipc_list;
-extern Alias force_list;
-extern Alias shutdown_list;
-extern Alias eventin_list;
</span>
static char version[]="Milliways III - Release "VER_MAJ"."VER_MIN"."VER_TWK"\n";
<span style="color: #aaaaaa">@@ -1461,8 +1452,6 @@ char **complete_entry(const char *text, int start, int end)
</span> {
script=script->next;
}
<span style="color: #000000;background-color: #ffdddd">-
- /* remove the memory used by funcname */
</span> free(funcname);
/* check the bound function exists */
</code></pre>
<br>
</li>
<li id='diff-7'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-7'>
<strong>
src/client/newmain.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/newmain.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/newmain.c
</span><span style="color: #aaaaaa">@@ -39,8 +39,6 @@
</span> #include "incoming.h"
#include <util.h>
<span style="color: #000000;background-color: #ffdddd">-extern Alias alias_list;
-
</span> extern int currentfolder,last_mesg;
extern FILE *output;
extern int busy; /* if true dont display messages i.e. during new/write */
</code></pre>
<br>
</li>
<li id='diff-8'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-8'>
<strong>
src/client/script.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/script.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/script.c
</span><span style="color: #aaaaaa">@@ -25,8 +25,6 @@
</span> #include "who.h"
#include <util.h>
<span style="color: #000000;background-color: #ffdddd">-extern Alias bind_list;
-
</span> #define MAX_ARGC 128
extern struct user * const user;
</code></pre>
<br>
</li>
<li id='diff-9'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-9'>
<strong>
src/client/script_inst.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/script_inst.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/script_inst.c
</span><span style="color: #aaaaaa">@@ -29,8 +29,6 @@
</span> #include "who.h"
extern struct user * const user;
<span style="color: #000000;background-color: #ffdddd">-extern Alias alias_list;
-extern Alias bind_list;
</span> /* current script runaway variable */
extern long runaway;
</code></pre>
<br>
</li>
<li id='diff-10'>
<a href='https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d#diff-10'>
<strong>
src/client/talker.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/talker.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/talker.c
</span><span style="color: #aaaaaa">@@ -33,16 +33,7 @@
</span> #include "who.h"
#include "mesg.h"
#include "incoming.h"
<span style="color: #000000;background-color: #ffdddd">-
</span> #include "alias.h"
<span style="color: #000000;background-color: #ffdddd">-extern Alias bind_list;
-extern Alias alias_list;
-extern Alias rpc_list;
-extern Alias event_list;
-extern Alias onoff_list;
-extern Alias ipc_list;
-extern Alias force_list;
-extern Alias shutdown_list;
</span>
extern int busy; /* if true dont display messages i.e. during new/write */
extern unsigned long rights;
</code></pre>
<br>
</li>
</div>
<div class='footer' style='margin-top: 10px;'>
<p>
—
<br>
<a href="https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d">View it on GitLab</a>
<br>
You're receiving this email because of your account on <a href="https://projects.sucs.org/">projects.sucs.org</a>.
If you'd like to receive fewer emails, you can adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Commit","url":"https://projects.sucs.org/arthur/mw/commit/a4e857931e30b695efe0ed2fa85934c19d6d9e8d"}}</script>
</p>
</div>
</body>
</html>