src/util/main.c
changeset 56 d5e3089906da
parent 55 a3542e78ecd8
child 63 2aab5d906dc8
equal deleted inserted replaced
55:a3542e78ecd8 56:d5e3089906da
    13     { "help",           false,  NULL,   'h' },
    13     { "help",           false,  NULL,   'h' },
    14     { "quiet",          false,  NULL,   'q' },
    14     { "quiet",          false,  NULL,   'q' },
    15     { "verbose",        false,  NULL,   'v' },
    15     { "verbose",        false,  NULL,   'v' },
    16     { "debug",          false,  NULL,   'D' },
    16     { "debug",          false,  NULL,   'D' },
    17     { "force-update",   false,  NULL,   'U' },
    17     { "force-update",   false,  NULL,   'U' },
       
    18     { "no-update",      false,  NULL,   'N' },
    18     { "background",     true,   NULL,   'B' },
    19     { "background",     true,   NULL,   'B' },
    19     { "width",          true,   NULL,   'W' },
    20     { "width",          true,   NULL,   'W' },
    20     { "height",         true,   NULL,   'H' },
    21     { "height",         true,   NULL,   'H' },
    21     { "x",              true,   NULL,   'x' },
    22     { "x",              true,   NULL,   'x' },
    22     { "y",              true,   NULL,   'y' },
    23     { "y",              true,   NULL,   'y' },
    37         "\t-h, --help           show this help and exit\n"
    38         "\t-h, --help           show this help and exit\n"
    38         "\t-q, --quiet          supress informational output\n"
    39         "\t-q, --quiet          supress informational output\n"
    39         "\t-v, --verbose        display more informational output\n"
    40         "\t-v, --verbose        display more informational output\n"
    40         "\t-D, --debug          equivalent to -v\n"
    41         "\t-D, --debug          equivalent to -v\n"
    41         "\t-U, --force-update   unconditionally update image caches\n"
    42         "\t-U, --force-update   unconditionally update image caches\n"
       
    43         "\t-N, --no-update      do not update the image cache\n"
    42         "\t-B, --background     set background pattern for cache update\n"
    44         "\t-B, --background     set background pattern for cache update\n"
    43         "\t-W, --width          set tile width\n"
    45         "\t-W, --width          set tile width\n"
    44         "\t-H, --height         set tile height\n"
    46         "\t-H, --height         set tile height\n"
    45         "\t-x, --x              set tile x offset\n"
    47         "\t-x, --x              set tile x offset\n"
    46         "\t-y, --y              set tile z offset\n"
    48         "\t-y, --y              set tile z offset\n"
    50 }
    52 }
    51 
    53 
    52 int main (int argc, char **argv)
    54 int main (int argc, char **argv)
    53 {
    55 {
    54     int opt;
    56     int opt;
    55     bool force_update = false;
    57     bool force_update = false, no_update = false;
    56     struct pt_tile_info ti = {0, 0, 0, 0, 0};
    58     struct pt_tile_info ti = {0, 0, 0, 0, 0};
    57     struct pt_image_params update_params = { };
    59     struct pt_image_params update_params = { };
    58     int threads = 2;
    60     int threads = 2;
    59     int tmp, err;
    61     int tmp, err;
    60     
    62     
    61     // parse arguments
    63     // parse arguments
    62     while ((opt = getopt_long(argc, argv, "hqvDUB:W:H:x:y:z:j:", options, NULL)) != -1) {
    64     while ((opt = getopt_long(argc, argv, "hqvDUNB:W:H:x:y:z:j:", options, NULL)) != -1) {
    63         switch (opt) {
    65         switch (opt) {
    64             case 'h':
    66             case 'h':
    65                 // display help
    67                 // display help
    66                 help(argv[0]);
    68                 help(argv[0]);
    67                 
    69                 
    83             case 'U':
    85             case 'U':
    84                 // force update of image caches
    86                 // force update of image caches
    85                 force_update = true;
    87                 force_update = true;
    86                 
    88                 
    87                 break;
    89                 break;
       
    90             
       
    91             case 'N':
       
    92                 // supress update of image caches
       
    93                 no_update = true;
       
    94 
       
    95                 break;
    88 
    96 
    89             case 'B':
    97             case 'B':
    90                 // background pattern
    98                 // background pattern
    91                 {
    99                 {
    92                     unsigned int b1, b2, b3, b4;
   100                     unsigned int b1 = 0, b2 = 0, b3 = 0, b4 = 0;
    93                     
   101                     
    94                     // parse 0xXXXXXXXX
   102                     // parse 0xXXXXXXXX
    95                     if (sscanf(optarg, "0x%02x%02x%02x%02x", &b1, &b2, &b3, &b4) != 4)
   103                     if (sscanf(optarg, "0x%02x%02x%02x%02x", &b1, &b2, &b3, &b4) < 1)
    96                         FATAL("Invalid hex value for -B/--background: %s", optarg);
   104                         FATAL("Invalid hex value for -B/--background: %s", optarg);
    97                     
   105                     
    98                     // store
   106                     // store
    99                     update_params.background_color[0] = b1;
   107                     update_params.background_color[0] = b1;
   100                     update_params.background_color[1] = b2;
   108                     update_params.background_color[1] = b2;
   180             if (status == PT_CACHE_NONE)
   188             if (status == PT_CACHE_NONE)
   181                 log_debug("\tImage cache is missing");
   189                 log_debug("\tImage cache is missing");
   182 
   190 
   183             else if (status == PT_CACHE_STALE)
   191             else if (status == PT_CACHE_STALE)
   184                 log_debug("\tImage cache is stale");
   192                 log_debug("\tImage cache is stale");
       
   193             
       
   194             else if (status == PT_CACHE_INCOMPAT)
       
   195                 log_debug("\tImage cache is incompatible");
   185 
   196 
   186             else if (status == PT_CACHE_FRESH)
   197             else if (status == PT_CACHE_FRESH)
   187                 log_debug("\tImage cache is fresh");
   198                 log_debug("\tImage cache is fresh");
   188 
   199             
   189             log_debug("\tUpdating image cache...");
   200             if (!no_update) {
   190 
   201                 log_debug("\tUpdating image cache...");
   191             if ((err = pt_image_update(image, &update_params))) {
   202 
   192                 log_warn_errno("pt_image_update: %s: %s", img_path, pt_strerror(err));
   203                 if ((err = pt_image_update(image, &update_params))) {
       
   204                     log_warn_errno("pt_image_update: %s: %s", img_path, pt_strerror(err));
       
   205                 }
       
   206 
       
   207                 log_info("\tUpdated image cache");
       
   208 
       
   209             } else {
       
   210                 log_warn("\tSupressing cache update");
   193             }
   211             }
   194 
   212 
   195             log_info("\tUpdated image cache");
   213         } else {    
       
   214             log_debug("\tImage cache is fresh");
       
   215         }
       
   216 
       
   217         // show info
       
   218         const struct pt_image_info *info;
       
   219         
       
   220         if ((err = pt_image_info(image, &info))) {
       
   221             log_warn_errno("pt_image_info: %s: %s", img_path, pt_strerror(err));
   196 
   222 
   197         } else {
   223         } else {
   198             log_debug("\tImage cache is fresh");
   224             log_info("\tImage dimensions: %zux%zu", info->img_width, info->img_height);
   199         }
   225             log_info("\tImage mtime=%u, bytes=%zu", info->image_mtime, info->image_bytes);
   200 
       
   201         // show info
       
   202         const struct pt_image_info *img_info;
       
   203         
       
   204         if ((err = pt_image_info(image, &img_info))) {
       
   205             log_warn_errno("pt_image_info: %s: %s", img_path, pt_strerror(err));
       
   206 
       
   207         } else {
       
   208             log_info("\tImage dimensions: %zux%zu", img_info->width, img_info->height);
       
   209             log_info("\tImage mtime=%u, bytes=%zu", img_info->image_mtime, img_info->image_bytes);
       
   210             log_info("\tCache mtime=%u, bytes=%zu, blocks=%zu (%zu bytes)", 
   226             log_info("\tCache mtime=%u, bytes=%zu, blocks=%zu (%zu bytes)", 
   211                     img_info->cache_mtime, img_info->cache_bytes, img_info->cache_blocks, img_info->cache_blocks * 512
   227                     info->cache_mtime, info->cache_bytes, info->cache_blocks, info->cache_blocks * 512
   212             );
   228             );
   213         }
   229         }
   214 
   230 
   215         // render tile?
   231         // render tile?
   216         if (ti.width && ti.height) {
   232         if (ti.width && ti.height) {