aboutsummaryrefslogtreecommitdiff
path: root/src/alias.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2016-03-07 15:00:21 +0000
committerIan C <ianc@noddybox.co.uk>2016-03-07 15:00:21 +0000
commit77e8708934c5c792b1435fa11dfe3c0a6f636a8c (patch)
tree8c68ecddaf2c2c0730ba310b8d1b9e0f1bd16132 /src/alias.c
parent6e9c9c9205d6eec1ff1cfb3fa407c6714854145a (diff)
Updated README and copied latest version in.
Diffstat (limited to 'src/alias.c')
-rw-r--r--src/alias.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/alias.c b/src/alias.c
new file mode 100644
index 0000000..01017bd
--- /dev/null
+++ b/src/alias.c
@@ -0,0 +1,146 @@
+/*
+
+ casm - Simple, portable assembler
+
+ Copyright (C) 2003-2015 Ian Cowburn (ianc@noddybox.demon.co.uk)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ -------------------------------------------------------------------------
+
+ Collection for aliases.
+
+*/
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "global.h"
+#include "alias.h"
+
+
+/* ---------------------------------------- TYPES
+*/
+
+typedef struct alias
+{
+ char *command;
+ char *alias;
+ struct alias *next;
+} Alias;
+
+
+/* ---------------------------------------- GLOBALS
+*/
+static Alias *head;
+static Alias *tail;
+
+
+/* ---------------------------------------- PRIVATE FUNCTIONS INTERFACES
+*/
+static Alias *FindAlias(const char *p)
+{
+ Alias *a = head;
+
+ while(a)
+ {
+ if (CompareString(a->command, p))
+ {
+ return a;
+ }
+
+ a = a->next;
+ }
+
+ return NULL;
+}
+
+
+static void AddAlias(const char *p, const char *r)
+{
+ Alias *a = FindAlias(p);
+
+ if (!a)
+ {
+ a = Malloc(sizeof *a);
+
+ a->command = DupStr(p);
+ a->alias = DupStr(r);
+ a->next = NULL;
+
+ if (tail)
+ {
+ tail->next = a;
+ }
+
+ tail = a;
+
+ if (!head)
+ {
+ head = a;
+ }
+ }
+ else
+ {
+ free(a->alias);
+ a->alias = DupStr(r);
+ }
+}
+
+
+/* ---------------------------------------- INTERFACES
+*/
+
+void AliasClear()
+{
+ while(head)
+ {
+ Alias *a;
+
+ free(head->command);
+ free(head->alias);
+ a = head;
+ head = head->next;
+ free(a);
+ }
+
+ head = NULL;
+ tail = NULL;
+}
+
+
+void AliasCreate(const char *command, const char *alias)
+{
+ AddAlias(command, alias);
+}
+
+
+char *AliasExpand(char *command)
+{
+ Alias *a;
+
+ if ((a = FindAlias(command)))
+ {
+ free(command);
+ command = DupStr(a->alias);
+ }
+
+ return command;
+}
+
+
+/*
+vim: ai sw=4 ts=8 expandtab
+*/