+/* -*-c-*-
+ *
+ * Common functions for the DVDrip C utilities.
+ *
+ * (c) 2022 Mark Wooding
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of the DVD ripping toolset.
+ *
+ * DVDrip 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.
+ *
+ * DVDrip 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 DVDrip. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
#include "lib.h"
+/*----- Diagnostics -------------------------------------------------------*/
+
const char *prog = "<unset>";
void set_prog(const char *p)
exit(2);
}
+/*----- Parsing utilities -------------------------------------------------*/
+
double parse_float(const char **p_inout, unsigned f,
double min, double max, const char *what)
{
return (x);
}
+/*----- Resizing buffers and arrays ---------------------------------------*/
+
+void buf__grow(struct buf *b)
+{
+ b->sz = b->sz ? 2*b->sz : 32;
+ b->p = realloc(b->p, b->sz);
+ if (!b->p) bail("out of memory allocating %zu bytes", b->sz);
+}
+
+void *vec__grow(void *p, size_t esz, size_t *sz_inout)
+{
+ size_t sz = *sz_inout, want;
+
+ sz = sz ? 2*sz : 32;
+ want = sz*esz;
+ p = realloc(p, want);
+ if (!p) bail("out of memory allocating %zu bytes", want);
+ *sz_inout = sz; return (p);
+}
+
+/*----- System utilities --------------------------------------------------*/
+
void sit(double t)
{
struct timeval tv;
}
}
+double tvdiff(const struct timeval *tv_lo, const struct timeval *tv_hi)
+{
+ return ((tv_hi->tv_sec - tv_lo->tv_sec) +
+ (tv_hi->tv_usec - tv_lo->tv_usec)/1.0e6);
+}
+
+int read_line(FILE *fp, struct buf *b)
+{
+ int ch;
+
+ ch = getc(fp);
+ if (ch == EOF)
+ return (-1);
+ else if (ch != '\n')
+ do { buf_putc(b, ch); ch = getc(fp); } while (ch != EOF && ch != '\n');
+ buf_putz(b);
+ return (0);
+}
+
void carefully_write(int fd, const void *buf, size_t sz)
{
const unsigned char *p = buf;
return ((off_t)volsz);
}
+/*----- Progress utilities ------------------------------------------------*/
+
struct progress_state progress = PROGRESS_STATE_INIT;
static struct banner_progress_item banner_progress;
progress_update(&progress);
}
+/*----- DVD utilities -----------------------------------------------------*/
+
#ifdef notdef
static void logfn(void *p, dvd_logger_level_t lev,
const char *fmt, va_list ap)
return (0);
}
+
+/*----- That's all, folks -------------------------------------------------*/