A big mess of changes all at once.
[dvdrip] / lib.h
diff --git a/lib.h b/lib.h
new file mode 100644 (file)
index 0000000..1f08848
--- /dev/null
+++ b/lib.h
@@ -0,0 +1,100 @@
+#ifndef LIB_H
+#define LIB_H
+
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <float.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <locale.h>
+#include <math.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/select.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+#include <getopt.h>
+
+#include <linux/fs.h>
+
+#include <dvdread/dvd_reader.h>
+#include <dvdread/dvd_udf.h>
+#include <dvdread/ifo_read.h>
+#include <dvdread/ifo_types.h>
+
+#include "multiprogress.h"
+
+#define CTYPE_HACK(fn, ch) fn((unsigned char)(ch))
+#define ISDIGIT(ch) CTYPE_HACK(isdigit, ch)
+#define ISSPACE(ch) CTYPE_HACK(isspace, ch)
+
+#define STRCMP(a, op, b) (strcmp((a), (b)) op 0)
+#define STRNCMP(a, op, b, n) (strncmp((a), (b), (n)) op 0)
+
+#ifdef DEBUG
+#  define D(x) x
+#else
+#  define D(x)
+#endif
+
+#define N(v) (sizeof(v)/sizeof((v)[0]))
+
+#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);
+extern void vmoan(const char *fmt, va_list ap);
+extern PRINTF_LIKE(1, 2) void moan(const char *fmt, ...);
+extern PRINTF_LIKE(1, 2) NORETURN void bail(const char *fmt, ...);
+extern PRINTF_LIKE(2, 3) NORETURN
+  void bail_syserr(int err, const char *fmt, ...);
+
+extern void sit(double t);
+
+enum { RAW, IFO, VOB, BUP };
+typedef uint_least32_t ident;
+
+static inline ident mkident(unsigned kind, unsigned title, unsigned part)
+  { return (((ident)kind << 0) | ((ident)title << 8) | ((ident)part << 16)); }
+static inline unsigned id_kind(ident id) { return ((id >> 0)&0x0ff); }
+static inline unsigned id_title(ident id) { return ((id >> 8)&0x0ff); }
+static inline unsigned id_part(ident id) { return ((id >> 16)&0x0ff); }
+
+#define MAXFNSZ (1 + 8 + 1 + 12 + 1)
+extern void store_filename(char *buf, ident id);
+
+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 *fd_out, dvd_reader_t **dvd_out);
+
+#endif