summaryrefslogtreecommitdiff
path: root/src/strll.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/strll.c')
-rw-r--r--src/strll.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/strll.c b/src/strll.c
new file mode 100644
index 0000000..fd47b5e
--- /dev/null
+++ b/src/strll.c
@@ -0,0 +1,77 @@
+// GPGEdit edits GPG encrypted files
+// Copyright (C) 2018 Aaron Ball <nullspoon@oper.io>
+//
+// 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 <https://www.gnu.org/licenses/>.
+
+#include "strll.h"
+
+struct strll* strll_new() {
+ struct strll* out;
+ out = malloc(sizeof(struct strll));
+ out->next = NULL;
+ out->str = NULL;
+
+ return out;
+}
+
+
+struct strll* strll_add(struct strll* listitem, char* str) {
+ struct strll* cur = listitem;
+
+ // If str == null, we're inside the first item of a new list
+ if(cur->str == NULL) {
+ cur->str = malloc(sizeof(char) * (strlen(str) + 1));
+ strcpy(cur->str, str);
+ cur->next = NULL;
+ return cur;
+ }
+
+ // Traverse to the last item in the list
+ while(cur->next != NULL)
+ cur = cur->next;
+
+ // Allocate the next item and update the next pointer
+ cur->next = malloc(sizeof(struct strll));
+ // Repoint cur to the newly allocated struct
+ cur = cur->next;
+
+ // Allocate string, copy in, and set next to null
+ cur->str = malloc(sizeof(char) * (strlen(str) + 1));
+ strcpy(cur->str, str);
+ cur->next = NULL;
+
+ return cur;
+}
+
+
+void strll_release(struct strll* listitem) {
+ struct strll* item = listitem;
+ struct strll* next = NULL;
+
+ while(item != NULL) {
+ next = item->next;
+ free(item->str);
+ free(item);
+ item = next;
+ }
+}
+
+
+void strll_dump(struct strll* listitem) {
+ struct strll* cur = listitem;
+ while(cur != NULL) {
+ printf("%s\n", cur->str);
+ cur = cur->next;
+ }
+}

Generated by cgit