ref: a3ab642abb64603e3fbef313dee420a704e95563
parent: fff686c2f47cc41c09328e9f5bffe5b4a1037281
author: Tevo <estevan.cps@gmail.com>
date: Fri Nov 20 20:46:38 EST 2020
Filesystem stub
--- a/cue.c
+++ b/cue.c
@@ -19,6 +19,43 @@
return emallocz(sizeof(Cuesheet), 1);
}
+void
+maybefree(void *s, void *p)
+{
+ if(p != nil && p != s)
+ free(p);
+}
+
+void
+recfreeentries(Cuesheet *s, Entry *cur)
+{
+ if(cur == nil)
+ return;
+ recfreeentries(s, cur->next);
+ maybefree(nil, cur->starts);
+ /* file should get freed by the cuesheet */
+ maybefree(nil, cur->title);
+ maybefree(s->performer, cur->performer);
+}
+
+void
+recfreefiles(Cuesheet *s, AFile *cur)
+{
+ if(cur == nil)
+ return;
+ recfreefiles(s, cur->next);
+ maybefree(nil, cur->name);
+}
+
+void
+freesheet(Cuesheet *s)
+{
+ recfreeentries(s, s->entries);
+ recfreefiles(s, s->files);
+ maybefree(nil, s->title);
+ maybefree(nil, s->performer);
+}
+
AFile*
lastfile(Cuesheet *c)
{
@@ -126,4 +163,21 @@
atleast(c->curentry, i);
c->curentry->starts[i] = t;
+}
+
+char*
+formatext(AFile *f)
+{
+ char *tab[] =
+ {
+ [MP3] = "mp3",
+ [AIFF] = "aiff",
+ [BINARY] = "pcm",
+ [MOTOROLA] = "" /* not sure */
+ };
+
+ if(f->type != WAVE)
+ return tab[f->type];
+
+ return "wav"; /* FIXME */
}
--- a/cuefs.h
+++ b/cuefs.h
@@ -63,6 +63,7 @@
Timestamp parsetime(int, int, int);
Cuesheet* newsheet(void);
+void freesheet(Cuesheet*);
void setperformer(Cuesheet*, char*);
void settitle(Cuesheet*, char*);
@@ -69,3 +70,7 @@
void addfile(Cuesheet*, char*, int);
void addnewtrack(Cuesheet*, int);
void settimestamp(Cuesheet*, int, Timestamp);
+
+char* formatext(AFile*);
+
+void cuefsinit(Cuesheet*, char*);
--- a/fs.c
+++ b/fs.c
@@ -1,7 +1,56 @@
#include <u.h>
#include <libc.h>
+#include <fcall.h>
+#include <thread.h>
+#include <9p.h>
#include "cuefs.h"
#include "y.tab.h"
+char *Estub = "not yet";
+
Cuesheet *cursheet;
+
+void
+fsopen(Req *r)
+{
+ respond(r, nil);
+}
+
+void
+fsread(Req *r)
+{
+ respond(r, Estub);
+}
+
+void
+fsend(Srv *s)
+{
+ freesheet(s->aux);
+}
+
+Srv fs =
+{
+ .open = fsopen,
+ .read = fsread,
+
+ .end = fsend
+};
+
+void
+cuefsinit(Cuesheet *sheet, char *mtpt)
+{
+ char *s;
+
+ fs.aux = sheet;
+ fs.tree = alloctree(nil, nil, DMDIR | 0444, nil);
+
+ for(Entry *e = sheet->entries; e != nil; e = e->next)
+ {
+ s = smprint("%02d - %s.%s", e->index, e->title, formatext(e->file));
+ createfile(fs.tree->root, s, nil, 0444, e);
+ free(s);
+ }
+
+ postmountsrv(&fs, nil, mtpt, MREPL);
+}
--- a/main.c
+++ b/main.c
@@ -8,7 +8,7 @@
void
usage(void)
{
- fprint(2, "usage: %s\n", argv0);
+ fprint(2, "usage: %s [-D] [-m mtpt] file\n", argv0);
exits("usage");
}
@@ -15,7 +15,16 @@
void
main(int argc, char **argv)
{
+ extern int chatty9p;
+ char *mtpt = "/n/cue";
+
ARGBEGIN {
+ case 'D':
+ chatty9p++;
+ break;
+ case 'm':
+ mtpt = EARGF(usage());
+ break;
default:
usage();
} ARGEND;
@@ -33,6 +42,8 @@
yyparse();
close(infd);
+
+ cuefsinit(cursheet, mtpt);
exits(0);
}