Permalink
Browse files

cleanup: put memory funcs into memory.c, cmdline handling into cmd.c

git-svn-id: http://svn.kfish.org/fastphoto/trunk@150 9c49b5d1-7df3-0310-bce2-b7278e68f44c
  • Loading branch information...
1 parent 13ae7d9 commit 01ad400c8dacfa2633af9a2e28ca200f579d0505 conrad committed Feb 19, 2006
Showing with 188 additions and 164 deletions.
  1. +2 −2 src/Makefile.am
  2. +0 −18 src/cache.c
  3. +0 −3 src/cache.h
  4. +2 −8 src/cgi.c
  5. +0 −2 src/cgi.h
  6. +137 −0 src/cmd.c
  7. +6 −0 src/cmd.h
  8. +2 −131 src/main.c
  9. +30 −0 src/memory.c
  10. +9 −0 src/memory.h
View
@@ -5,9 +5,9 @@ AM_CFLAGS = $(EPEG_CFLAGS)
bin_PROGRAMS = fastphoto
noinst_PROGRAMS = httpdate_test
-noinst_HEADERS = alloc_snprintf.h cache.h cgi.h header.h httpdate.h photo.h resize.h
+noinst_HEADERS = alloc_snprintf.h cache.h cgi.h cmd.h header.h httpdate.h memory.h photo.h resize.h
-fastphoto_SOURCES = main.c alloc_snprintf.c cache.c cgi.c header.c httpdate.c photo.c resize.c
+fastphoto_SOURCES = main.c alloc_snprintf.c cache.c cgi.c cmd.c header.c httpdate.c memory.c photo.c resize.c
fastphoto_LDADD = $(EPEG_LIBS)
httpdate_test_SOURCES = httpdate.c httpdate_test.c
View
@@ -59,24 +59,6 @@ cache_check (fastphoto_t * params)
}
int
-memory_init (fastphoto_t * params)
-{
- params->out.name = NULL;
-
-#if 0 /* buggy Epeg, pre-20060207 */
- if ((file_check (params->infile, NULL, &params->infile_size)) == 1) {
- params->data = malloc (params->infile_size);
- params->data_size = params->infile_size;
- }
-#else
- params->data = NULL;
- params->data_size = 0;
-#endif
-
- return 0;
-}
-
-int
cache_init (fastphoto_t * params, char * path_info)
{
char * cachedir = FASTPHOTO_DEFAULT_CACHEDIR;
View
@@ -3,7 +3,4 @@
int cache_init (fastphoto_t * params, char * path_info);
-int memory_init (fastphoto_t * params);
-int memory_send (fastphoto_t * params);
-
#endif /* __CACHE_H__ */
View
@@ -8,6 +8,7 @@
#include "cache.h"
#include "header.h"
#include "httpdate.h"
+#include "memory.h"
#include "photo.h"
#include "resize.h"
@@ -83,13 +84,6 @@ cgi_test (void)
return 1;
}
-size_t
-send_memory (fastphoto_t * params)
-{
- size_t n = fwrite (params->data, 1, params->data_size, stdout);
- fflush (stdout);
- return n;
-}
static int
cgi_send_photo (photo_t * photo)
@@ -115,7 +109,7 @@ cgi_send (fastphoto_t * params)
header_content_length ((off_t)params->data_size);
header_end();
- send_memory (params);
+ memory_send (params);
}
return 0;
View
@@ -7,6 +7,4 @@ int cgi_test (void);
int cgi_main (fastphoto_t * params);
-size_t send_memory (fastphoto_t * params);
-
#endif /* __CGI_H__ */
View
137 src/cmd.c
@@ -0,0 +1,137 @@
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <getopt.h>
+
+#include "fastphoto.h"
+
+#include "memory.h"
+#include "resize.h"
+
+static void
+version (void)
+{
+ printf ("FastPhoto " VERSION "\n");
+}
+
+static void
+usage (void)
+{
+ printf ("Usage: fastphoto [options] infile [outfile]\n");
+ printf ("Rescale a JPEG image\n");
+ printf ("\nScaling options\n");
+ printf (" -x, --width Set the width of the output image\n");
+ printf (" -y, --height Set the height of the output image\n");
+ printf (" -s, --scale Set a percentage to scale the image by\n");
+ printf ("\nOutput options\n");
+ printf (" -g, --gray Output grayscale\n");
+ printf (" -q, --quality Set the output quality 0-100\n");
+ printf ("\nInformational options\n");
+ printf (" -i, --info Print information about image\n");
+ printf ("\nMiscellaneous options\n");
+ printf (" -h, --help Display this help and exit\n");
+ printf (" -v, --version Output version information and exit\n");
+ printf ("\n");
+}
+
+int
+cmd_main (fastphoto_t * params, int argc, char * argv[])
+{
+ int err = 0;
+ int show_help = 0;
+ int show_version = 0;
+ int i;
+
+ while (1) {
+ char * optstring = "hvx:y:s:gq:i";
+
+#ifdef HAVE_GETOPT_LONG
+ static struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"version", no_argument, 0, 'v'},
+ {"width", required_argument, 0, 'x'},
+ {"height", required_argument, 0, 'y'},
+ {"scale", required_argument, 0, 's'},
+ {"gray", no_argument, 0, 'g'},
+ {"quality", required_argument, 0, 'q'},
+ {"info", no_argument, 0, 'i'},
+ {0,0,0,0}
+ };
+
+ i = getopt_long (argc, argv, optstring, long_options, NULL);
+#else
+ i = getopt (argc, argv, optstring);
+#endif
+
+ if (i == -1) break;
+ if (i == ':') {
+ usage ();
+ return 1;
+ }
+
+ switch (i) {
+ case 'h': /* help */
+ show_help = 1;
+ break;
+ case 'v': /* version */
+ show_version = 1;
+ break;
+ case 'x': /* width */
+ params->x = atoi (optarg);
+ break;
+ case 'y': /* height */
+ params->y = atoi (optarg);
+ break;
+ case 's': /* scale */
+ params->scale = atoi (optarg);
+ break;
+ case 'g': /* gray */
+ params->gray = 1;
+ break;
+ case 'q': /* quality */
+ params->quality = atoi (optarg);
+ break;
+ case 'i': /* info */
+ params->info = 1;
+ break;
+ default:
+ break;
+ }
+
+ }
+
+ if (show_version) {
+ version ();
+ }
+
+ if (show_help) {
+ usage ();
+ }
+
+ if (show_version || show_help) {
+ return 0;
+ }
+
+ if (optind >= argc) {
+ usage ();
+ return 1;
+ }
+
+ params->in.name = argv[optind++];
+
+ if (optind >= argc) {
+ memory_init (params);
+ } else {
+ params->out.name = argv[optind++];
+ }
+
+ err = resize (params);
+
+ if (!err)
+ memory_send (params);
+
+ return err;
+}
View
@@ -0,0 +1,6 @@
+#ifndef __CMD_H__
+#define __CMD_H__
+
+int cmd_main (fastphoto_t * params, int argc, char * argv[]);
+
+#endif /* __CMD_H__ */
View
@@ -4,139 +4,10 @@
#include <stdlib.h>
#include <string.h>
-#include <getopt.h>
-
#include "fastphoto.h"
-#include "cache.h"
#include "cgi.h"
-#include "header.h"
-#include "resize.h"
-
-static void
-version (void)
-{
- printf ("FastPhoto " VERSION "\n");
-}
-
-static void
-usage (void)
-{
- printf ("Usage: fastphoto [options] infile [outfile]\n");
- printf ("Rescale a JPEG image\n");
- printf ("\nScaling options\n");
- printf (" -x, --width Set the width of the output image\n");
- printf (" -y, --height Set the height of the output image\n");
- printf (" -s, --scale Set a percentage to scale the image by\n");
- printf ("\nOutput options\n");
- printf (" -g, --gray Output grayscale\n");
- printf (" -q, --quality Set the output quality 0-100\n");
- printf ("\nInformational options\n");
- printf (" -i, --info Print information about image\n");
- printf ("\nMiscellaneous options\n");
- printf (" -h, --help Display this help and exit\n");
- printf (" -v, --version Output version information and exit\n");
- printf ("\n");
-}
-
-static int
-cmd_main (fastphoto_t * params, int argc, char * argv[])
-{
- int err = 0;
- int show_help = 0;
- int show_version = 0;
- int i;
-
- while (1) {
- char * optstring = "hvx:y:s:gq:i";
-
-#ifdef HAVE_GETOPT_LONG
- static struct option long_options[] = {
- {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'v'},
- {"width", required_argument, 0, 'x'},
- {"height", required_argument, 0, 'y'},
- {"scale", required_argument, 0, 's'},
- {"gray", no_argument, 0, 'g'},
- {"quality", required_argument, 0, 'q'},
- {"info", no_argument, 0, 'i'},
- {0,0,0,0}
- };
-
- i = getopt_long (argc, argv, optstring, long_options, NULL);
-#else
- i = getopt (argc, argv, optstring);
-#endif
-
- if (i == -1) break;
- if (i == ':') {
- usage ();
- return 1;
- }
-
- switch (i) {
- case 'h': /* help */
- show_help = 1;
- break;
- case 'v': /* version */
- show_version = 1;
- break;
- case 'x': /* width */
- params->x = atoi (optarg);
- break;
- case 'y': /* height */
- params->y = atoi (optarg);
- break;
- case 's': /* scale */
- params->scale = atoi (optarg);
- break;
- case 'g': /* gray */
- params->gray = 1;
- break;
- case 'q': /* quality */
- params->quality = atoi (optarg);
- break;
- case 'i': /* info */
- params->info = 1;
- break;
- default:
- break;
- }
-
- }
-
- if (show_version) {
- version ();
- }
-
- if (show_help) {
- usage ();
- }
-
- if (show_version || show_help) {
- return 0;
- }
-
- if (optind >= argc) {
- usage ();
- return 1;
- }
-
- params->in.name = argv[optind++];
-
- if (optind >= argc) {
- memory_init (params);
- } else {
- params->out.name = argv[optind++];
- }
-
- err = resize (params);
-
- if (!err)
- send_memory (params);
-
- return err;
-}
-
+#include "cmd.h"
+
int
main (int argc, char * argv[])
{
Oops, something went wrong.

0 comments on commit 01ad400

Please sign in to comment.