From d4c89d8688a30275e6273c30b5368a2f9248a2b9 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Sat, 18 May 2013 10:00:37 +0000 Subject: html: render tables for inclusion in support.php git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@14419 67ed7778-7388-44ab-90cf-0a291f65f57c --- packaging/generic/print-camera-list.c | 188 ++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) (limited to 'packaging') diff --git a/packaging/generic/print-camera-list.c b/packaging/generic/print-camera-list.c index 218aa3aac..96cde9c29 100644 --- a/packaging/generic/print-camera-list.c +++ b/packaging/generic/print-camera-list.c @@ -1143,6 +1143,184 @@ fdi_device_end_func (const func_params_t *params, void *data) return 0; } +/* HTML output */ +struct html_comment { + char *name; + char *comment; +}; +struct html_data { + int nrofcomments; + struct html_comment *comments; +}; + +static int +html_begin_func (const func_params_t *params, void **data) { + FILE *f; + char buf[512]; + int n; + struct html_data *hd; + + printf("\n", + "libgphoto2 " ARGV0); + print_version_comment(stdout, " | ", "\n", "\n"); + printf("\n"); + printf("\n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf("\n"); + + hd = malloc(sizeof(*hd)); + hd->nrofcomments = 0; + hd->comments = NULL; + + f = fopen("comments.txt","r"); + if (!f) + return 0; + while (fgets(buf,sizeof(buf),f)) { + char *s = strchr(buf,';'); + if (!s) + continue; + *s = '\0'; + if (hd->nrofcomments) { + hd->comments = realloc(hd->comments, (hd->nrofcomments+1)*sizeof(hd->comments[0])); + } else { + hd->comments = malloc(sizeof(hd->comments[0])); + } + hd->comments[hd->nrofcomments].name = strdup(buf); + hd->comments[hd->nrofcomments].comment = strdup(s+1); + hd->nrofcomments++; + } + fclose (f); + return 0; +} + +static char* +escape_html(const char *str) { + char *s, *newstr, *ns; + int inc = 0; + + s = str; + do { + s = strchr(s,'&'); + if (s) { + inc+=strlen("&"); + s++; + } + } while (s); + /* FIXME: if we ever get a camera with <> or so, add escape code here */ + newstr = malloc(strlen(str)+1+inc); + s = str; ns = newstr; + do { + char *x; + x = strchr(s,'&'); + if (x) { + memcpy (ns, s, x-s); + ns += x-s; + memcpy (ns, "&", strlen("&")); + ns += strlen("&"); + s = x+1; + } else { + strcpy (ns, s); + break; + } + } while (1); + return newstr; +} + +static int +html_camera_func ( + const func_params_t *params, + const int i, + const int total, + const CameraAbilities *a, + void *data +) { + char *m; + CameraOperation op = a->operations; + + if (a->device_type != GP_DEVICE_STILL_CAMERA) + return 0; + + printf ("\n"); + m = escape_html (a->model); + printf (" ", m); free (m); + printf (" "); + printf(" "); + printf("\n"); + return 0; +} + +static int html_middle_func ( + const func_params_t *params, + void **data +) { + printf("
Camera ModelAbilitiesComments
%s"); + if (!op) printf (" "); + if (op & GP_OPERATION_CAPTURE_IMAGE) { + printf ("Image Capture"); + op &= ~GP_OPERATION_CAPTURE_IMAGE; + if (op) printf (", "); + } + if (op & GP_OPERATION_CAPTURE_PREVIEW) { + printf ("Liveview"); + op &= ~GP_OPERATION_CAPTURE_PREVIEW; + if (op) printf (", "); + } + if (op & GP_OPERATION_CONFIG) { + printf ("Configuration"); + op &= ~GP_OPERATION_CONFIG; + if (op) printf (", "); + } + if (op) { + printf ("Other Ops %x", op); + } + printf(" "); + switch (a->status) { + case GP_DRIVER_STATUS_PRODUCTION: break; + case GP_DRIVER_STATUS_TESTING: printf("Testing (Beta)"); break; + case GP_DRIVER_STATUS_EXPERIMENTAL: printf("Experimental"); break; + case GP_DRIVER_STATUS_DEPRECATED: printf("Deprecated"); break; + } + /* read comments */ + printf("  "); + printf("

\n"); + printf("Media Players that are supported by both libmtp and libgphoto2:

\n"); + printf("\n"); + printf("\n"); + printf(" \n"); + printf("\n"); + return 0; +} + +static int +html_camera2_func ( + const func_params_t *params, + const int i, + const int total, + const CameraAbilities *a, + void *data +) { + char *m; + + if (a->device_type != GP_DEVICE_AUDIO_PLAYER) + return 0; + + m = escape_html (a->model); + printf ("\n"); + printf (" ", m); free (m); + printf("\n"); + return 0; +} + + +static int html_end_func ( + const func_params_t *params, + void *data +) { + printf("
Media Player Model
%s
\n"); + return 0; +} /* time zero for debug log time stamps */ struct timeval glob_tv_zero = { 0, 0 }; @@ -1301,6 +1479,16 @@ static const output_format_t formats[] = { udev_camera_func2, udev_end_func }, + {"html", + "HTML table file for gphoto.org website", + "Paste it into /proj/libgphoto2/support.php", + NULL, + html_begin_func, + html_camera_func, + html_middle_func, + html_camera2_func, + html_end_func + }, {"idlist", "list of IDs and names", "grep for an ID to find the device name", -- cgit v1.2.1