Changeset 150

Show
Ignore:
Timestamp:
02/19/06 18:03:21 (3 years ago)
Author:
conrad
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fastphoto/trunk/src/Makefile.am

    r145 r150  
    66noinst_PROGRAMS = httpdate_test 
    77 
    8 noinst_HEADERS = alloc_snprintf.h cache.h cgi.h header.h httpdate.h photo.h resize.h 
     8noinst_HEADERS = alloc_snprintf.h cache.h cgi.h cmd.h header.h httpdate.h memory.h photo.h resize.h 
    99 
    10 fastphoto_SOURCES = main.c alloc_snprintf.c cache.c cgi.c header.c httpdate.c photo.c resize.c 
     10fastphoto_SOURCES = main.c alloc_snprintf.c cache.c cgi.c cmd.c header.c httpdate.c memory.c photo.c resize.c 
    1111fastphoto_LDADD = $(EPEG_LIBS) 
    1212 
  • fastphoto/trunk/src/cache.c

    r139 r150  
    6060 
    6161int 
    62 memory_init (fastphoto_t * params) 
    63 { 
    64     params->out.name = NULL; 
    65  
    66 #if 0 /* buggy Epeg, pre-20060207 */ 
    67     if ((file_check (params->infile, NULL, &params->infile_size)) == 1) { 
    68         params->data = malloc (params->infile_size); 
    69         params->data_size = params->infile_size; 
    70     } 
    71 #else 
    72     params->data = NULL; 
    73     params->data_size = 0; 
    74 #endif 
    75  
    76     return 0; 
    77 } 
    78  
    79 int 
    8062cache_init (fastphoto_t * params, char * path_info) 
    8163{ 
  • fastphoto/trunk/src/cache.h

    r135 r150  
    44int cache_init (fastphoto_t * params, char * path_info); 
    55 
    6 int memory_init (fastphoto_t * params); 
    7 int memory_send (fastphoto_t * params); 
    8  
    96#endif /* __CACHE_H__ */ 
  • fastphoto/trunk/src/cgi.c

    r149 r150  
    99#include "header.h" 
    1010#include "httpdate.h" 
     11#include "memory.h" 
    1112#include "photo.h" 
    1213#include "resize.h" 
     
    8485  return 1; 
    8586} 
    86 size_t 
    87 send_memory (fastphoto_t * params) 
    88 { 
    89     size_t n = fwrite (params->data, 1, params->data_size, stdout); 
    90     fflush (stdout); 
    91     return n; 
    92 } 
    9387 
    9488static int 
     
    116110    header_end(); 
    117111 
    118     send_memory (params); 
     112    memory_send (params); 
    119113  } 
    120114 
  • fastphoto/trunk/src/cgi.h

    r149 r150  
    88int cgi_main (fastphoto_t * params); 
    99 
    10 size_t send_memory (fastphoto_t * params); 
    11  
    1210#endif /* __CGI_H__ */ 
  • fastphoto/trunk/src/main.c

    r149 r150  
    55#include <string.h> 
    66 
    7 #include <getopt.h> 
    8  
    97#include "fastphoto.h" 
    10 #include "cache.h" 
    118#include "cgi.h" 
    12 #include "header.h" 
    13 #include "resize.h" 
    14  
    15 static void 
    16 version (void) 
    17 
    18     printf ("FastPhoto " VERSION "\n"); 
    19 
    20  
    21 static void 
    22 usage (void) 
    23 
    24     printf ("Usage: fastphoto [options] infile [outfile]\n"); 
    25     printf ("Rescale a JPEG image\n"); 
    26     printf ("\nScaling options\n"); 
    27     printf ("  -x, --width          Set the width of the output image\n"); 
    28     printf ("  -y, --height         Set the height of the output image\n"); 
    29     printf ("  -s, --scale          Set a percentage to scale the image by\n"); 
    30     printf ("\nOutput options\n"); 
    31     printf ("  -g, --gray           Output grayscale\n"); 
    32     printf ("  -q, --quality        Set the output quality 0-100\n"); 
    33     printf ("\nInformational options\n"); 
    34     printf ("  -i, --info           Print information about image\n"); 
    35     printf ("\nMiscellaneous options\n"); 
    36     printf ("  -h, --help           Display this help and exit\n"); 
    37     printf ("  -v, --version        Output version information and exit\n"); 
    38     printf ("\n"); 
    39 
    40  
    41 static int 
    42 cmd_main (fastphoto_t * params, int argc, char * argv[]) 
    43 
    44   int err = 0; 
    45   int show_help = 0; 
    46   int show_version = 0; 
    47   int i; 
    48  
    49   while (1) { 
    50     char * optstring = "hvx:y:s:gq:i"; 
    51  
    52 #ifdef HAVE_GETOPT_LONG 
    53     static struct option long_options[] = { 
    54       {"help", no_argument, 0, 'h'}, 
    55       {"version", no_argument, 0, 'v'}, 
    56       {"width", required_argument, 0, 'x'}, 
    57       {"height", required_argument, 0, 'y'}, 
    58       {"scale", required_argument, 0, 's'}, 
    59       {"gray", no_argument, 0, 'g'}, 
    60       {"quality", required_argument, 0, 'q'}, 
    61       {"info", no_argument, 0, 'i'}, 
    62       {0,0,0,0} 
    63     }; 
    64  
    65     i = getopt_long (argc, argv, optstring, long_options, NULL); 
    66 #else 
    67     i = getopt (argc, argv, optstring); 
    68 #endif 
    69  
    70     if (i == -1) break; 
    71     if (i == ':') { 
    72       usage (); 
    73       return 1; 
    74     } 
    75  
    76     switch (i) { 
    77     case 'h': /* help */ 
    78       show_help = 1; 
    79       break; 
    80     case 'v': /* version */ 
    81       show_version = 1; 
    82       break; 
    83     case 'x': /* width */ 
    84       params->x = atoi (optarg); 
    85       break; 
    86     case 'y': /* height */ 
    87       params->y = atoi (optarg); 
    88       break; 
    89     case 's': /* scale */ 
    90       params->scale = atoi (optarg); 
    91       break; 
    92     case 'g': /* gray */ 
    93       params->gray = 1; 
    94       break; 
    95     case 'q': /* quality */ 
    96       params->quality = atoi (optarg); 
    97       break; 
    98     case 'i': /* info */ 
    99       params->info = 1; 
    100       break; 
    101     default: 
    102       break; 
    103     } 
    104  
    105   } 
    106  
    107   if (show_version) { 
    108     version (); 
    109   } 
    110  
    111   if (show_help) { 
    112     usage (); 
    113   } 
    114  
    115   if (show_version || show_help) { 
    116     return 0; 
    117   } 
    118  
    119   if (optind >= argc) { 
    120     usage (); 
    121     return 1; 
    122   } 
    123  
    124   params->in.name = argv[optind++]; 
    125  
    126   if (optind >= argc) { 
    127     memory_init (params); 
    128   } else { 
    129     params->out.name = argv[optind++]; 
    130   } 
    131  
    132   err = resize (params); 
    133      
    134   if (!err) 
    135     send_memory (params); 
    136      
    137   return err; 
    138 
    139  
     9#include "cmd.h" 
     10  
    14011int 
    14112main (int argc, char * argv[])