|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "ns.h" |
|
|
|
|
|
#include "exif.h" |
|
|
|
|
|
#define BUFSIZE 1024 |
|
|
|
|
|
static void |
|
|
rec_put(Ns_Set *set, exif_record_t *rec) |
|
|
{ |
|
|
char buf[BUFSIZE]; |
|
|
char *str = buf; |
|
|
|
|
|
switch (rec->rec_type) { |
|
|
case 's': |
|
|
str = rec->rec_data.s; |
|
|
break; |
|
|
case 'f': |
|
|
snprintf(buf, BUFSIZE, "%f", rec->rec_data.f); |
|
|
break; |
|
|
case 'g': |
|
|
snprintf(buf, BUFSIZE, "%g", rec->rec_data.f); |
|
|
break; |
|
|
case 'l': |
|
|
snprintf(buf, BUFSIZE, "%ld", rec->rec_data.l); |
|
|
break; |
|
|
case 'r': |
|
|
snprintf(buf, BUFSIZE, "%d/%d", rec->rec_data.r.num, |
|
|
rec->rec_data.r.denom); |
|
|
break; |
|
|
default: |
|
|
snprintf(buf, BUFSIZE, "<Unknown record type '%c'>", rec->rec_type); |
|
|
break; |
|
|
} |
|
|
Ns_SetPut(set, rec->rec_name, str); |
|
|
} |
|
|
|
|
|
static int |
|
|
Tcl_ReadExifDataCmd ( |
|
|
ClientData clientData, |
|
|
Tcl_Interp *interp, |
|
|
int argc, |
|
|
char **argv) |
|
|
{ |
|
|
exif_data_t *d; |
|
|
int i; |
|
|
Ns_Set *rset; |
|
|
|
|
|
d = exif_parse_file(argv[1]); |
|
|
if (d == NULL) { |
|
|
Tcl_AppendResult(interp, "Could not process file '", argv[1], "'", NULL); |
|
|
return TCL_ERROR; |
|
|
} |
|
|
rset = Ns_SetCreate("exif"); |
|
|
|
|
|
for (i=0; i<d->n_recs; i++) { |
|
|
rec_put(rset, &d->recs[i]); |
|
|
} |
|
|
|
|
|
Ns_TclEnterSet(interp, rset, NS_TCL_SET_TEMPORARY | NS_TCL_SET_DYNAMIC); |
|
|
exif_free_data(d); |
|
|
return TCL_OK; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
Tcl_InitExif (interp) |
|
|
Tcl_Interp *interp; |
|
|
{ |
|
|
Tcl_CreateCommand (interp, "ns_exif", Tcl_ReadExifDataCmd, |
|
|
NULL, NULL); |
|
|
} |
|
|
|
|
|
static int |
|
|
nsexif_interp_init (Tcl_Interp *interp, void *dummy) |
|
|
{ |
|
|
Tcl_InitExif(interp); |
|
|
return TCL_OK; |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
Ns_ModuleInit(char *hServer, char *hModule) |
|
|
{ |
|
|
char *configPath; |
|
|
|
|
|
Ns_Log( Notice, "%s module starting", hModule); |
|
|
|
|
|
exif_init((void *(*)(int))Ns_Malloc, |
|
|
(void (*)(void *))Ns_Free, |
|
|
(void *(*)(void *, int))Ns_Realloc); |
|
|
|
|
|
configPath = Ns_ConfigGetPath(hServer, hModule, NULL); |
|
|
|
|
|
|
|
|
|
|
|
Ns_TclInitInterps (hServer, nsexif_interp_init, NULL); |
|
|
return NS_OK; |
|
|
} |
|
|
|
|
|
int Ns_ModuleVersion = 1; |
|
|
|