lib.[ch]: Rearrange the toplevel definitions into a more sensible order.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 25 Mar 2022 18:56:44 +0000 (18:56 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 25 Mar 2022 18:56:44 +0000 (18:56 +0000)
No code changes.

lib.c
lib.h

diff --git a/lib.c b/lib.c
index 2529f24..6772eec 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -138,81 +138,6 @@ off_t device_size(int fd, const char *file, int *blksz_out)
   return ((off_t)volsz);
 }
 
-void store_filename(char *buf, ident id)
-{
-  switch (id_kind(id)) {
-    case RAW:
-      sprintf(buf, "#<raw device>");
-      break;
-    case IFO:
-      if (!id_title(id)) sprintf(buf, "/VIDEO_TS/VIDEO_TS.IFO");
-      else sprintf(buf, "/VIDEO_TS/VTS_%02u_0.IFO", id_title(id));
-      break;
-    case BUP:
-      if (!id_title(id)) sprintf(buf, "/VIDEO_TS/VIDEO_TS.BUP");
-      else sprintf(buf, "/VIDEO_TS/VTS_%02u_0.BUP", id_title(id));
-      break;
-    case VOB:
-      if (!id_title(id)) sprintf(buf, "/VIDEO_TS/VIDEO_TS.VOB");
-      else
-       sprintf(buf, "/VIDEO_TS/VTS_%02u_%u.VOB", id_title(id), id_part(id));
-      break;
-    default:
-      abort();
-  }
-}
-
-static char *copy_string(char *p, const char *q)
-{
-  while (*q) *p++ = *q++;
-  *p = 0; return (p);
-}
-
-static char *copy_hex(char *p, const unsigned char *q, size_t sz)
-{
-  while (sz) {
-    sprintf(p, "%02x", *q);
-    p += 2; q++; sz--;
-  }
-  return (p);
-}
-
-int dvd_id(char *p, dvd_reader_t *dvd, unsigned f, const char *file)
-{
-  char volid[33];
-  unsigned char volsetid[16], discid[16];
-  int rc;
-  size_t n;
-
-  rc = DVDUDFVolumeInfo(dvd,
-                       volid, sizeof(volid),
-                       volsetid, sizeof(volsetid));
-  if (!rc) {
-    p = copy_string(p, volid);
-    *p++ = '-';
-    for (n = sizeof(volsetid); n && !volsetid[n - 1]; n--);
-    p = copy_hex(p, volsetid, n);
-  } else if (f&DIF_MUSTVOLINF) {
-    if (file) moan("failed to read volume info for `%s'", file);
-    else moan("failed to read volume info");
-    return (-1);
-  } else
-    p = copy_string(p, "<error reading volume info>");
-
-  *p++ = ':';
-  rc = DVDDiscID(dvd, discid);
-  if (!rc)
-    p = copy_hex(p, discid, sizeof(discid));
-  else if (f&DIF_MUSTIFOHASH) {
-    if (file) moan("failed to determine disc id of `%s'", file);
-    else moan("failed to determine disc id");
-    return (-1);
-  } else
-    p = copy_string(p, "<error reading disc-id>");
-
-  return (0);
-}
-
 struct progress_state progress = PROGRESS_STATE_INIT;
 static struct banner_progress_item banner_progress;
 
@@ -289,3 +214,78 @@ void open_dvd(const char *device, int mode,
   if (fd_out) *fd_out = fd;
   else close(fd);
 }
