~ubuntu-branches/debian/sid/pngphoon/sid

« back to all changes in this revision

Viewing changes to main.c

  • Committer: Package Import Robot
  • Author(s): Paulo Roberto Alves de Oliveira (aka kretcheu)
  • Date: 2015-08-10 00:52:00 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20150810005200-6snhuszsm0a97m45
Tags: 1.2-1
* QA upload.
* New upstream release.
* Migrations:
    - DH level to 9.
    - Standards-Version to 3.9.6.
    - debian/copyright to 1.0 format.
    - DebSrc to 3.0 format.
* debian/clean: Included to remove manpage created when building.
* debian/copyright: revised and updated all information.
* debian/dirs: removed because it is useless now.
* debian/install:
    - Included pngphoon binary.
    - Included sample script to use with xdpyinfo from X11-utils.
* debian/manpages: created to install the manpage.
* debian/rules: 
    - Updated to reduced format.
    - Added DEB_BUILD_MAINT_OPTIONS to improve the GCC hardening.
* debian/watch: Improved and removed extra comments.
* Added a patch 01-fix-Makefile-for-hardening
  to enable hardening options and remove library not used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include "moon.h"
4
4
#include "pngwrite.h"
5
5
#include "stars.h"
 
6
#include "fail.h"
6
7
 
7
8
#include <stdio.h>
8
9
#include <stdlib.h>
9
10
#include <unistd.h>
10
11
 
11
 
#define VERSION "1.0"
 
12
#define VERSION "1.2"
12
13
 
13
14
static inline void usage( char *name )
14
15
{
21
22
   }
22
23
   
23
24
   printf( "this is pngphoon version " VERSION "\n\n"
24
 
           "usage: %s options (* = mandatory)\n"
25
 
           "\t-w # width*\n"
26
 
           "\t-h # height*\n"
27
 
           "\t-f $ filename*\n"
28
 
           "\t-x # number of moons in x axis (for multihead configurations)\n"
29
 
           "\t-y # number of moons in y axis (for multihead configurations)\n"
30
 
           "\t-s # star density\n"
31
 
           "\t-b   black (no earthlight)\n", base );
 
25
           "usage: %s options (* = mandatory)\n"
 
26
           "\t-w # width*\n"
 
27
           "\t-h # height*\n"
 
28
           "\t-f $ filename*\n"
 
29
           "\t-x # number of moons in x axis (for multihead configurations)\n"
 
30
           "\t-y # number of moons in y axis (for multihead configurations)\n"
 
31
           "\t-s # star density\n"
 
32
           "\t-b   black (no earthlight)\n"
 
33
           "\t-q   quiet (disable warnings)\n", base );
32
34
   exit(0);
33
35
}
34
36
 
35
37
int main( int argc, char *argv[] )
36
38
{
37
 
   int     width     = 0;
38
 
   int     height    = 0;
39
 
   int     xmoons    = 1;
40
 
   int     ymoons    = 1;
41
 
   int     stars     = 50;
42
 
   char    *filename = NULL;
43
 
   int     black     = 0;
44
 
   image_t *image    = NULL;
45
 
   moon_t  *moon     = NULL;
 
39
   int     width      = 0;
 
40
   int     height     = 0;
 
41
   int     drawheight = 0;
 
42
   int     xmoons     = 1;
 
43
   int     ymoons     = 1;
 
44
   int     stars      = 50;
 
45
   char    *filename  = NULL;
 
46
   int     black      = 0;
 
47
   image_t *image     = NULL;
 
48
   moon_t  *moon      = NULL;
46
49
   int     c;
47
50
   int     x;
48
51
   int     y;
54
57
      usage( argv[0] );
55
58
   }
56
59
   
57
 
   while ((c = getopt (argc, argv, "w:h:x:y:s:f:b")) != EOF)
 
60
   while ((c = getopt (argc, argv, "w:h:x:y:s:f:bq")) != EOF)
