Mercurial > mplayer.hg
comparison libvo/vo_jpeg.c @ 13283:858b7e04718c
This patch moves the directory creation code to a separate function. I have
tried to re-use as much code as possible, to reduce the size of the patch.
All duplicate code is removed, resulting in my first patch that actually
decreases the size of the binary by about 700 bytes :-)
author | ivo |
---|---|
date | Wed, 08 Sep 2004 01:11:16 +0000 |
parents | 7dfd84faaa09 |
children | 6370626e902b |
comparison
equal
deleted
inserted
replaced
13282:a46dce85af0a | 13283:858b7e04718c |
---|---|
78 | 78 |
79 static int framenum = 0; | 79 static int framenum = 0; |
80 | 80 |
81 /* ------------------------------------------------------------------------- */ | 81 /* ------------------------------------------------------------------------- */ |
82 | 82 |
83 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, | 83 /** \brief Create a directory. |
84 uint32_t d_height, uint32_t fullscreen, char *title, | 84 * |
85 uint32_t format) | 85 * This function creates a directory. If it already exists, it tests if |
86 { | 86 * it's a directory and not something else, and if it is, it tests whether |
87 char buf[BUFLENGTH]; | 87 * the directory is writable or not. |
88 * | |
89 * \param buf Pointer to directory name. | |
90 * \param verbose Verbose on success. If verbose is non-zero, it will print | |
91 * a message if it was successful in creating the directory. | |
92 * | |
93 * \return nothing In case anything fails, the player will exit. If it | |
94 * returns, everything went well. | |
95 */ | |
96 | |
97 void jpeg_mkdir(char *buf, int verbose) { | |
88 struct stat stat_p; | 98 struct stat stat_p; |
89 | 99 |
90 /* Create outdir. | |
91 * If it already exists, test if it's a writable directory */ | |
92 | |
93 snprintf(buf, BUFLENGTH, "%s", jpeg_outdir); | |
94 | |
95 if ( mkdir(buf, 0755) < 0 ) { | 100 if ( mkdir(buf, 0755) < 0 ) { |
96 switch (errno) { /* use switch in case other errors need to be caught | 101 switch (errno) { /* use switch in case other errors need to be caught |
97 and handled in the future */ | 102 and handled in the future */ |
98 case EEXIST: | 103 case EEXIST: |
99 if ( stat(buf, &stat_p ) < 0 ) { | 104 if ( stat(buf, &stat_p ) < 0 ) { |
107 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, | 112 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, |
108 buf, MSGTR_VO_JPEG_ExistsButNoDirectory); | 113 buf, MSGTR_VO_JPEG_ExistsButNoDirectory); |
109 exit_player(MSGTR_Exit_error); | 114 exit_player(MSGTR_Exit_error); |
110 } | 115 } |
111 if ( !(stat_p.st_mode & S_IWUSR) ) { | 116 if ( !(stat_p.st_mode & S_IWUSR) ) { |
112 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | 117 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name, |
113 MSGTR_VO_JPEG_DirExistsButNotWritable); | 118 buf, MSGTR_VO_JPEG_DirExistsButNotWritable); |
114 exit_player(MSGTR_Exit_error); | 119 exit_player(MSGTR_Exit_error); |
115 } | 120 } |
116 | 121 |
117 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | 122 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name, |
118 MSGTR_VO_JPEG_DirExistsAndIsWritable); | 123 buf, MSGTR_VO_JPEG_DirExistsAndIsWritable); |
119 break; | 124 break; |
120 | 125 |
121 default: | 126 default: |
122 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | 127 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, |
123 MSGTR_VO_JPEG_GenericError, strerror(errno) ); | 128 MSGTR_VO_JPEG_GenericError, strerror(errno) ); |
124 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | 129 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name, |
125 MSGTR_VO_JPEG_CantCreateDirectory); | 130 buf, MSGTR_VO_JPEG_CantCreateDirectory); |
126 exit_player(MSGTR_Exit_error); | 131 exit_player(MSGTR_Exit_error); |
127 } /* end switch */ | 132 } /* end switch */ |
128 } else { | 133 } else if ( verbose ) { |
129 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | 134 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name, |
130 MSGTR_VO_JPEG_DirectoryCreateSuccess); | 135 buf, MSGTR_VO_JPEG_DirectoryCreateSuccess); |
131 } /* end if */ | 136 } /* end if */ |
137 } | |
138 | |
139 /* ------------------------------------------------------------------------- */ | |
140 | |
141 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, | |
142 uint32_t d_height, uint32_t fullscreen, char *title, | |
143 uint32_t format) | |
144 { | |
145 char buf[BUFLENGTH]; | |
146 | |
147 /* Create outdir. */ | |
148 | |
149 snprintf(buf, BUFLENGTH, "%s", jpeg_outdir); | |
150 | |
151 jpeg_mkdir(buf, 1); /* This function only returns if creation was | |
152 successful. If not, the player will exit. */ | |
132 | 153 |
133 image_height = height; | 154 image_height = height; |
134 image_width = width; | 155 image_width = width; |
135 | 156 |
136 return 0; | 157 return 0; |
208 * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */ | 229 * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */ |
209 if ( !framecounter && jpeg_subdirs ) { | 230 if ( !framecounter && jpeg_subdirs ) { |
210 snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, | 231 snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, |
211 ++subdircounter); | 232 ++subdircounter); |
212 snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname); | 233 snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname); |
213 if ( mkdir(buf, 0755) < 0 ) { | 234 jpeg_mkdir(buf, 0); /* This function only returns if creation was |
214 switch (errno) { /* use switch in case other errors need to be | 235 successful. If not, the player will exit. */ |
215 caught and handled in the future */ | 236 } |
216 case EEXIST: | |
217 if ( stat(buf, &stat_p) < 0 ) { | |
218 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", | |
219 info.short_name, MSGTR_VO_JPEG_GenericError, | |
220 strerror(errno) ); | |
221 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", | |
222 info.short_name, MSGTR_VO_JPEG_UnableToAccess, | |
223 buf); | |
224 exit_player(MSGTR_Exit_error); | |
225 } | |
226 if ( !S_ISDIR(stat_p.st_mode) ) { | |
227 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n", | |
228 info.short_name, buf, | |
229 MSGTR_VO_JPEG_ExistsButNoDirectory); | |
230 exit_player(MSGTR_Exit_error); | |
231 } | |
232 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
233 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n", | |
234 info.short_name, buf, | |
235 MSGTR_VO_JPEG_DirExistsButNotWritable); | |
236 exit_player(MSGTR_Exit_error); | |
237 } | |
238 | |
239 mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n", | |
240 info.short_name, buf, | |
241 MSGTR_VO_JPEG_DirExistsAndIsWritable); | |
242 break; | |
243 | |
244 default: | |
245 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
246 MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
247 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n", | |
248 info.short_name, buf, | |
249 MSGTR_VO_JPEG_CantCreateDirectory); | |
250 exit_player(MSGTR_Exit_error); | |
251 break; | |
252 } | |
253 } /* switch */ | |
254 } /* if !framecounter && jpeg_subdirs */ | |
255 | 237 |
256 framenum++; | 238 framenum++; |
257 | 239 |
258 /* snprintf the full pathname of the outputfile */ | 240 /* snprintf the full pathname of the outputfile */ |
259 snprintf(buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname, | 241 snprintf(buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname, |