diff --git a/src/Makefile.am b/src/Makefile.am index aff3db8..45cba3c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,12 +4,13 @@ AM_CPPFLAGS = \ -DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \ -DPACKAGE_SRC_DIR=\""$(srcdir)"\" \ -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \ - -DCNFPATH=\""$(prefix)/etc"\" + -DCNFPATH=\""$(prefix)/etc"\" \ + -I $(srcdir) AM_CFLAGS = -Wall -g bin_PROGRAMS = exifdate -exifdate_SOURCES = exifdate.c +exifdate_SOURCES = dtex.c exifdate.c exifdate_LDADD = $(LIBS) $(LIBEXIF_LIBS) diff --git a/src/dtex.c b/src/dtex.c new file mode 100644 index 0000000..b7226c8 --- /dev/null +++ b/src/dtex.c @@ -0,0 +1,81 @@ +/* + * EXIF date tool + * + * (c) Alexander Vdolainen 2023 + * + * this 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 2 of the License, or + * (at your option) any later version. + * + * this 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 this program. If not, see ."; + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +time_t exifdt_tm(const char *dtbuf) +{ + struct tm tddt; + char buf[5], *b = (char *)dtbuf; + + if(!dtbuf) return (time_t) -1; + if(strlen(dtbuf) < 18) return (time_t) -1; + + memset(&tddt, 0, sizeof(struct tm)); + /* year */ + memset(buf, 0, 5); + strncpy(buf, dtbuf, 4); + tddt.tm_year = atoi(buf) - 1900; + /* month */ + memset(buf, 0, 5); + b = strchr(b, ':'); + if(!b) return (time_t) -1; + else b++; + strncpy(buf, b, 2); + tddt.tm_mon = atoi(buf) - 1; + /* day */ + memset(buf, 0, 5); + b = strchr(b, ':'); + if(!b) return (time_t) -1; + else b++; + strncpy(buf, b, 2); + tddt.tm_mday = atoi(buf); + /* hour */ + memset(buf, 0, 5); + b = strchr(b, ' '); + if(!b) return (time_t) -1; + else b++; + strncpy(buf, b, 2); + tddt.tm_hour = atoi(buf); + /* minute */ + memset(buf, 0, 5); + b = strchr(b, ':'); + if(!b) return (time_t) -1; + else b++; + strncpy(buf, b, 2); + tddt.tm_min = atoi(buf); + /* second */ + memset(buf, 0, 5); + b = strchr(b, ':'); + if(!b) return (time_t) -1; + else b++; + strncpy(buf, b, 2); + tddt.tm_sec = atoi(buf); + + return mktime(&tddt); +} diff --git a/src/exifdate.c b/src/exifdate.c index cdf5518..b5f0990 100644 --- a/src/exifdate.c +++ b/src/exifdate.c @@ -30,7 +30,7 @@ #include -#include "../config.h" +#include #ifndef TOOL_FULLNAME #define TOOL_FULLNAME "Jpeg EXIF data date tool" @@ -61,57 +61,7 @@ static void display_help(FILE *o, const char *exec_name) return; } -static time_t exifdt_tm(const char *dtbuf) -{ - struct tm tddt; - char buf[5], *b = (char *)dtbuf; - - if(!dtbuf) return (time_t) -1; - if(strlen(dtbuf) < 18) return (time_t) -1; - - memset(&tddt, 0, sizeof(struct tm)); - /* year */ - memset(buf, 0, 5); - strncpy(buf, dtbuf, 4); - tddt.tm_year = atoi(buf) - 1900; - /* month */ - memset(buf, 0, 5); - b = strchr(b, ':'); - if(!b) return (time_t) -1; - else b++; - strncpy(buf, b, 2); - tddt.tm_mon = atoi(buf) - 1; - /* day */ - memset(buf, 0, 5); - b = strchr(b, ':'); - if(!b) return (time_t) -1; - else b++; - strncpy(buf, b, 2); - tddt.tm_mday = atoi(buf); - /* hour */ - memset(buf, 0, 5); - b = strchr(b, ' '); - if(!b) return (time_t) -1; - else b++; - strncpy(buf, b, 2); - tddt.tm_hour = atoi(buf); - /* minute */ - memset(buf, 0, 5); - b = strchr(b, ':'); - if(!b) return (time_t) -1; - else b++; - strncpy(buf, b, 2); - tddt.tm_min = atoi(buf); - /* second */ - memset(buf, 0, 5); - b = strchr(b, ':'); - if(!b) return (time_t) -1; - else b++; - strncpy(buf, b, 2); - tddt.tm_sec = atoi(buf); - - return mktime(&tddt); -} +extern time_t exifdt_tm(const char *); int main(int argc, char **argv) {