58
61
   {
59
62
      switch (c)
60
63
      {
61
 
         case 'w':
62
 
            width    = strtol( optarg, NULL, 0 );
63
 
            break;
64
 
         case 'h':
65
 
            height   = strtol( optarg, NULL, 0 );
66
 
            break;
67
 
         case 'x':
68
 
            xmoons   = strtol( optarg, NULL, 0 );
69
 
            break;
70
 
         case 'y':
71
 
            ymoons   = strtol( optarg, NULL, 0 );
72
 
            break;
73
 
         case 's':
74
 
            stars    = strtol( optarg, NULL, 0 );
75
 
            break;
76
 
         case 'f':
77
 
            filename = optarg;
78
 
            break;
79
 
         case 'b':
80
 
            black    = 1;
81
 
            break;
82
 
         default:
83
 
            printf("unknown option: '%c'\n", c);
 
64
      case 'w':
 
65
         width    = strtol( optarg, NULL, 0 );
 
66
         break;
 
67
      case 'h':
 
68
         height   = strtol( optarg, NULL, 0 );
 
69
         break;
 
70
      case 'x':
 
71
         xmoons   = strtol( optarg, NULL, 0 );
 
72
         break;
 
73
      case 'y':
 
74
         ymoons   = strtol( optarg, NULL, 0 );
 
75
         break;
 
76
      case 's':
 
77
         stars    = strtol( optarg, NULL, 0 );
 
78
         break;
 
79
      case 'f':
 
80
         filename = optarg;
 
81
         break;
 
82
      case 'b':
 
83
         black    = 1;
 
84
         break;
 
85
      case 'q':
 
86
         disablewarn();
 
87
         break;
 
88
      default:
 
89
         fail("unknown option: '%c'\n", c);
84
90
      }
85
91
   }
86
92
   
87
93
   if( !width || !height || !filename )
88
94
   {
89
 
      printf( "you need to specify at least width, height and filename\n" );
90
 
      exit(1);
 
95
      fail( "you need to specify at least width, height and filename\n" );
91
96
   }
92
97
   
93
98
   moon = mooncreate();
 
99
 
 
100
   if( width < moon->width )
 
101
   {
 
102
      warn( "image not wide enough for anything, just creating stars\n" );
 
103
      xmoons = 0;
 
104
   }
 
105
 
 
106
   if( width < moon->width * xmoons )
 
107
   {
 
108
      warn( "decreasing number of moons in x axis from %d ", xmoons );
 
109
      while( width < moon->width * --xmoons );
 
110
      warn( "to %d moons.\n", xmoons );
 
111
   }
 
112
 
 
113
   drawheight = height;
 
114
   if( height < moon->height )
 
115
   {
 
116
      warn( "image not high enough for moon, using truncate mode\n" );
 
117
      drawheight = moon->height;
 
118
      ymoons = 1;
 
119
   }
 
120
   else
 
121
   {
 
122
      if( height < moon->height * ymoons )
 
123
      {
 
124
         warn( "decreasing number of moons in y axis from %d ", ymoons );
 
125
         /* this is not nice, but works: decreasing number of moons until they fit */
 
126
         while( width < (moon->width * --ymoons) );
 
127
         warn( "to %d moons.\n", ymoons );
 
128
      }
 
129
   }
94
130
   
95
 
   image = imagecreate( width, height );
96
 
   if( (width  < (moon->width)  * xmoons) ||
97
 
       (height < (moon->height) * ymoons) )
98
 
   {
99
 
      printf("image too small to fit moon%s, creating stars only\n",
100
 
             (xmoons * ymoons > 1) ? "s" : "");
 
131
   image = imagecreate( width, drawheight );
 
132
   if( xmoons * ymoons )
 
133
   {
 
134
      scarymonster( image, stars );
 
135
      for( y = (drawheight/ymoons)/2; y < height; y += (drawheight/ymoons) )
 
136
      {
 
137
         for( x = (width/xmoons)/2; x < width; x += (width/xmoons) )
 
138
         {
 
139
            mooncopy( image, moon, x, y, black );
 
140
         }
 
141
      }
 
142
   }
 
143
   else
 
144
   {
101
145
      scarymonster( image, stars * 2 );
102
146
   }
103
 
   else
104
 
   {
105
 
      scarymonster( image, stars );
106
 
      for( y = (height/ymoons)/2; y < height; y += (height/ymoons) )
107
 
      {
108
 
         for( x = (width/xmoons)/2; x < width; x += (width/xmoons) )
109
 
         {
110
 
            mooncopy( image, moon, x, y, black );
111
 
         }
112
 
      }
113
 
   }
114
 
   pngwrite( image, filename );
 
147
   pngwrite( image, filename, height );
115
148
   imagedestroy( image );
116
149
   moondestroy( moon );
117
150