diff options
| author | 2024-04-29 07:43:01 +0200 | |
|---|---|---|
| committer | 2024-04-29 07:43:01 +0200 | |
| commit | 8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75 (patch) | |
| tree | 7d896846e16d6324d16e061a2bc08cfc0183efb0 /data.c | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75.tar.gz snac2-8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75.tar.xz snac2-8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75.zip | |
Start of list support.
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 62 |
1 files changed, 62 insertions, 0 deletions
| @@ -1729,6 +1729,68 @@ xs_list *tag_search(char *tag, int skip, int show) | |||
| 1729 | } | 1729 | } |
| 1730 | 1730 | ||
| 1731 | 1731 | ||
| 1732 | /** lists **/ | ||
| 1733 | |||
| 1734 | xs_list *list_maint(snac *user, const char *list, int op) | ||
| 1735 | { | ||
| 1736 | xs_list *l = NULL; | ||
| 1737 | |||
| 1738 | switch (op) { | ||
| 1739 | case 0: /** list of lists **/ | ||
| 1740 | { | ||
| 1741 | FILE *f; | ||
| 1742 | xs *spec = xs_fmt("%s/list/" "*.id", user->basedir); | ||
| 1743 | xs *ls = xs_glob(spec, 0, 0); | ||
| 1744 | int c = 0; | ||
| 1745 | char *v; | ||
| 1746 | |||
| 1747 | l = xs_list_new(); | ||
| 1748 | |||
| 1749 | while (xs_list_next(ls, &v, &c)) { | ||
| 1750 | if ((f = fopen(v, "r")) != NULL) { | ||
| 1751 | xs *title = xs_readline(f); | ||
| 1752 | fclose(f); | ||
| 1753 | |||
| 1754 | title = xs_strip_i(title); | ||
| 1755 | xs *md5 = xs_md5_hex(title, strlen(title)); | ||
| 1756 | |||
| 1757 | /* return [ list_id, list_title ] */ | ||
| 1758 | l = xs_list_append(l, xs_list_append(xs_list_new(), md5, title)); | ||
| 1759 | } | ||
| 1760 | } | ||
| 1761 | } | ||
| 1762 | |||
| 1763 | break; | ||
| 1764 | |||
| 1765 | case 1: /** create new list (list is the name) **/ | ||
| 1766 | { | ||
| 1767 | FILE *f; | ||
| 1768 | xs *dir = xs_fmt("%s/list/", user->basedir); | ||
| 1769 | xs *md5 = xs_md5_hex(list, strlen(list)); | ||
| 1770 | |||
| 1771 | mkdirx(dir); | ||
| 1772 | |||
| 1773 | xs *fn = xs_fmt("%s%s.id", dir, md5); | ||
| 1774 | |||
| 1775 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 1776 | fprintf(f, "%s\n", list); | ||
| 1777 | fclose(f); | ||
| 1778 | } | ||
| 1779 | } | ||
| 1780 | |||
| 1781 | break; | ||
| 1782 | |||
| 1783 | case 2: /** delete list (list is md5 id) **/ | ||
| 1784 | break; | ||
| 1785 | |||
| 1786 | case 3: /** list content (list is md5 id) **/ | ||
| 1787 | break; | ||
| 1788 | } | ||
| 1789 | |||
| 1790 | return l; | ||
| 1791 | } | ||
| 1792 | |||
| 1793 | |||
| 1732 | /** static data **/ | 1794 | /** static data **/ |
| 1733 | 1795 | ||
| 1734 | static int _load_raw_file(const char *fn, xs_val **data, int *size, | 1796 | static int _load_raw_file(const char *fn, xs_val **data, int *size, |