+
+void store_filename(char *buf, ident id)
+{
+  switch (id_kind(id)) {
+    case RAW:
+      sprintf(buf, "#<raw device>");
+      break;
+    case IFO:
+      if (!id_title(id)) sprintf(buf, "/VIDEO_TS/VIDEO_TS.IFO");
+      else sprintf(buf, "/VIDEO_TS/VTS_%02u_0.IFO", id_title(id));
+      break;
+    case BUP:
+      if (!id_title(id)) sprintf(buf, "/VIDEO_TS/VIDEO_TS.BUP");
+      else sprintf(buf, "/VIDEO_TS/VTS_%02u_0.BUP", id_title(id));
+      break;
+    case VOB:
+      if (!id_title(id)) sprintf(buf, "/VIDEO_TS/VIDEO_TS.VOB");
+      else
+       sprintf(buf, "/VIDEO_TS/VTS_%02u_%u.VOB", id_title(id), id_part(id));
+      break;
+    default:
+      abort();
+  }
+}
+
+static char *copy_string(char *p, const char *q)
+{
+  while (*q) *p++ = *q++;
+  *p = 0; return (p);
+}
+
+static char *copy_hex(char *p, const unsigned char *q, size_t sz)
+{
+  while (sz) {
+    sprintf(p, "%02x", *q);
+    p += 2; q++; sz--;
+  }
+  return (p);
+}
+
+int dvd_id(char *p, dvd_reader_t *dvd, unsigned f, const char *file)
+{
+  char volid[33];
+  unsigned char volsetid[16], discid[16];
+  int rc;
+  size_t n;
+
+  rc = DVDUDFVolumeInfo(dvd,
+                       volid, sizeof(volid),
+                       volsetid, sizeof(volsetid));
+  if (!rc) {
+    p = copy_string(p, volid);
+    *p++ = '-';
+    for (n = sizeof(volsetid); n && !volsetid[n - 1]; n--);
+    p = copy_hex(p, volsetid, n);
+  } else if (f&DIF_MUSTVOLINF) {
+    if (file) moan("failed to read volume info for `%s'", file);
+    else moan("failed to read volume info");
+    return (-1);
+  } else
+    p = copy_string(p, "<error reading volume info>");
+
+  *p++ = ':';
+  rc = DVDDiscID(dvd, discid);
+  if (!rc)
+    p = copy_hex(p, discid, sizeof(discid));
+  else if (f&DIF_MUSTIFOHASH) {
+    if (file) moan("failed to determine disc id of `%s'", file);
+    else moan("failed to determine disc id");
+    return (-1);
+  } else
+    p = copy_string(p, "<error reading disc-id>");
+
+  return (0);
+}
diff --git a/lib.h b/lib.h
index 069cd37..5e8b865 100644 (file)
--- a/lib.h
+++ b/lib.h
 
 #define N(v) (sizeof(v)/sizeof((v)[0]))
 
+#define PRINTF_LIKE(fmt, dots) __attribute__((format(printf, fmt, dots)))
+#define NORETURN __attribute__((noreturn))
+
 #define SECTORSZ 2048
 #define SECTORS(n) (((n) + (SECTORSZ - 1))/SECTORSZ)
 typedef uint_least32_t secaddr;
 #define PRIuSEC PRIuLEAST32
 #define SECLIMIT 0x00400000
 
-#define PRINTF_LIKE(fmt, dots) __attribute__((format(printf, fmt, dots)))
-#define NORETURN __attribute__((noreturn))
-
 extern const char *prog;
 
 extern void set_prog(const char *p);
@@ -88,6 +88,19 @@ extern void check_write(FILE *fp, const char *what);
 extern void carefully_fclose(FILE *fp, const char *what);
 extern off_t device_size(int fd, const char *file, int *blksz_out);
 
+struct banner_progress_item {
+  struct progress_item _base;
+  const char *msg;
+};
+
+extern struct progress_state progress;
+
+extern void show_banner(const char *msg);
+extern void hide_banner(void);
+
+extern void open_dvd(const char *device, int mode,
+                    int *fd_out, dvd_reader_t **dvd_out);
+
 enum { RAW, IFO, VOB, BUP };
 typedef uint_least32_t ident;
 
@@ -105,17 +118,4 @@ extern void store_filename(char *buf, ident id);
 #define MAXIDSZ 99
 extern int dvd_id(char *p, dvd_reader_t *dvd, unsigned f, const char *file);
 
-struct banner_progress_item {
-  struct progress_item _base;
-  const char *msg;
-};
-
-extern struct progress_state progress;
-
-extern void show_banner(const char *msg);
-extern void hide_banner(void);
-
-extern void open_dvd(const char *device, int mode,
-                    int *fd_out, dvd_reader_t **dvd_out);
-
 #endif