• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

特定条件(ファイルサイズや画像サイズ)の画像削除


Commit MetaInfo

Révision1 (tree)
l'heure2014-10-29 22:09:14
Auteuryuki0220

Message de Log

rempic V0.1 release

Change Summary

Modification

--- branch/rempic-0.1/file_chk.c (nonexistent)
+++ branch/rempic-0.1/file_chk.c (revision 1)
@@ -0,0 +1,57 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+
44+/*******************************************************************************
45+ * Extension check ************************************************************/
46+unsigned int ext_chk (unsigned char *ext)
47+{
48+ if (strcmp ((char *)ext, "jpg" )==0) {return GEXTJPG; }
49+ else if (strcmp ((char *)ext, "JPG" )==0) {return GEXTJPG; }
50+ else if (strcmp ((char *)ext, "jpeg")==0) {return GEXTJPEG;}
51+ else if (strcmp ((char *)ext, "png" )==0) {return GEXTPNG; }
52+ else if (strcmp ((char *)ext, "PNG" )==0) {return GEXTPNG; }
53+ else if (strcmp ((char *)ext, "gif" )==0) {return GEXTGIF; }
54+ else if (strcmp ((char *)ext, "GIF" )==0) {return GEXTGIF; }
55+
56+ return GEXTNOGRAPHIC;
57+}
--- branch/rempic-0.1/rempic.h (nonexistent)
+++ branch/rempic-0.1/rempic.h (revision 1)
@@ -0,0 +1,149 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+#ifndef REMPIC_H__
26+#define REMPIC_H__ __DATE__
27+
28+/*******************************************************************************
29+ * Include ********************************************************************/
30+#if !defined(MACRO_H_)
31+# include <macro.h>
32+#endif
33+#if !defined(_SYS_PARAM_H_) && !defined(_SYS_PARAM_H)
34+# include <sys/param.h>
35+#endif
36+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
37+# include <stdio.h>
38+#endif
39+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
40+# include <sys/stat.h>
41+#endif
42+
43+
44+/*******************************************************************************
45+ * Define *********************************************************************/
46+/*=Program state==============================================================*/
47+#define VERSION "1.0.0" /* Program version */
48+/*=Option Flags===============================================================*/
49+#define FLGALL 0x000003ff /* All flags bits */
50+#define FLGDEBUGMODE 0x00000001 /* Debug Mode ON (-D) */
51+#define FLGRECURSIVE 0x00000002 /* Directory Recursive ON (-r)*/
52+#define FLGRMPICBADFILE 0x00000004 /* rm picture badfile (-b) */
53+#define FLGALLFILES 0x00000008 /* target is ALL files (-a) */
54+#define FLGRMUPPERSIZE 0x00000010 /* rm upper picture bytes (-S)*/
55+#define FLGRMLOWERSIZE 0x00000020 /* rm lower picture bytes (-s)*/
56+#define FLGRMUPPERX 0x00000040 /* rm upper picture x (-X) */
57+#define FLGRMLOWERX 0x00000080 /* rm lower picture x (-x) */
58+#define FLGRMUPPERY 0x00000100 /* rm upper picture y (-Y) */
59+#define FLGRMLOWERY 0x00000200 /* rm lower picture y (-y) */
60+/*=Path Process Return========================================================*/
61+#define PPRALLKILL -1
62+#define PPRABORT -2
63+/*=Remove check===============================================================*/
64+#define RMCHKINIT 0
65+#define RMCHKREMOVE 1
66+#define RMCHKSAVE 2
67+/*=Graphic extension==========================================================*/
68+#define GEXTERROR 0x00000000
69+#define GEXTNOGRAPHIC 0x00000001
70+#define GEXTGRAPHICALL 0x0000001e
71+#define GEXTJPG 0x00000002
72+#define GEXTPNG 0x00000004
73+#define GEXTJPEG 0x00000008
74+#define GEXTGIF 0x00000010
75+/*=Graphic config=============================================================*/
76+#define MAXMALLOCSIZE 0x1fffff /* Max allocate memory size */
77+/*=Graphic config(JPEG)=======================================================*/
78+#define JPGMARKSOL 0x1
79+#define JPGMARKEOL 0x2
80+
81+/*******************************************************************************
82+ * Save Path name *************************************************************/
83+/*=File Type define===========================================================*/
84+#define SPFTINIT 0x00 /* File type init */
85+#define SPFTFILE 0x01 /* File type is normal */
86+#define SPFTDIR 0x02 /* File type is dir */
87+#define SPFTOTHERS 0x03 /* Other file type */
88+#define SPFTUNKNOWN 0x04 /* File type is unknown */
89+/*=structure==================================================================*/
90+typedef struct SAVEPATHNAME {
91+ struct SAVEPATHNAME *farray;
92+ unsigned char ft; /* File Type */
93+ unsigned char path[MAXPATHLEN]; /* path name */
94+ unsigned int fnum; /* This directory have File number */
95+ struct stat sb;
96+} spname;
97+
98+/*******************************************************************************
99+ * Pic info *******************************************************************/
100+typedef struct {
101+ unsigned char fm;
102+ unsigned int ft;
103+ unsigned char perUnit;
104+ off_t fsize;
105+ unsigned long img_x, img_y;
106+} picInfo;
107+
108+
109+/*******************************************************************************
110+ * Global functions ***********************************************************/
111+/*=file_chk===================================================================*/
112+void jpeg_chk (int fd, picInfo *pinfo);
113+unsigned int ext_chk (unsigned char *ext);
114+/*=open_dir===================================================================*/
115+int open_dir (spname *pspn);
116+/*=option.c===================================================================*/
117+int opt_proc (int argc, char **argv);
118+/*=remove.c===================================================================*/
119+int remove_chk (spname finfo);
120+/*=stdlib.c===================================================================*/
121+void * malloc_init (size_t size);
122+/*=usage.c====================================================================*/
123+void usage (void);
124+/*=jpg_chk====================================================================*/
125+void jpeg_chk (int fd, picInfo *pinfo);
126+/*=png_chk====================================================================*/
127+void png_chk (int fd, picInfo *pinfo);
128+/*=gif_chk====================================================================*/
129+void gif_chk (int fd, picInfo *pinfo);
130+
131+/*******************************************************************************
132+ * Global variables ***********************************************************/
133+/*-Program state--------------------------------------------------------------*/
134+char *pname; /* Program name */
135+/*-Option Process-------------------------------------------------------------*/
136+unsigned int flags;
137+spname *patharray;
138+unsigned int FirstPathNum;
139+unsigned int TargetFileType;
140+off_t UpperSize, LowerSize;
141+unsigned int UpperX, LowerX;
142+unsigned int UpperY, LowerY;
143+/*-Error Output---------------------------------------------------------------*/
144+FILE *debugout;
145+FILE *usageout;
146+FILE *patherr;
147+
148+
149+#endif /* REMPIC_H__ */
--- branch/rempic-0.1/usage.c (nonexistent)
+++ branch/rempic-0.1/usage.c (revision 1)
@@ -0,0 +1,53 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
34+# include <stdlib.h>
35+#endif
36+
37+/*******************************************************************************
38+ * Usage **********************************************************************/
39+void usage (void)
40+{
41+ usageout = stdout;
42+ fprintf (usageout, "%s [-x LowXSize] [-X UpperXSize] [-y LowYSize] [-Y UpperYSize]\n", pname);
43+ fprintf (usageout, "\t[-s UnderSize] [-S OverSize] [-a] [-b] [-r] [-D] targetname....\n");
44+ fprintf (usageout, "\t-x|-X : Target X-Length, LowXSize<TargetXSize, TargetXSize<UpperXSize\n");
45+ fprintf (usageout, "\t-y|-Y : Target Y-Length, LowYSize<TargetYSize, TargetYSize<UpperYSize\n");
46+ fprintf (usageout, "\t-s|-S : Target Size , UnderSize<TargetFileSize, TargetFileSize<OverSize\n");
47+ fprintf (usageout, "\t-a : Include hide file\n");
48+ fprintf (usageout, "\t-b : Remove Bad format file\n");
49+ fprintf (usageout, "\t-r : Recurcive Directory\n");
50+ fprintf (usageout, "\t-D : Debug mode\n");
51+
52+ exit (1);
53+}
--- branch/rempic-0.1/jpg_chk.c (nonexistent)
+++ branch/rempic-0.1/jpg_chk.c (revision 1)
@@ -0,0 +1,288 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+/*//========================================================================\\*
44+ *|| Jpeg check ||*
45+ *\\========================================================================//*/
46+/*******************************************************************************
47+ * jpeg check APP0 ************************************************************/
48+static int jpeg_chk_app0 (picInfo *pinfo, unsigned char *data, off_t len)
49+{
50+ data+=2; /* skip head length */
51+ if (strncmp ((char *)data, "JFIF", 4)!=0) {goto err_proc;}
52+ else if (*(data+4)!=0x00) {goto err_proc;}
53+ data+=5;
54+ data+=2; /* skip version */
55+ pinfo->perUnit = *data; data+=1; /* unit */
56+
57+ pinfo->fm = 0;
58+ return 1;
59+ err_proc:
60+ pinfo->fm = 1;
61+ return 0;
62+}
63+/*******************************************************************************
64+ * jpeg check SOF0 ************************************************************/
65+static int jpeg_chk_sof0 (picInfo *pinfo, unsigned char *data, off_t len)
66+{
67+ data+=2; /* skip head length */
68+ /*if (*(data+0)!=0x08) {goto err_proc;}*/
69+ data+=1;
70+ pinfo->img_y = ((unsigned short)(*data)<<8) | ((unsigned short)*(data+1)); data+=2;
71+ pinfo->img_x = ((unsigned short)(*data)<<8) | ((unsigned short)*(data+1)); data+=2;
72+ if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("img_x: %ld, img_y: %ld\n", pinfo->img_x, pinfo->img_y);}
73+
74+ pinfo->fm = 0;
75+ return 1;
76+
77+ pinfo->fm = 1;
78+ return 0;
79+}
80+
81+/*******************************************************************************
82+ * jpeg check(jpg,jpeg) *******************************************************/
83+void jpeg_chk (int fd, picInfo *pinfo)
84+{
85+ unsigned int masize;
86+ unsigned char *ifpot, *ifoff, br;
87+ off_t rlen, off_set, size;
88+ int i, rrtn;
89+
90+ pinfo->fm = 0;
91+ /*******************************************************************
92+ * Get File size and allocate memory ******************************/
93+ masize = MIN((unsigned int)pinfo->fsize, (unsigned int)MAXMALLOCSIZE);
94+ if ((ifpot=(unsigned char *)malloc_init (masize))==NULL) {return ;}
95+ ifoff = ifpot;
96+ br = rlen = off_set = 0;
97+
98+
99+ /*-Get packet info from input file and dividing flow Start--------*/
100+ while ((rrtn=read (fd, ifoff, (masize-rlen)))>=0) {
101+ rlen = (off_t)rrtn + rlen;
102+ if (rlen<0) {free (ifpot); return;}
103+ ifoff = ifpot;
104+ if (off_set==0 && rlen==0) {pinfo->fm = 1; br=1; break;}
105+
106+ /*-Get packet info from read data Start-------------------------*/
107+ while (rlen>=2) {
108+ if (off_set==0) { /* SOL */
109+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOL\n");}
110+ if (!(*ifoff==0xff && *(ifoff+1)==0xd8)) {
111+ pinfo->fm = 1;
112+ br=1; break;
113+ }
114+ size = 2;
115+ } else if (*ifoff==0xff && *(ifoff+1)==0xe0) { /* APP0 */
116+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP0\n");}
117+ if (rlen<4) {break;}
118+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
119+ if (rlen<(size+2)) {break;}
120+ else if (!jpeg_chk_app0 (pinfo, ifoff+2, size)) {br=1; break;}
121+ size+=2;
122+ } else if (*ifoff==0xff && *(ifoff+1)==0xdb) { /* DQT */
123+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("DQT\n");}
124+ if (rlen<4) {break;}
125+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
126+ if (rlen<(size+2)) {break;}
127+ size+=2;
128+ } else if (*ifoff==0xff && *(ifoff+1)==0xc4) { /* DHT */
129+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("DHT\n");}
130+ if (rlen<4) {break;}
131+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
132+ if (rlen<(size+2)) {break;}
133+ size+=2;
134+ } else if (*ifoff==0xff && *(ifoff+1)==0xc0) { /* SOF0 */
135+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOF0\n");}
136+ if (rlen<4) {break;}
137+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
138+ if (rlen<(size+2)) {break;}
139+ else if (!jpeg_chk_sof0 (pinfo, ifoff+2, size)) {br=1; break;}
140+ size+=2;
141+ } else if (*ifoff==0xff && *(ifoff+1)==0xc1) { /* SOF1 */
142+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOF1\n");}
143+ if (rlen<4) {break;}
144+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
145+ if (rlen<(size+2)) {break;}
146+ else if (!jpeg_chk_sof0 (pinfo, ifoff+2, size)) {br=1; break;}
147+ size+=2;
148+ } else if (*ifoff==0xff && *(ifoff+1)==0xc2) { /* SOF2 */
149+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOF2\n");}
150+ if (rlen<4) {break;}
151+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
152+ if (rlen<(size+2)) {break;}
153+ else if (!jpeg_chk_sof0 (pinfo, ifoff+2, size)) {br=1; break;}
154+ size+=2;
155+ } else if (*ifoff==0xff && *(ifoff+1)==0xd9) { /* EOL */
156+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("EOL\n");}
157+ if (rlen<4) {break;}
158+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
159+ if (rlen<(size+2)) {break;}
160+ size+=2;
161+ } else if (*ifoff==0xff && *(ifoff+1)==0xe1) { /* APP1 */
162+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP1\n");}
163+ if (rlen<4) {break;}
164+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
165+ if (rlen<(size+2)) {break;}
166+ size+=2;
167+ } else if (*ifoff==0xff && *(ifoff+1)==0xe2) { /* APP2 */
168+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP1\n");}
169+ if (rlen<4) {break;}
170+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
171+ if (rlen<(size+2)) {break;}
172+ size+=2;
173+ } else if (*ifoff==0xff && *(ifoff+1)==0xe3) { /* APP3 */
174+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP3\n");}
175+ if (rlen<4) {break;}
176+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
177+ if (rlen<(size+2)) {break;}
178+ size+=2;
179+ } else if (*ifoff==0xff && *(ifoff+1)==0xe4) { /* APP4 */
180+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP4\n");}
181+ if (rlen<4) {break;}
182+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
183+ if (rlen<(size+2)) {break;}
184+ size+=2;
185+ } else if (*ifoff==0xff && *(ifoff+1)==0xe5) { /* APP5 */
186+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP5\n");}
187+ if (rlen<4) {break;}
188+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
189+ if (rlen<(size+2)) {break;}
190+ size+=2;
191+ } else if (*ifoff==0xff && *(ifoff+1)==0xe6) { /* APP6 */
192+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP6\n");}
193+ if (rlen<4) {break;}
194+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
195+ if (rlen<(size+2)) {break;}
196+ size+=2;
197+ } else if (*ifoff==0xff && *(ifoff+1)==0xe7) { /* APP7 */
198+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP7\n");}
199+ if (rlen<4) {break;}
200+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
201+ if (rlen<(size+2)) {break;}
202+ size+=2;
203+ } else if (*ifoff==0xff && *(ifoff+1)==0xe8) { /* APP8 */
204+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP8\n");}
205+ if (rlen<4) {break;}
206+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
207+ if (rlen<(size+2)) {break;}
208+ size+=2;
209+ } else if (*ifoff==0xff && *(ifoff+1)==0xe9) { /* APP9 */
210+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP9\n");}
211+ if (rlen<4) {break;}
212+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
213+ if (rlen<(size+2)) {break;}
214+ size+=2;
215+ } else if (*ifoff==0xff && *(ifoff+1)==0xea) { /* APPa */
216+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPa\n");}
217+ if (rlen<4) {break;}
218+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
219+ if (rlen<(size+2)) {break;}
220+ size+=2;
221+ } else if (*ifoff==0xff && *(ifoff+1)==0xeb) { /* APPb */
222+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPb\n");}
223+ if (rlen<4) {break;}
224+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
225+ if (rlen<(size+2)) {break;}
226+ size+=2;
227+ } else if (*ifoff==0xff && *(ifoff+1)==0xec) { /* APPc */
228+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPc\n");}
229+ if (rlen<4) {break;}
230+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
231+ if (rlen<(size+2)) {break;}
232+ size+=2;
233+ } else if (*ifoff==0xff && *(ifoff+1)==0xed) { /* APPd */
234+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPd\n");}
235+ if (rlen<4) {break;}
236+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
237+ /*printf ("appd size: 0x%4X\n", size);*/
238+ if (rlen<(size+2)) {break;}
239+ size+=2;
240+ } else if (*ifoff==0xff && *(ifoff+1)==0xee) { /* APPe */
241+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPe\n");}
242+ if (rlen<4) {break;}
243+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
244+ /*printf ("appd size: 0x%4X\n", size);*/
245+ if (rlen<(size+2)) {break;}
246+ size+=2;
247+ } else if (*ifoff==0xff && *(ifoff+1)==0xef) { /* APPf */
248+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPf\n");}
249+ if (rlen<4) {break;}
250+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
251+ /*printf ("appd size: 0x%4X\n", size);*/
252+ if (rlen<(size+2)) {break;}
253+ size+=2;
254+ } else if (*ifoff==0xff && *(ifoff+1)==0xda) { /* SOS */
255+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOS\n");}
256+ if (rlen<4) {break;}
257+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
258+ if (rlen<(size+2)) {break;}
259+ size+=2;
260+ } else if (*ifoff==0xff && *(ifoff+1)==0xfe) { /* comment */
261+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("comment\n");}
262+ if (rlen<4) {break;}
263+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
264+ if (rlen<(size+2)) {break;}
265+ size+=2;
266+ } else {
267+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("else: 0x%2X%2X\n", *ifoff, *(ifoff+1));}
268+ br=1; break;
269+ }
270+ /*if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("size: 0x%4X%\n", size);}*/
271+
272+ if (pinfo->img_x!=0 && pinfo->img_y!=0) {br=1; break;}
273+ rlen -= size; ifoff += size; off_set += size;
274+ }
275+ if (br) {break;}
276+
277+
278+ /*-Get packet info from read data End---------------------------*/
279+ for (i=0; i<rlen; i++) {*(ifpot+i) = *(ifoff+i);}
280+ ifoff = ifpot + rlen;
281+ }
282+ if (pinfo->img_x==0 || pinfo->img_y==0) {pinfo->fm = 1;}
283+ /*-Get packet info from input file and dividing flow End----------*/
284+ free (ifpot);
285+
286+ return ;
287+}
288+
--- branch/rempic-0.1/macro.h (nonexistent)
+++ branch/rempic-0.1/macro.h (revision 1)
@@ -0,0 +1,36 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+#ifndef MACRO_H__
26+#define MACRO_H__ __DATE__
27+
28+/*******************************************************************************
29+ * Flagment processing ********************************************************/
30+#define FLGINIT(a) (*a=0) /* Flag initialise */
31+#define FLGSET(a,b) (*a|=b) /* Set flag bit */
32+#define FLGCLR(a,b) (*a^=(*a&b)) /* Clear flag bit */
33+#define FLGTGR(a,b) (*a^=b) /* Toggle flag bit */
34+#define FLGCHK(a,b) ((a&b)==b?1:0) /* Check flag bit */
35+
36+#endif /* MACRO_H__ */
--- branch/rempic-0.1/option.c (nonexistent)
+++ branch/rempic-0.1/option.c (revision 1)
@@ -0,0 +1,126 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_SYS_PARAM_H_) && !defined(_SYS_PARAM_H)
31+# include <sys/param.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+
44+/*******************************************************************************
45+ * Size transfer **************************************************************/
46+static off_t SizeTransfer (char *str)
47+{
48+ char chk;
49+ int rlen, shift;
50+ unsigned int idx, isize;
51+ double dsize;
52+
53+ shift = chk = 0;
54+ rlen = strlen (str);
55+ for (idx=0; idx<rlen; idx++) {
56+ if (idx==(rlen-1)) {
57+ if ('0'<=str[idx] && str[idx]<='9') {}
58+ else if (str[idx]=='k' || str[idx]=='K') {shift=10; str[idx]=0x00;}
59+ else if (str[idx]=='m' || str[idx]=='M') {shift=20; str[idx]=0x00;}
60+ else if (str[idx]=='g' || str[idx]=='G') {shift=30; str[idx]=0x00;}
61+ } else {
62+ if ('0'<=str[idx] && str[idx]<='9') {}
63+ else if (chk==0 && str[idx]=='.') {chk = 1;}
64+ else {return -1;}
65+ }
66+ }
67+ dsize = strtod (str, NULL);
68+ isize = (int)(dsize * (double)(1<<shift));
69+ /*printf ("size: %u\n", isize);*/
70+ return (off_t)isize;
71+}
72+
73+/*******************************************************************************
74+ * Option *********************************************************************/
75+int opt_proc (int argc, char **argv)
76+{
77+ int i;
78+ int ch;
79+
80+ /*****************************************************************************
81+ * Option init **************************************************************/
82+ pname = *argv;
83+ patherr = stdout;
84+ debugout = stdout;
85+ TargetFileType = 0;
86+ UpperSize = LowerSize = 0;
87+
88+ /*****************************************************************************
89+ * Get Option ***************************************************************/
90+ while ((ch = getopt (argc, argv, "abrS:s:X:x:Y:y:Dh?"))>=0) {
91+ switch (ch) {
92+ case 'a': FLGSET(&flags, FLGALLFILES); break;
93+ case 'b': FLGSET(&flags, FLGRMPICBADFILE); break;
94+ case 'r': FLGSET(&flags, FLGRECURSIVE); break;
95+ case 's': FLGSET(&flags, FLGRMLOWERSIZE); if ((LowerSize = SizeTransfer (optarg))==-1) {usage ();}; break;
96+ case 'S': FLGSET(&flags, FLGRMUPPERSIZE); if ((UpperSize = SizeTransfer (optarg))==-1) {usage ();}; break;
97+ case 'x': FLGSET(&flags, FLGRMLOWERX); LowerX = (unsigned int)atoi (optarg); break;
98+ case 'X': FLGSET(&flags, FLGRMUPPERX); UpperX = (unsigned int)atoi (optarg); break;
99+ case 'y': FLGSET(&flags, FLGRMLOWERY); LowerY = (unsigned int)atoi (optarg); break;
100+ case 'Y': FLGSET(&flags, FLGRMUPPERY); UpperY = (unsigned int)atoi (optarg); break;
101+ case 'D': FLGSET(&flags, FLGDEBUGMODE); break;
102+ case 'h': case '?': default:
103+ usage ();
104+ }
105+ }
106+ argc -= optind;
107+ argv += optind;
108+
109+ /*****************************************************************************
110+ * Option After process *****************************************************/
111+ if (TargetFileType==0) {TargetFileType = GEXTGRAPHICALL;}
112+
113+ FirstPathNum = argc;
114+ if ((patharray=malloc_init ((sizeof (spname)*argc)))==NULL) {
115+ fprintf (stderr, "Memory allocate error for path name\n");
116+ return 0;
117+ }
118+ for (i=0; i<argc; i++) {
119+ memcpy ((patharray+i)->path, *(argv+i), MIN(MAXPATHLEN, strlen (*(argv+i))));
120+ if ((patharray+i)->path[strlen (*(argv+i))-1]=='/') {
121+ (patharray+i)->path[strlen (*(argv+i))-1] = 0;
122+ }
123+ }
124+
125+ return 1;
126+}
--- branch/rempic-0.1/png_chk.c (nonexistent)
+++ branch/rempic-0.1/png_chk.c (revision 1)
@@ -0,0 +1,130 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+/*//========================================================================\\*
44+ *|| Jpeg check ||*
45+ *\\========================================================================//*/
46+/*******************************************************************************
47+ * png check IHDL *************************************************************/
48+static int png_chk_ihdl (picInfo *pinfo, unsigned char *data, off_t len)
49+{
50+ pinfo->img_x = ((unsigned long)(*data)<<24)|((unsigned long)(*(data+1))<<16)|((unsigned long)(*(data+2))<<8)|(unsigned long)(*(data+3));data+=4;
51+ pinfo->img_y = ((unsigned long)(*data)<<24)|((unsigned long)(*(data+1))<<16)|((unsigned long)(*(data+2))<<8)|(unsigned long)(*(data+3));data+=4;
52+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("img_x: %ld, img_y: %ld\n", pinfo->img_x, pinfo->img_y);}
53+
54+ pinfo->fm = 0;
55+ return 1;
56+
57+ pinfo->fm = 1;
58+ return 0;
59+}
60+
61+/*******************************************************************************
62+ * png check(jpg,jpeg) *******************************************************/
63+void png_chk (int fd, picInfo *pinfo)
64+{
65+ unsigned int masize;
66+ unsigned char *ifpot, *ifoff, br;
67+ off_t rlen, off_set, size;
68+ unsigned int crc, crc_chk, hl;
69+ int i, rrtn;
70+
71+ pinfo->fm = 0;
72+ /*******************************************************************
73+ * Get File size and allocate memory ******************************/
74+ masize = MIN((unsigned int)pinfo->fsize, (unsigned int)MAXMALLOCSIZE);
75+ if ((ifpot=(unsigned char *)malloc_init (masize))==NULL) {return ;}
76+ ifoff = ifpot;
77+ br = rlen = off_set = 0;
78+
79+
80+ /*-Get packet info from input file and dividing flow Start--------*/
81+ while ((rrtn=read (fd, ifoff, (masize-rlen)))>=0) {
82+ rlen = (off_t)rrtn + rlen;
83+ if (rlen<0) {free (ifpot); return;}
84+ ifoff = ifpot;
85+ if (off_set==0 && rlen==0) {pinfo->fm = 1; br=1; break;}
86+
87+ /*-Get packet info from read data Start-------------------------*/
88+ while (rlen>=8) {
89+ if (off_set==0) { /* SOL */
90+ if (rlen<8) {br=1; break;}
91+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("PNG identifier\n");}
92+ if (!(*(ifoff+0)==0x89 && *(ifoff+1)==0x50 && *(ifoff+2)==0x4e && *(ifoff+3)==0x47 &&
93+ *(ifoff+4)==0x0d && *(ifoff+5)==0x0a && *(ifoff+6)==0x1a && *(ifoff+7)==0x0a)) {
94+ pinfo->fm = 1;
95+ br=1; break;
96+ }
97+ size = 8;
98+ } else {
99+ hl = ((off_t)*(ifoff+0)<<24)|((off_t)*(ifoff+1)<<16)|((off_t)*(ifoff+2)<<8)|((off_t)*(ifoff+3));
100+ /*printf ("size: 0x%8X, %u\n", hl, hl);*/
101+ if (rlen<(hl+12)) {if ((hl+12)>masize) {br=1; pinfo->fm = 2;}break;}
102+ size = (off_t) (hl+12);
103+ /***** crc check *****/
104+ crc = crc_chk = 0;
105+ crc = ((unsigned int)*(ifoff+hl+8)<<24)|((unsigned int)*(ifoff+hl+9)<<16)|((unsigned int)*(ifoff+hl+10)<<8)|((unsigned int)*(ifoff+hl+11));
106+ crc_chk = crc; /* crc code */
107+ /*printf ("crc: 0x%8X\n", crc);*/
108+ if ((crc^crc_chk)!=0) {br=1; pinfo->fm = 1; break;}
109+
110+ if (*(ifoff+4)=='I' && *(ifoff+5)=='H' && *(ifoff+6)=='D' && *(ifoff+7)=='R') {png_chk_ihdl (pinfo, (ifoff+8), hl);}
111+ }
112+ /*if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("size: 0x%4X%\n", size);}*/
113+
114+ if (pinfo->img_x!=0 && pinfo->img_y!=0) {br=1; break;}
115+ rlen -= size; ifoff += size; off_set += size;
116+ }
117+ if (br) {break;}
118+
119+
120+ /*-Get packet info from read data End---------------------------*/
121+ for (i=0; i<rlen; i++) {*(ifpot+i) = *(ifoff+i);}
122+ ifoff = ifpot + rlen;
123+ }
124+ if (pinfo->img_x==0 || pinfo->img_y==0) {pinfo->fm = 1;}
125+ /*-Get packet info from input file and dividing flow End----------*/
126+ free (ifpot);
127+
128+ return ;
129+}
130+
--- branch/rempic-0.1/gif_chk.c (nonexistent)
+++ branch/rempic-0.1/gif_chk.c (revision 1)
@@ -0,0 +1,94 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+/*//========================================================================\\*
44+ *|| GIF check ||*
45+ *\\========================================================================//*/
46+/*******************************************************************************
47+ * gif check(gif) *************************************************************/
48+void gif_chk (int fd, picInfo *pinfo)
49+{
50+ unsigned int masize;
51+ unsigned char *ifpot, *ifoff, br;
52+ off_t rlen, off_set;
53+ int i, rrtn;
54+
55+ pinfo->fm = 0;
56+ /*******************************************************************
57+ * Get File size and allocate memory ******************************/
58+ masize = MIN((unsigned int)pinfo->fsize, (unsigned int)MAXMALLOCSIZE);
59+
60+ if (masize<=20) {pinfo->fm = 1; return ;}
61+ if ((ifpot=(unsigned char *)malloc_init (masize))==NULL) {return ;}
62+ ifoff = ifpot;
63+ br = rlen = off_set = 0;
64+
65+
66+ /*-Get packet info from input file and dividing flow Start--------*/
67+ while ((rrtn=read (fd, ifoff, (masize-rlen)))>=0) {
68+ rlen = (off_t)rrtn + rlen;
69+ if (rlen<0) {free (ifpot); return;}
70+ ifoff = ifpot;
71+ if (off_set==0 && rlen==0) {pinfo->fm = 1; br=1; break;}
72+
73+ /*-Get packet info from read data Start-------------------------*/
74+ if (off_set==0) { /* Signature Check */
75+ if (!(*(ifoff+0)==0x47 && *(ifoff+1)==0x49 && *(ifoff+2)==0x46)) {pinfo->fm = 1; return ;}
76+ else if (!((*(ifoff+3)==0x38 && *(ifoff+4)==0x37 && *(ifoff+5)==0x61) ||
77+ (*(ifoff+3)==0x38 && *(ifoff+4)==0x39 && *(ifoff+5)==0x61))) {pinfo->fm = 1; return ;}
78+ pinfo->img_x = (unsigned int)(*(ifoff+7))<<8|(unsigned int)(*(ifoff+6));
79+ pinfo->img_y = (unsigned int)(*(ifoff+9))<<8|(unsigned int)(*(ifoff+8));
80+ if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("img_x: %ld, img_y: %ld\n", pinfo->img_x, pinfo->img_y);}
81+ break;
82+ }
83+
84+ /*-Get packet info from read data End---------------------------*/
85+ for (i=0; i<rlen; i++) {*(ifpot+i) = *(ifoff+i);}
86+ ifoff = ifpot + rlen;
87+ }
88+ if (pinfo->img_x==0 || pinfo->img_y==0) {pinfo->fm = 1;}
89+ /*-Get packet info from input file and dividing flow End----------*/
90+ free (ifpot);
91+
92+ return ;
93+}
94+
--- branch/rempic-0.1/Makefile (nonexistent)
+++ branch/rempic-0.1/Makefile (revision 1)
@@ -0,0 +1,60 @@
1+#
2+# The MIT License (MIT)
3+#
4+# Copyright (c) 2014 Yuki SAKAI
5+#
6+# Permission is hereby granted, free of charge, to any person obtaining a copy
7+# of this software and associated documentation files (the "Software"), to deal
8+# in the Software without restriction, including without limitation the rights
9+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+# copies of the Software, and to permit persons to whom the Software is
11+# furnished to do so, subject to the following conditions:
12+#
13+# The above copyright notice and this permission notice shall be included in
14+# all copies or substantial portions of the Software.
15+#
16+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+# THE SOFTWARE.
23+################################################################################
24+
25+################################################################################
26+RMFILE = *~ *.core
27+RMFILE +=
28+################################################################################
29+PROG = rempic
30+INSTDIR =
31+################################################################################
32+RMOBJ = rempic.o usage.o option.o stdlib.o open_dir.o remove.o
33+RMOBJ += file_chk.o jpg_chk.o png_chk.o gif_chk.o
34+RMOBJ +=
35+OBJECT = rempic.h macro.h
36+OBJECT += $(RMOBJ)
37+################################################################################
38+# -DDEBUG
39+DMACRO =
40+DOPT = $(DMACRO)
41+DOPT +=
42+LINK =
43+LIB = -L./
44+INCLUDE = -I./
45+CFLAGS = -O2 -Wall $(OPT) $(INCLUDE) $(LIB) $(DOPT)
46+RM = rm -f
47+
48+
49+all: $(PROG)
50+
51+rempic: $(OBJECT)
52+
53+$(PROG): $(OBJECT)
54+ $(CC) $(CFLAGS) -o $@ $(RMOBJ) $(LINK)
55+
56+.c.o:
57+
58+clean:
59+ $(RM) $(PROG) $(RMOBJ) $(RMFILE)
60+
--- branch/rempic-0.1/remove.c (nonexistent)
+++ branch/rempic-0.1/remove.c (revision 1)
@@ -0,0 +1,220 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
37+# include <unistd.h>
38+#endif
39+#if !defined(_ERRNO_H_) && !defined(_ERRNO_H)
40+# include <errno.h>
41+#endif
42+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
43+# include <sys/types.h>
44+#endif
45+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
46+# include <sys/stat.h>
47+#endif
48+#if !defined(_SYS_FILE_H_) && !defined(_SYS_FILE_H)
49+# include <sys/file.h>
50+#endif
51+#if !defined(_FCNTL_H_) && !defined(_FCNTL_H)
52+# include <fcntl.h>
53+#endif
54+
55+
56+/*******************************************************************************
57+ * read file ******************************************************************/
58+static int read_file (unsigned char *path, picInfo *pinfo)
59+{
60+ int fd;
61+
62+ if ((fd=open ((char *)path, O_RDONLY))==-1) {return 0;}
63+ else if (flock (fd, LOCK_SH)==-1) {close (fd); return 0;}
64+
65+ if (FLGCHK(pinfo->ft, GEXTJPG)) {jpeg_chk (fd, pinfo);}
66+ else if (FLGCHK(pinfo->ft, GEXTJPEG)) {jpeg_chk (fd, pinfo);}
67+ else if (FLGCHK(pinfo->ft, GEXTPNG)) {png_chk (fd, pinfo); }
68+ else if (FLGCHK(pinfo->ft, GEXTGIF)) {gif_chk (fd, pinfo); }
69+
70+ flock (fd, LOCK_UN);
71+ close (fd);
72+
73+ return 1;
74+}
75+
76+/*******************************************************************************
77+ * file extension chk *********************************************************/
78+static unsigned int file_extchk (unsigned char *path)
79+{
80+ unsigned char *pext;
81+ unsigned char ext[10];
82+ (void) memset ((char *)ext, 0, 10);
83+
84+ for (pext = path + strlen ((char *)path) - 1; pext!=path; pext--) {
85+ if (*pext=='.') {break;}
86+ }
87+ if (*pext!='.') {return GEXTERROR;}
88+ else if (strlen ((char *)(pext+1))>9) {return GEXTERROR;}
89+ strncpy ((char *)ext, (char *)(pext+1), 10);
90+ return ext_chk (ext);
91+}
92+
93+/*******************************************************************************
94+ * file size check ************************************************************/
95+static int fsize_chk (off_t size)
96+{
97+ if (FLGCHK(flags, FLGRMUPPERSIZE) && FLGCHK(flags, FLGRMLOWERSIZE)) {
98+ if (UpperSize<=LowerSize) {
99+ if (UpperSize>=size) {return RMCHKREMOVE;}
100+ else if (LowerSize<=size) {return RMCHKREMOVE;}
101+ } else {
102+ if (UpperSize>=size && LowerSize<=size) {return RMCHKREMOVE;}
103+ }
104+ } else if (FLGCHK(flags, FLGRMUPPERSIZE)) {
105+ if (UpperSize>=size) {return RMCHKREMOVE;}
106+ } else if (FLGCHK(flags, FLGRMLOWERSIZE)) {
107+ if (LowerSize<=size) {return RMCHKREMOVE;}
108+ }
109+
110+ return RMCHKINIT;
111+}
112+
113+/*******************************************************************************
114+ * file X check ***************************************************************/
115+static int fx_chk (unsigned long img_x)
116+{
117+ if (FLGCHK(flags, FLGRMUPPERX) && FLGCHK(flags, FLGRMLOWERX)) {
118+ if (UpperX<=LowerX) {
119+ if (UpperX>=img_x) {return RMCHKREMOVE;}
120+ else if (LowerX<=img_x) {return RMCHKREMOVE;}
121+ } else {
122+ if (UpperX>=img_x && LowerX<=img_x) {return RMCHKREMOVE;}
123+ }
124+ } else if (FLGCHK(flags, FLGRMUPPERX)) {
125+ if (UpperX>=img_x) {return RMCHKREMOVE;}
126+ } else if (FLGCHK(flags, FLGRMLOWERX)) {
127+ if (LowerX<=img_x) {return RMCHKREMOVE;}
128+ }
129+
130+ return RMCHKINIT;
131+}
132+
133+/*******************************************************************************
134+ * file Y check ***************************************************************/
135+static int fy_chk (unsigned long img_y)
136+{
137+ if (FLGCHK(flags, FLGRMUPPERY) && FLGCHK(flags, FLGRMLOWERY)) {
138+ if (UpperY<=LowerY) {
139+ if (UpperY>=img_y) {return RMCHKREMOVE;}
140+ else if (LowerY<=img_y) {return RMCHKREMOVE;}
141+ } else {
142+ if (UpperY>=img_y && LowerY<=img_y) {return RMCHKREMOVE;}
143+ }
144+ } else if (FLGCHK(flags, FLGRMUPPERY)) {
145+ if (UpperY>=img_y) {return RMCHKREMOVE;}
146+ } else if (FLGCHK(flags, FLGRMLOWERY)) {
147+ if (LowerY<=img_y) {return RMCHKREMOVE;}
148+ }
149+
150+ return RMCHKINIT;
151+}
152+
153+/*******************************************************************************
154+ * Remove check ***************************************************************/
155+int remove_chk (spname finfo)
156+{
157+ /*****************************************************************************
158+ * if determine remove process(chk!=0), jump remove process ******************
159+ ****************************************************************************/
160+ unsigned int ft;
161+ int chk;
162+ picInfo pinfo;
163+
164+ chk = RMCHKINIT;
165+ ft = GEXTERROR;
166+ (void) memset ((char *)&pinfo, 0, sizeof (picInfo));
167+ pinfo.fsize = finfo.sb.st_size;
168+ /*****************************************************************************
169+ * Analyse filepath name extension ******************************************/
170+ if ((pinfo.ft=file_extchk (finfo.path))==GEXTERROR) {chk = RMCHKSAVE; goto rm_proc;}
171+ else if ((pinfo.ft&TargetFileType)==0) {chk = RMCHKSAVE; goto rm_proc;}
172+ /*****************************************************************************
173+ * File if check ************************************************************/
174+ if ((chk=fsize_chk (pinfo.fsize))!=RMCHKINIT) {goto rm_proc;} /* file size */
175+ else if (!read_file (finfo.path, &pinfo)) {return 0;} /* read file i*/
176+ else if (pinfo.fm) {
177+ if (pinfo.fm==2) {chk = RMCHKSAVE; }
178+ else if (FLGCHK(flags, FLGRMPICBADFILE)) {chk = RMCHKREMOVE;}
179+ else {chk = RMCHKSAVE; }
180+ goto rm_proc;
181+ }
182+ else if (FLGCHK(flags, FLGRMPICBADFILE) && pinfo.fm) {chk = RMCHKSAVE; goto rm_proc;}
183+ else if ((chk=fx_chk (pinfo.img_x))!=RMCHKINIT) {goto rm_proc;} /* file size */
184+ else if ((chk=fy_chk (pinfo.img_y))!=RMCHKINIT) {goto rm_proc;} /* file size */
185+
186+ chk = RMCHKSAVE;
187+ /*****************************************************************************
188+ * Remove Process ***********************************************************/
189+ rm_proc:
190+ if (FLGCHK(flags, FLGDEBUGMODE)) {
191+ /* not remove */
192+ if (chk==RMCHKREMOVE) {fprintf (debugout, "remove: %s\n" , finfo.path);}
193+ else if (chk==RMCHKSAVE) {fprintf (debugout, "save: %s\n" , finfo.path);}
194+ else {fprintf (debugout, "no check: %s\n", finfo.path);}
195+ } else {
196+ if (chk==RMCHKREMOVE && 1) {
197+ errno = 0;
198+ if (unlink ((char *)finfo.path)<0) {
199+ switch (errno) {
200+ case ENOTDIR : fprintf (patherr, "%s: path is include not directory and file name\n", finfo.path); break;
201+ case ENAMETOOLONG: fprintf (patherr, "%s: path name is long\n" , finfo.path); break;
202+ case ENOENT : fprintf (patherr, "%s: no such file\n" , finfo.path); break;
203+ case EACCES : fprintf (patherr, "%s: Can't access\n" , finfo.path); break;
204+ case ELOOP : fprintf (patherr, "%s: Many symbolic link\n" , finfo.path); break;
205+ case EPERM : fprintf (patherr, "%s: Don't permit remove\n" , finfo.path); break;
206+ case EBUSY : fprintf (patherr, "%s: Can't remove for file is busy\n" , finfo.path); break;
207+ case EIO : fprintf (patherr, "%s: I/O error\n" , finfo.path); break;
208+ case EROFS : fprintf (patherr, "%s: file is read only\n" , finfo.path); break;
209+ case EFAULT : fprintf (patherr, "%s: Pointer error\n" , finfo.path); break;
210+ }
211+ fprintf (stdout, "can't rm: %s\n" , finfo.path);
212+ } else {fprintf (stdout, "remove: %s\n" , finfo.path);}
213+ } else {fprintf (stdout, "save : %s\n" , finfo.path);}
214+ }
215+ return 1;
216+}
217+
218+
219+
220+
--- branch/rempic-0.1/open_dir.c (nonexistent)
+++ branch/rempic-0.1/open_dir.c (revision 1)
@@ -0,0 +1,141 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
37+# include <sys/types.h>
38+#endif
39+#if !defined(_DIRENT_H_) && !defined(_DIRENT_H)
40+# include <dirent.h>
41+#endif
42+#if !defined(_ERRNO_H_) && !defined(_ERRNO_H)
43+# include <errno.h>
44+#endif
45+
46+
47+/*******************************************************************************
48+ * Open directory *************************************************************/
49+int open_dir (spname *pspn)
50+{
51+ struct dirent entry, *result;
52+ DIR *dfd;
53+ int i;
54+
55+ if (pspn->ft!=SPFTDIR) {return PPRABORT;}
56+
57+ errno = 0;
58+ if ((dfd=opendir ((char *)pspn->path))==NULL) {
59+ switch (errno) {
60+ case EACCES : fprintf (patherr, "%s: Can't access this directory\n", pspn->path); break;
61+ case EMFILE : fprintf (patherr, "%s: Can't open file descriptor\n" , pspn->path); break;
62+ case ENFILE : fprintf (patherr, "%s: Many file is open\n" , pspn->path); break;
63+ case ENOENT : fprintf (patherr, "%s: No such file or directory\n" , pspn->path); break;
64+ case ENOMEM : fprintf (patherr, "%s: Empty memory\n" , pspn->path); break;
65+ case ENOTDIR: fprintf (patherr, "%s: Path is not directory\n" , pspn->path); break;
66+ }
67+ return PPRALLKILL;
68+ if (errno==ENOMEM) {
69+ return PPRALLKILL;
70+ }
71+ return PPRABORT;
72+ }
73+
74+ /*****************************************************************************
75+ * path Count in directory **************************************************/
76+ pspn->fnum = 0;
77+ while (1) {
78+ errno = 0;
79+ if (readdir_r (dfd, &entry, &result)!=0) {
80+ switch (errno) {
81+ case EBADF : fprintf (patherr, "%s: Can't read dir\n" , pspn->path); break;
82+ case ENOENT: fprintf (patherr, "%s: Don't open dir\n" , pspn->path); break;
83+ case EFAULT: fprintf (patherr, "%s: Open dir failed\n", pspn->path); break;
84+ }
85+ closedir (dfd);
86+ return PPRABORT;
87+ } else if (result==NULL) {break;}
88+
89+ if (result->d_name[strlen (result->d_name)-1]=='/') {result->d_name[strlen (result->d_name)-1] = 0;}
90+
91+ if (strcmp (result->d_name, "." )==0) {continue;}
92+ else if (strcmp (result->d_name, "..")==0) {continue;}
93+
94+ if (result->d_name[0]=='.' && !FLGCHK(flags, FLGALLFILES)) {continue;}
95+ pspn->fnum++;
96+ }
97+
98+ /*****************************************************************************
99+ * Get path name init *******************************************************/
100+ if (pspn->fnum==0) {pspn->farray = NULL; return PPRABORT;}
101+ else if ((pspn->farray=malloc_init ((sizeof (spname)*pspn->fnum)))==NULL) {
102+ fprintf (stderr, "Memory allocate error for path name\n");
103+ return PPRALLKILL;
104+ }
105+ rewinddir (dfd);
106+ i = 0;
107+
108+ /*****************************************************************************
109+ * Get path name ************************************************************/
110+ while (1) {
111+ errno = 0;
112+ if (readdir_r (dfd, &entry, &result)!=0) {
113+ switch (errno) {
114+ case EBADF : fprintf (patherr, "%s: Can't read dir\n" , pspn->path); break;
115+ case ENOENT: fprintf (patherr, "%s: Don't open dir\n" , pspn->path); break;
116+ case EFAULT: fprintf (patherr, "%s: Open dir failed\n", pspn->path); break;
117+ }
118+ closedir (dfd);
119+ return PPRABORT;
120+ } else if (result==NULL) {
121+
122+ break;}
123+
124+ if (result->d_name[strlen (result->d_name)-1]=='/') {result->d_name[strlen (result->d_name)-1] = 0;}
125+
126+ if (strcmp (result->d_name, "." )==0) {continue;} /* skip "." path */
127+ else if (strcmp (result->d_name, "..")==0) {continue;} /* skip ".." path */
128+ if (result->d_name[0]=='.' && !FLGCHK(flags, FLGALLFILES)) {continue;} /* skip? ".hogehoge" path */
129+
130+ snprintf ((char *)pspn->farray[i].path, MAXPATHLEN-1, "%s/%s", pspn->path, result->d_name);
131+ i++;
132+ }
133+
134+ closedir (dfd);
135+ return 1;
136+}
137+
138+
139+
140+
141+
--- branch/rempic-0.1/rempic.c (nonexistent)
+++ branch/rempic-0.1/rempic.c (revision 1)
@@ -0,0 +1,114 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
31+# include <sys/stat.h>
32+#endif
33+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
34+# include <stdio.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_ERRNO_H_) && !defined(_ERRNO_H)
40+# include <errno.h>
41+#endif
42+
43+
44+
45+/*******************************************************************************
46+ * Path processing ************************************************************/
47+int path_proc (spname *pArray, unsigned int FileNum)
48+{
49+ int i;
50+ int rtn;
51+
52+ if (pArray==NULL) {fprintf (patherr, "no path\n"); return PPRABORT;}
53+ else if (FileNum==0 ) {fprintf (patherr, "no path\n"); return PPRABORT;}
54+
55+ for (i=0; i<FileNum; i++) {
56+ /***************************************************************************
57+ * Get Path info **********************************************************/
58+ errno = 0;
59+ if (lstat ((char *)pArray[i].path, &(pArray[i].sb))<0) {
60+ switch (errno) {
61+ case EACCES : fprintf (patherr, "%s: Can't access this path\n" , pArray[i].path); break;
62+ case ELOOP : fprintf (patherr, "%s: Symbolic link is many\n" , pArray[i].path); break;
63+ case ENAMETOOLONG: fprintf (patherr, "%s: Path name is long\n" , pArray[i].path); break;
64+ case ENOENT : fprintf (patherr, "%s: No such file or directory\n" , pArray[i].path); break;
65+ case ENOMEM : fprintf (patherr, "%s: Empty memory\n" , pArray[i].path); goto stop_err; break;
66+ case ENOTDIR : fprintf (patherr, "%s: Path is not directory or file\n", pArray[i].path); break;
67+ }
68+ continue;
69+ }
70+ if (S_ISREG(pArray[i].sb.st_mode)) {pArray[i].ft = SPFTFILE; }
71+ else if (S_ISDIR(pArray[i].sb.st_mode)) {pArray[i].ft = SPFTDIR; }
72+ else {pArray[i].ft = SPFTOTHERS;}
73+
74+ /***************************************************************************
75+ * Path processing ********************************************************/
76+ if (pArray[i].ft==SPFTFILE) {
77+ /* remove check and remove process */
78+ remove_chk (pArray[i]);
79+ } else if (pArray[i].ft==SPFTDIR) {
80+ /*=Directory read check=================================================*/
81+ if (FLGCHK(flags, FLGRECURSIVE)) {
82+ rtn = open_dir (&pArray[i]);
83+ if (rtn==PPRABORT) {}
84+ else if (rtn==PPRALLKILL) {goto stop_err;}
85+ else {
86+ rtn = path_proc (pArray[i].farray, pArray[i].fnum);
87+ free (pArray[i].farray);
88+ if (rtn==PPRALLKILL) {goto stop_err;}
89+ }
90+ }
91+ }
92+ }
93+
94+ return 1;
95+
96+ stop_err:
97+ return 0;
98+}
99+
100+
101+/*******************************************************************************
102+ * Main processing ************************************************************/
103+int main (int argc, char **argv)
104+{
105+ /**Option Processing Block***************************************************/
106+ if (opt_proc (argc, argv)<0) {goto non_proc_err;}
107+ else if (path_proc (patharray, FirstPathNum)<0) {goto non_proc_err;}
108+ free (patharray);
109+
110+ return 0;
111+
112+ non_proc_err:
113+ return 1;
114+}
--- branch/rempic-0.1/stdlib.c (nonexistent)
+++ branch/rempic-0.1/stdlib.c (revision 1)
@@ -0,0 +1,44 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H_)
31+# include <stdlib.h>
32+#endif
33+
34+/*******************************************************************************
35+ * memAllocate ****************************************************************/
36+void * malloc_init (size_t size)
37+{
38+ void *pt, *pp;
39+ size_t i;
40+ if ((pt=malloc (size))==NULL) {return NULL;}
41+ for (pp=pt,i=0; i<size; i++,pp++) {*(unsigned char *)pp = 0;}
42+ return pt;
43+}
44+
--- release/rempic-0.1/open_dir.c (nonexistent)
+++ release/rempic-0.1/open_dir.c (revision 1)
@@ -0,0 +1,141 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
37+# include <sys/types.h>
38+#endif
39+#if !defined(_DIRENT_H_) && !defined(_DIRENT_H)
40+# include <dirent.h>
41+#endif
42+#if !defined(_ERRNO_H_) && !defined(_ERRNO_H)
43+# include <errno.h>
44+#endif
45+
46+
47+/*******************************************************************************
48+ * Open directory *************************************************************/
49+int open_dir (spname *pspn)
50+{
51+ struct dirent entry, *result;
52+ DIR *dfd;
53+ int i;
54+
55+ if (pspn->ft!=SPFTDIR) {return PPRABORT;}
56+
57+ errno = 0;
58+ if ((dfd=opendir ((char *)pspn->path))==NULL) {
59+ switch (errno) {
60+ case EACCES : fprintf (patherr, "%s: Can't access this directory\n", pspn->path); break;
61+ case EMFILE : fprintf (patherr, "%s: Can't open file descriptor\n" , pspn->path); break;
62+ case ENFILE : fprintf (patherr, "%s: Many file is open\n" , pspn->path); break;
63+ case ENOENT : fprintf (patherr, "%s: No such file or directory\n" , pspn->path); break;
64+ case ENOMEM : fprintf (patherr, "%s: Empty memory\n" , pspn->path); break;
65+ case ENOTDIR: fprintf (patherr, "%s: Path is not directory\n" , pspn->path); break;
66+ }
67+ return PPRALLKILL;
68+ if (errno==ENOMEM) {
69+ return PPRALLKILL;
70+ }
71+ return PPRABORT;
72+ }
73+
74+ /*****************************************************************************
75+ * path Count in directory **************************************************/
76+ pspn->fnum = 0;
77+ while (1) {
78+ errno = 0;
79+ if (readdir_r (dfd, &entry, &result)!=0) {
80+ switch (errno) {
81+ case EBADF : fprintf (patherr, "%s: Can't read dir\n" , pspn->path); break;
82+ case ENOENT: fprintf (patherr, "%s: Don't open dir\n" , pspn->path); break;
83+ case EFAULT: fprintf (patherr, "%s: Open dir failed\n", pspn->path); break;
84+ }
85+ closedir (dfd);
86+ return PPRABORT;
87+ } else if (result==NULL) {break;}
88+
89+ if (result->d_name[strlen (result->d_name)-1]=='/') {result->d_name[strlen (result->d_name)-1] = 0;}
90+
91+ if (strcmp (result->d_name, "." )==0) {continue;}
92+ else if (strcmp (result->d_name, "..")==0) {continue;}
93+
94+ if (result->d_name[0]=='.' && !FLGCHK(flags, FLGALLFILES)) {continue;}
95+ pspn->fnum++;
96+ }
97+
98+ /*****************************************************************************
99+ * Get path name init *******************************************************/
100+ if (pspn->fnum==0) {pspn->farray = NULL; return PPRABORT;}
101+ else if ((pspn->farray=malloc_init ((sizeof (spname)*pspn->fnum)))==NULL) {
102+ fprintf (stderr, "Memory allocate error for path name\n");
103+ return PPRALLKILL;
104+ }
105+ rewinddir (dfd);
106+ i = 0;
107+
108+ /*****************************************************************************
109+ * Get path name ************************************************************/
110+ while (1) {
111+ errno = 0;
112+ if (readdir_r (dfd, &entry, &result)!=0) {
113+ switch (errno) {
114+ case EBADF : fprintf (patherr, "%s: Can't read dir\n" , pspn->path); break;
115+ case ENOENT: fprintf (patherr, "%s: Don't open dir\n" , pspn->path); break;
116+ case EFAULT: fprintf (patherr, "%s: Open dir failed\n", pspn->path); break;
117+ }
118+ closedir (dfd);
119+ return PPRABORT;
120+ } else if (result==NULL) {
121+
122+ break;}
123+
124+ if (result->d_name[strlen (result->d_name)-1]=='/') {result->d_name[strlen (result->d_name)-1] = 0;}
125+
126+ if (strcmp (result->d_name, "." )==0) {continue;} /* skip "." path */
127+ else if (strcmp (result->d_name, "..")==0) {continue;} /* skip ".." path */
128+ if (result->d_name[0]=='.' && !FLGCHK(flags, FLGALLFILES)) {continue;} /* skip? ".hogehoge" path */
129+
130+ snprintf ((char *)pspn->farray[i].path, MAXPATHLEN-1, "%s/%s", pspn->path, result->d_name);
131+ i++;
132+ }
133+
134+ closedir (dfd);
135+ return 1;
136+}
137+
138+
139+
140+
141+
--- release/rempic-0.1/rempic.c (nonexistent)
+++ release/rempic-0.1/rempic.c (revision 1)
@@ -0,0 +1,114 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
31+# include <sys/stat.h>
32+#endif
33+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
34+# include <stdio.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_ERRNO_H_) && !defined(_ERRNO_H)
40+# include <errno.h>
41+#endif
42+
43+
44+
45+/*******************************************************************************
46+ * Path processing ************************************************************/
47+int path_proc (spname *pArray, unsigned int FileNum)
48+{
49+ int i;
50+ int rtn;
51+
52+ if (pArray==NULL) {fprintf (patherr, "no path\n"); return PPRABORT;}
53+ else if (FileNum==0 ) {fprintf (patherr, "no path\n"); return PPRABORT;}
54+
55+ for (i=0; i<FileNum; i++) {
56+ /***************************************************************************
57+ * Get Path info **********************************************************/
58+ errno = 0;
59+ if (lstat ((char *)pArray[i].path, &(pArray[i].sb))<0) {
60+ switch (errno) {
61+ case EACCES : fprintf (patherr, "%s: Can't access this path\n" , pArray[i].path); break;
62+ case ELOOP : fprintf (patherr, "%s: Symbolic link is many\n" , pArray[i].path); break;
63+ case ENAMETOOLONG: fprintf (patherr, "%s: Path name is long\n" , pArray[i].path); break;
64+ case ENOENT : fprintf (patherr, "%s: No such file or directory\n" , pArray[i].path); break;
65+ case ENOMEM : fprintf (patherr, "%s: Empty memory\n" , pArray[i].path); goto stop_err; break;
66+ case ENOTDIR : fprintf (patherr, "%s: Path is not directory or file\n", pArray[i].path); break;
67+ }
68+ continue;
69+ }
70+ if (S_ISREG(pArray[i].sb.st_mode)) {pArray[i].ft = SPFTFILE; }
71+ else if (S_ISDIR(pArray[i].sb.st_mode)) {pArray[i].ft = SPFTDIR; }
72+ else {pArray[i].ft = SPFTOTHERS;}
73+
74+ /***************************************************************************
75+ * Path processing ********************************************************/
76+ if (pArray[i].ft==SPFTFILE) {
77+ /* remove check and remove process */
78+ remove_chk (pArray[i]);
79+ } else if (pArray[i].ft==SPFTDIR) {
80+ /*=Directory read check=================================================*/
81+ if (FLGCHK(flags, FLGRECURSIVE)) {
82+ rtn = open_dir (&pArray[i]);
83+ if (rtn==PPRABORT) {}
84+ else if (rtn==PPRALLKILL) {goto stop_err;}
85+ else {
86+ rtn = path_proc (pArray[i].farray, pArray[i].fnum);
87+ free (pArray[i].farray);
88+ if (rtn==PPRALLKILL) {goto stop_err;}
89+ }
90+ }
91+ }
92+ }
93+
94+ return 1;
95+
96+ stop_err:
97+ return 0;
98+}
99+
100+
101+/*******************************************************************************
102+ * Main processing ************************************************************/
103+int main (int argc, char **argv)
104+{
105+ /**Option Processing Block***************************************************/
106+ if (opt_proc (argc, argv)<0) {goto non_proc_err;}
107+ else if (path_proc (patharray, FirstPathNum)<0) {goto non_proc_err;}
108+ free (patharray);
109+
110+ return 0;
111+
112+ non_proc_err:
113+ return 1;
114+}
--- release/rempic-0.1/stdlib.c (nonexistent)
+++ release/rempic-0.1/stdlib.c (revision 1)
@@ -0,0 +1,44 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H_)
31+# include <stdlib.h>
32+#endif
33+
34+/*******************************************************************************
35+ * memAllocate ****************************************************************/
36+void * malloc_init (size_t size)
37+{
38+ void *pt, *pp;
39+ size_t i;
40+ if ((pt=malloc (size))==NULL) {return NULL;}
41+ for (pp=pt,i=0; i<size; i++,pp++) {*(unsigned char *)pp = 0;}
42+ return pt;
43+}
44+
--- release/rempic-0.1/file_chk.c (nonexistent)
+++ release/rempic-0.1/file_chk.c (revision 1)
@@ -0,0 +1,57 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+
44+/*******************************************************************************
45+ * Extension check ************************************************************/
46+unsigned int ext_chk (unsigned char *ext)
47+{
48+ if (strcmp ((char *)ext, "jpg" )==0) {return GEXTJPG; }
49+ else if (strcmp ((char *)ext, "JPG" )==0) {return GEXTJPG; }
50+ else if (strcmp ((char *)ext, "jpeg")==0) {return GEXTJPEG;}
51+ else if (strcmp ((char *)ext, "png" )==0) {return GEXTPNG; }
52+ else if (strcmp ((char *)ext, "PNG" )==0) {return GEXTPNG; }
53+ else if (strcmp ((char *)ext, "gif" )==0) {return GEXTGIF; }
54+ else if (strcmp ((char *)ext, "GIF" )==0) {return GEXTGIF; }
55+
56+ return GEXTNOGRAPHIC;
57+}
--- release/rempic-0.1/rempic.h (nonexistent)
+++ release/rempic-0.1/rempic.h (revision 1)
@@ -0,0 +1,149 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+#ifndef REMPIC_H__
26+#define REMPIC_H__ __DATE__
27+
28+/*******************************************************************************
29+ * Include ********************************************************************/
30+#if !defined(MACRO_H_)
31+# include <macro.h>
32+#endif
33+#if !defined(_SYS_PARAM_H_) && !defined(_SYS_PARAM_H)
34+# include <sys/param.h>
35+#endif
36+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
37+# include <stdio.h>
38+#endif
39+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
40+# include <sys/stat.h>
41+#endif
42+
43+
44+/*******************************************************************************
45+ * Define *********************************************************************/
46+/*=Program state==============================================================*/
47+#define VERSION "1.0.0" /* Program version */
48+/*=Option Flags===============================================================*/
49+#define FLGALL 0x000003ff /* All flags bits */
50+#define FLGDEBUGMODE 0x00000001 /* Debug Mode ON (-D) */
51+#define FLGRECURSIVE 0x00000002 /* Directory Recursive ON (-r)*/
52+#define FLGRMPICBADFILE 0x00000004 /* rm picture badfile (-b) */
53+#define FLGALLFILES 0x00000008 /* target is ALL files (-a) */
54+#define FLGRMUPPERSIZE 0x00000010 /* rm upper picture bytes (-S)*/
55+#define FLGRMLOWERSIZE 0x00000020 /* rm lower picture bytes (-s)*/
56+#define FLGRMUPPERX 0x00000040 /* rm upper picture x (-X) */
57+#define FLGRMLOWERX 0x00000080 /* rm lower picture x (-x) */
58+#define FLGRMUPPERY 0x00000100 /* rm upper picture y (-Y) */
59+#define FLGRMLOWERY 0x00000200 /* rm lower picture y (-y) */
60+/*=Path Process Return========================================================*/
61+#define PPRALLKILL -1
62+#define PPRABORT -2
63+/*=Remove check===============================================================*/
64+#define RMCHKINIT 0
65+#define RMCHKREMOVE 1
66+#define RMCHKSAVE 2
67+/*=Graphic extension==========================================================*/
68+#define GEXTERROR 0x00000000
69+#define GEXTNOGRAPHIC 0x00000001
70+#define GEXTGRAPHICALL 0x0000001e
71+#define GEXTJPG 0x00000002
72+#define GEXTPNG 0x00000004
73+#define GEXTJPEG 0x00000008
74+#define GEXTGIF 0x00000010
75+/*=Graphic config=============================================================*/
76+#define MAXMALLOCSIZE 0x1fffff /* Max allocate memory size */
77+/*=Graphic config(JPEG)=======================================================*/
78+#define JPGMARKSOL 0x1
79+#define JPGMARKEOL 0x2
80+
81+/*******************************************************************************
82+ * Save Path name *************************************************************/
83+/*=File Type define===========================================================*/
84+#define SPFTINIT 0x00 /* File type init */
85+#define SPFTFILE 0x01 /* File type is normal */
86+#define SPFTDIR 0x02 /* File type is dir */
87+#define SPFTOTHERS 0x03 /* Other file type */
88+#define SPFTUNKNOWN 0x04 /* File type is unknown */
89+/*=structure==================================================================*/
90+typedef struct SAVEPATHNAME {
91+ struct SAVEPATHNAME *farray;
92+ unsigned char ft; /* File Type */
93+ unsigned char path[MAXPATHLEN]; /* path name */
94+ unsigned int fnum; /* This directory have File number */
95+ struct stat sb;
96+} spname;
97+
98+/*******************************************************************************
99+ * Pic info *******************************************************************/
100+typedef struct {
101+ unsigned char fm;
102+ unsigned int ft;
103+ unsigned char perUnit;
104+ off_t fsize;
105+ unsigned long img_x, img_y;
106+} picInfo;
107+
108+
109+/*******************************************************************************
110+ * Global functions ***********************************************************/
111+/*=file_chk===================================================================*/
112+void jpeg_chk (int fd, picInfo *pinfo);
113+unsigned int ext_chk (unsigned char *ext);
114+/*=open_dir===================================================================*/
115+int open_dir (spname *pspn);
116+/*=option.c===================================================================*/
117+int opt_proc (int argc, char **argv);
118+/*=remove.c===================================================================*/
119+int remove_chk (spname finfo);
120+/*=stdlib.c===================================================================*/
121+void * malloc_init (size_t size);
122+/*=usage.c====================================================================*/
123+void usage (void);
124+/*=jpg_chk====================================================================*/
125+void jpeg_chk (int fd, picInfo *pinfo);
126+/*=png_chk====================================================================*/
127+void png_chk (int fd, picInfo *pinfo);
128+/*=gif_chk====================================================================*/
129+void gif_chk (int fd, picInfo *pinfo);
130+
131+/*******************************************************************************
132+ * Global variables ***********************************************************/
133+/*-Program state--------------------------------------------------------------*/
134+char *pname; /* Program name */
135+/*-Option Process-------------------------------------------------------------*/
136+unsigned int flags;
137+spname *patharray;
138+unsigned int FirstPathNum;
139+unsigned int TargetFileType;
140+off_t UpperSize, LowerSize;
141+unsigned int UpperX, LowerX;
142+unsigned int UpperY, LowerY;
143+/*-Error Output---------------------------------------------------------------*/
144+FILE *debugout;
145+FILE *usageout;
146+FILE *patherr;
147+
148+
149+#endif /* REMPIC_H__ */
--- release/rempic-0.1/usage.c (nonexistent)
+++ release/rempic-0.1/usage.c (revision 1)
@@ -0,0 +1,53 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
34+# include <stdlib.h>
35+#endif
36+
37+/*******************************************************************************
38+ * Usage **********************************************************************/
39+void usage (void)
40+{
41+ usageout = stdout;
42+ fprintf (usageout, "%s [-x LowXSize] [-X UpperXSize] [-y LowYSize] [-Y UpperYSize]\n", pname);
43+ fprintf (usageout, "\t[-s UnderSize] [-S OverSize] [-a] [-b] [-r] [-D] targetname....\n");
44+ fprintf (usageout, "\t-x|-X : Target X-Length, LowXSize<TargetXSize, TargetXSize<UpperXSize\n");
45+ fprintf (usageout, "\t-y|-Y : Target Y-Length, LowYSize<TargetYSize, TargetYSize<UpperYSize\n");
46+ fprintf (usageout, "\t-s|-S : Target Size , UnderSize<TargetFileSize, TargetFileSize<OverSize\n");
47+ fprintf (usageout, "\t-a : Include hide file\n");
48+ fprintf (usageout, "\t-b : Remove Bad format file\n");
49+ fprintf (usageout, "\t-r : Recurcive Directory\n");
50+ fprintf (usageout, "\t-D : Debug mode\n");
51+
52+ exit (1);
53+}
--- release/rempic-0.1/jpg_chk.c (nonexistent)
+++ release/rempic-0.1/jpg_chk.c (revision 1)
@@ -0,0 +1,288 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+/*//========================================================================\\*
44+ *|| Jpeg check ||*
45+ *\\========================================================================//*/
46+/*******************************************************************************
47+ * jpeg check APP0 ************************************************************/
48+static int jpeg_chk_app0 (picInfo *pinfo, unsigned char *data, off_t len)
49+{
50+ data+=2; /* skip head length */
51+ if (strncmp ((char *)data, "JFIF", 4)!=0) {goto err_proc;}
52+ else if (*(data+4)!=0x00) {goto err_proc;}
53+ data+=5;
54+ data+=2; /* skip version */
55+ pinfo->perUnit = *data; data+=1; /* unit */
56+
57+ pinfo->fm = 0;
58+ return 1;
59+ err_proc:
60+ pinfo->fm = 1;
61+ return 0;
62+}
63+/*******************************************************************************
64+ * jpeg check SOF0 ************************************************************/
65+static int jpeg_chk_sof0 (picInfo *pinfo, unsigned char *data, off_t len)
66+{
67+ data+=2; /* skip head length */
68+ /*if (*(data+0)!=0x08) {goto err_proc;}*/
69+ data+=1;
70+ pinfo->img_y = ((unsigned short)(*data)<<8) | ((unsigned short)*(data+1)); data+=2;
71+ pinfo->img_x = ((unsigned short)(*data)<<8) | ((unsigned short)*(data+1)); data+=2;
72+ if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("img_x: %ld, img_y: %ld\n", pinfo->img_x, pinfo->img_y);}
73+
74+ pinfo->fm = 0;
75+ return 1;
76+
77+ pinfo->fm = 1;
78+ return 0;
79+}
80+
81+/*******************************************************************************
82+ * jpeg check(jpg,jpeg) *******************************************************/
83+void jpeg_chk (int fd, picInfo *pinfo)
84+{
85+ unsigned int masize;
86+ unsigned char *ifpot, *ifoff, br;
87+ off_t rlen, off_set, size;
88+ int i, rrtn;
89+
90+ pinfo->fm = 0;
91+ /*******************************************************************
92+ * Get File size and allocate memory ******************************/
93+ masize = MIN((unsigned int)pinfo->fsize, (unsigned int)MAXMALLOCSIZE);
94+ if ((ifpot=(unsigned char *)malloc_init (masize))==NULL) {return ;}
95+ ifoff = ifpot;
96+ br = rlen = off_set = 0;
97+
98+
99+ /*-Get packet info from input file and dividing flow Start--------*/
100+ while ((rrtn=read (fd, ifoff, (masize-rlen)))>=0) {
101+ rlen = (off_t)rrtn + rlen;
102+ if (rlen<0) {free (ifpot); return;}
103+ ifoff = ifpot;
104+ if (off_set==0 && rlen==0) {pinfo->fm = 1; br=1; break;}
105+
106+ /*-Get packet info from read data Start-------------------------*/
107+ while (rlen>=2) {
108+ if (off_set==0) { /* SOL */
109+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOL\n");}
110+ if (!(*ifoff==0xff && *(ifoff+1)==0xd8)) {
111+ pinfo->fm = 1;
112+ br=1; break;
113+ }
114+ size = 2;
115+ } else if (*ifoff==0xff && *(ifoff+1)==0xe0) { /* APP0 */
116+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP0\n");}
117+ if (rlen<4) {break;}
118+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
119+ if (rlen<(size+2)) {break;}
120+ else if (!jpeg_chk_app0 (pinfo, ifoff+2, size)) {br=1; break;}
121+ size+=2;
122+ } else if (*ifoff==0xff && *(ifoff+1)==0xdb) { /* DQT */
123+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("DQT\n");}
124+ if (rlen<4) {break;}
125+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
126+ if (rlen<(size+2)) {break;}
127+ size+=2;
128+ } else if (*ifoff==0xff && *(ifoff+1)==0xc4) { /* DHT */
129+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("DHT\n");}
130+ if (rlen<4) {break;}
131+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
132+ if (rlen<(size+2)) {break;}
133+ size+=2;
134+ } else if (*ifoff==0xff && *(ifoff+1)==0xc0) { /* SOF0 */
135+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOF0\n");}
136+ if (rlen<4) {break;}
137+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
138+ if (rlen<(size+2)) {break;}
139+ else if (!jpeg_chk_sof0 (pinfo, ifoff+2, size)) {br=1; break;}
140+ size+=2;
141+ } else if (*ifoff==0xff && *(ifoff+1)==0xc1) { /* SOF1 */
142+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOF1\n");}
143+ if (rlen<4) {break;}
144+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
145+ if (rlen<(size+2)) {break;}
146+ else if (!jpeg_chk_sof0 (pinfo, ifoff+2, size)) {br=1; break;}
147+ size+=2;
148+ } else if (*ifoff==0xff && *(ifoff+1)==0xc2) { /* SOF2 */
149+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOF2\n");}
150+ if (rlen<4) {break;}
151+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
152+ if (rlen<(size+2)) {break;}
153+ else if (!jpeg_chk_sof0 (pinfo, ifoff+2, size)) {br=1; break;}
154+ size+=2;
155+ } else if (*ifoff==0xff && *(ifoff+1)==0xd9) { /* EOL */
156+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("EOL\n");}
157+ if (rlen<4) {break;}
158+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
159+ if (rlen<(size+2)) {break;}
160+ size+=2;
161+ } else if (*ifoff==0xff && *(ifoff+1)==0xe1) { /* APP1 */
162+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP1\n");}
163+ if (rlen<4) {break;}
164+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
165+ if (rlen<(size+2)) {break;}
166+ size+=2;
167+ } else if (*ifoff==0xff && *(ifoff+1)==0xe2) { /* APP2 */
168+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP1\n");}
169+ if (rlen<4) {break;}
170+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
171+ if (rlen<(size+2)) {break;}
172+ size+=2;
173+ } else if (*ifoff==0xff && *(ifoff+1)==0xe3) { /* APP3 */
174+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP3\n");}
175+ if (rlen<4) {break;}
176+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
177+ if (rlen<(size+2)) {break;}
178+ size+=2;
179+ } else if (*ifoff==0xff && *(ifoff+1)==0xe4) { /* APP4 */
180+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP4\n");}
181+ if (rlen<4) {break;}
182+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
183+ if (rlen<(size+2)) {break;}
184+ size+=2;
185+ } else if (*ifoff==0xff && *(ifoff+1)==0xe5) { /* APP5 */
186+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP5\n");}
187+ if (rlen<4) {break;}
188+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
189+ if (rlen<(size+2)) {break;}
190+ size+=2;
191+ } else if (*ifoff==0xff && *(ifoff+1)==0xe6) { /* APP6 */
192+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP6\n");}
193+ if (rlen<4) {break;}
194+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
195+ if (rlen<(size+2)) {break;}
196+ size+=2;
197+ } else if (*ifoff==0xff && *(ifoff+1)==0xe7) { /* APP7 */
198+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP7\n");}
199+ if (rlen<4) {break;}
200+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
201+ if (rlen<(size+2)) {break;}
202+ size+=2;
203+ } else if (*ifoff==0xff && *(ifoff+1)==0xe8) { /* APP8 */
204+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP8\n");}
205+ if (rlen<4) {break;}
206+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
207+ if (rlen<(size+2)) {break;}
208+ size+=2;
209+ } else if (*ifoff==0xff && *(ifoff+1)==0xe9) { /* APP9 */
210+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP9\n");}
211+ if (rlen<4) {break;}
212+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
213+ if (rlen<(size+2)) {break;}
214+ size+=2;
215+ } else if (*ifoff==0xff && *(ifoff+1)==0xea) { /* APPa */
216+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPa\n");}
217+ if (rlen<4) {break;}
218+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
219+ if (rlen<(size+2)) {break;}
220+ size+=2;
221+ } else if (*ifoff==0xff && *(ifoff+1)==0xeb) { /* APPb */
222+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPb\n");}
223+ if (rlen<4) {break;}
224+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
225+ if (rlen<(size+2)) {break;}
226+ size+=2;
227+ } else if (*ifoff==0xff && *(ifoff+1)==0xec) { /* APPc */
228+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPc\n");}
229+ if (rlen<4) {break;}
230+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
231+ if (rlen<(size+2)) {break;}
232+ size+=2;
233+ } else if (*ifoff==0xff && *(ifoff+1)==0xed) { /* APPd */
234+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPd\n");}
235+ if (rlen<4) {break;}
236+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
237+ /*printf ("appd size: 0x%4X\n", size);*/
238+ if (rlen<(size+2)) {break;}
239+ size+=2;
240+ } else if (*ifoff==0xff && *(ifoff+1)==0xee) { /* APPe */
241+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPe\n");}
242+ if (rlen<4) {break;}
243+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
244+ /*printf ("appd size: 0x%4X\n", size);*/
245+ if (rlen<(size+2)) {break;}
246+ size+=2;
247+ } else if (*ifoff==0xff && *(ifoff+1)==0xef) { /* APPf */
248+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPf\n");}
249+ if (rlen<4) {break;}
250+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
251+ /*printf ("appd size: 0x%4X\n", size);*/
252+ if (rlen<(size+2)) {break;}
253+ size+=2;
254+ } else if (*ifoff==0xff && *(ifoff+1)==0xda) { /* SOS */
255+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOS\n");}
256+ if (rlen<4) {break;}
257+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
258+ if (rlen<(size+2)) {break;}
259+ size+=2;
260+ } else if (*ifoff==0xff && *(ifoff+1)==0xfe) { /* comment */
261+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("comment\n");}
262+ if (rlen<4) {break;}
263+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
264+ if (rlen<(size+2)) {break;}
265+ size+=2;
266+ } else {
267+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("else: 0x%2X%2X\n", *ifoff, *(ifoff+1));}
268+ br=1; break;
269+ }
270+ /*if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("size: 0x%4X%\n", size);}*/
271+
272+ if (pinfo->img_x!=0 && pinfo->img_y!=0) {br=1; break;}
273+ rlen -= size; ifoff += size; off_set += size;
274+ }
275+ if (br) {break;}
276+
277+
278+ /*-Get packet info from read data End---------------------------*/
279+ for (i=0; i<rlen; i++) {*(ifpot+i) = *(ifoff+i);}
280+ ifoff = ifpot + rlen;
281+ }
282+ if (pinfo->img_x==0 || pinfo->img_y==0) {pinfo->fm = 1;}
283+ /*-Get packet info from input file and dividing flow End----------*/
284+ free (ifpot);
285+
286+ return ;
287+}
288+
--- release/rempic-0.1/macro.h (nonexistent)
+++ release/rempic-0.1/macro.h (revision 1)
@@ -0,0 +1,36 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+#ifndef MACRO_H__
26+#define MACRO_H__ __DATE__
27+
28+/*******************************************************************************
29+ * Flagment processing ********************************************************/
30+#define FLGINIT(a) (*a=0) /* Flag initialise */
31+#define FLGSET(a,b) (*a|=b) /* Set flag bit */
32+#define FLGCLR(a,b) (*a^=(*a&b)) /* Clear flag bit */
33+#define FLGTGR(a,b) (*a^=b) /* Toggle flag bit */
34+#define FLGCHK(a,b) ((a&b)==b?1:0) /* Check flag bit */
35+
36+#endif /* MACRO_H__ */
--- release/rempic-0.1/option.c (nonexistent)
+++ release/rempic-0.1/option.c (revision 1)
@@ -0,0 +1,126 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_SYS_PARAM_H_) && !defined(_SYS_PARAM_H)
31+# include <sys/param.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+
44+/*******************************************************************************
45+ * Size transfer **************************************************************/
46+static off_t SizeTransfer (char *str)
47+{
48+ char chk;
49+ int rlen, shift;
50+ unsigned int idx, isize;
51+ double dsize;
52+
53+ shift = chk = 0;
54+ rlen = strlen (str);
55+ for (idx=0; idx<rlen; idx++) {
56+ if (idx==(rlen-1)) {
57+ if ('0'<=str[idx] && str[idx]<='9') {}
58+ else if (str[idx]=='k' || str[idx]=='K') {shift=10; str[idx]=0x00;}
59+ else if (str[idx]=='m' || str[idx]=='M') {shift=20; str[idx]=0x00;}
60+ else if (str[idx]=='g' || str[idx]=='G') {shift=30; str[idx]=0x00;}
61+ } else {
62+ if ('0'<=str[idx] && str[idx]<='9') {}
63+ else if (chk==0 && str[idx]=='.') {chk = 1;}
64+ else {return -1;}
65+ }
66+ }
67+ dsize = strtod (str, NULL);
68+ isize = (int)(dsize * (double)(1<<shift));
69+ /*printf ("size: %u\n", isize);*/
70+ return (off_t)isize;
71+}
72+
73+/*******************************************************************************
74+ * Option *********************************************************************/
75+int opt_proc (int argc, char **argv)
76+{
77+ int i;
78+ int ch;
79+
80+ /*****************************************************************************
81+ * Option init **************************************************************/
82+ pname = *argv;
83+ patherr = stdout;
84+ debugout = stdout;
85+ TargetFileType = 0;
86+ UpperSize = LowerSize = 0;
87+
88+ /*****************************************************************************
89+ * Get Option ***************************************************************/
90+ while ((ch = getopt (argc, argv, "abrS:s:X:x:Y:y:Dh?"))>=0) {
91+ switch (ch) {
92+ case 'a': FLGSET(&flags, FLGALLFILES); break;
93+ case 'b': FLGSET(&flags, FLGRMPICBADFILE); break;
94+ case 'r': FLGSET(&flags, FLGRECURSIVE); break;
95+ case 's': FLGSET(&flags, FLGRMLOWERSIZE); if ((LowerSize = SizeTransfer (optarg))==-1) {usage ();}; break;
96+ case 'S': FLGSET(&flags, FLGRMUPPERSIZE); if ((UpperSize = SizeTransfer (optarg))==-1) {usage ();}; break;
97+ case 'x': FLGSET(&flags, FLGRMLOWERX); LowerX = (unsigned int)atoi (optarg); break;
98+ case 'X': FLGSET(&flags, FLGRMUPPERX); UpperX = (unsigned int)atoi (optarg); break;
99+ case 'y': FLGSET(&flags, FLGRMLOWERY); LowerY = (unsigned int)atoi (optarg); break;
100+ case 'Y': FLGSET(&flags, FLGRMUPPERY); UpperY = (unsigned int)atoi (optarg); break;
101+ case 'D': FLGSET(&flags, FLGDEBUGMODE); break;
102+ case 'h': case '?': default:
103+ usage ();
104+ }
105+ }
106+ argc -= optind;
107+ argv += optind;
108+
109+ /*****************************************************************************
110+ * Option After process *****************************************************/
111+ if (TargetFileType==0) {TargetFileType = GEXTGRAPHICALL;}
112+
113+ FirstPathNum = argc;
114+ if ((patharray=malloc_init ((sizeof (spname)*argc)))==NULL) {
115+ fprintf (stderr, "Memory allocate error for path name\n");
116+ return 0;
117+ }
118+ for (i=0; i<argc; i++) {
119+ memcpy ((patharray+i)->path, *(argv+i), MIN(MAXPATHLEN, strlen (*(argv+i))));
120+ if ((patharray+i)->path[strlen (*(argv+i))-1]=='/') {
121+ (patharray+i)->path[strlen (*(argv+i))-1] = 0;
122+ }
123+ }
124+
125+ return 1;
126+}
--- release/rempic-0.1/png_chk.c (nonexistent)
+++ release/rempic-0.1/png_chk.c (revision 1)
@@ -0,0 +1,130 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+/*//========================================================================\\*
44+ *|| Jpeg check ||*
45+ *\\========================================================================//*/
46+/*******************************************************************************
47+ * png check IHDL *************************************************************/
48+static int png_chk_ihdl (picInfo *pinfo, unsigned char *data, off_t len)
49+{
50+ pinfo->img_x = ((unsigned long)(*data)<<24)|((unsigned long)(*(data+1))<<16)|((unsigned long)(*(data+2))<<8)|(unsigned long)(*(data+3));data+=4;
51+ pinfo->img_y = ((unsigned long)(*data)<<24)|((unsigned long)(*(data+1))<<16)|((unsigned long)(*(data+2))<<8)|(unsigned long)(*(data+3));data+=4;
52+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("img_x: %ld, img_y: %ld\n", pinfo->img_x, pinfo->img_y);}
53+
54+ pinfo->fm = 0;
55+ return 1;
56+
57+ pinfo->fm = 1;
58+ return 0;
59+}
60+
61+/*******************************************************************************
62+ * png check(jpg,jpeg) *******************************************************/
63+void png_chk (int fd, picInfo *pinfo)
64+{
65+ unsigned int masize;
66+ unsigned char *ifpot, *ifoff, br;
67+ off_t rlen, off_set, size;
68+ unsigned int crc, crc_chk, hl;
69+ int i, rrtn;
70+
71+ pinfo->fm = 0;
72+ /*******************************************************************
73+ * Get File size and allocate memory ******************************/
74+ masize = MIN((unsigned int)pinfo->fsize, (unsigned int)MAXMALLOCSIZE);
75+ if ((ifpot=(unsigned char *)malloc_init (masize))==NULL) {return ;}
76+ ifoff = ifpot;
77+ br = rlen = off_set = 0;
78+
79+
80+ /*-Get packet info from input file and dividing flow Start--------*/
81+ while ((rrtn=read (fd, ifoff, (masize-rlen)))>=0) {
82+ rlen = (off_t)rrtn + rlen;
83+ if (rlen<0) {free (ifpot); return;}
84+ ifoff = ifpot;
85+ if (off_set==0 && rlen==0) {pinfo->fm = 1; br=1; break;}
86+
87+ /*-Get packet info from read data Start-------------------------*/
88+ while (rlen>=8) {
89+ if (off_set==0) { /* SOL */
90+ if (rlen<8) {br=1; break;}
91+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("PNG identifier\n");}
92+ if (!(*(ifoff+0)==0x89 && *(ifoff+1)==0x50 && *(ifoff+2)==0x4e && *(ifoff+3)==0x47 &&
93+ *(ifoff+4)==0x0d && *(ifoff+5)==0x0a && *(ifoff+6)==0x1a && *(ifoff+7)==0x0a)) {
94+ pinfo->fm = 1;
95+ br=1; break;
96+ }
97+ size = 8;
98+ } else {
99+ hl = ((off_t)*(ifoff+0)<<24)|((off_t)*(ifoff+1)<<16)|((off_t)*(ifoff+2)<<8)|((off_t)*(ifoff+3));
100+ /*printf ("size: 0x%8X, %u\n", hl, hl);*/
101+ if (rlen<(hl+12)) {if ((hl+12)>masize) {br=1; pinfo->fm = 2;}break;}
102+ size = (off_t) (hl+12);
103+ /***** crc check *****/
104+ crc = crc_chk = 0;
105+ crc = ((unsigned int)*(ifoff+hl+8)<<24)|((unsigned int)*(ifoff+hl+9)<<16)|((unsigned int)*(ifoff+hl+10)<<8)|((unsigned int)*(ifoff+hl+11));
106+ crc_chk = crc; /* crc code */
107+ /*printf ("crc: 0x%8X\n", crc);*/
108+ if ((crc^crc_chk)!=0) {br=1; pinfo->fm = 1; break;}
109+
110+ if (*(ifoff+4)=='I' && *(ifoff+5)=='H' && *(ifoff+6)=='D' && *(ifoff+7)=='R') {png_chk_ihdl (pinfo, (ifoff+8), hl);}
111+ }
112+ /*if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("size: 0x%4X%\n", size);}*/
113+
114+ if (pinfo->img_x!=0 && pinfo->img_y!=0) {br=1; break;}
115+ rlen -= size; ifoff += size; off_set += size;
116+ }
117+ if (br) {break;}
118+
119+
120+ /*-Get packet info from read data End---------------------------*/
121+ for (i=0; i<rlen; i++) {*(ifpot+i) = *(ifoff+i);}
122+ ifoff = ifpot + rlen;
123+ }
124+ if (pinfo->img_x==0 || pinfo->img_y==0) {pinfo->fm = 1;}
125+ /*-Get packet info from input file and dividing flow End----------*/
126+ free (ifpot);
127+
128+ return ;
129+}
130+
--- release/rempic-0.1/gif_chk.c (nonexistent)
+++ release/rempic-0.1/gif_chk.c (revision 1)
@@ -0,0 +1,94 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+/*//========================================================================\\*
44+ *|| GIF check ||*
45+ *\\========================================================================//*/
46+/*******************************************************************************
47+ * gif check(gif) *************************************************************/
48+void gif_chk (int fd, picInfo *pinfo)
49+{
50+ unsigned int masize;
51+ unsigned char *ifpot, *ifoff, br;
52+ off_t rlen, off_set;
53+ int i, rrtn;
54+
55+ pinfo->fm = 0;
56+ /*******************************************************************
57+ * Get File size and allocate memory ******************************/
58+ masize = MIN((unsigned int)pinfo->fsize, (unsigned int)MAXMALLOCSIZE);
59+
60+ if (masize<=20) {pinfo->fm = 1; return ;}
61+ if ((ifpot=(unsigned char *)malloc_init (masize))==NULL) {return ;}
62+ ifoff = ifpot;
63+ br = rlen = off_set = 0;
64+
65+
66+ /*-Get packet info from input file and dividing flow Start--------*/
67+ while ((rrtn=read (fd, ifoff, (masize-rlen)))>=0) {
68+ rlen = (off_t)rrtn + rlen;
69+ if (rlen<0) {free (ifpot); return;}
70+ ifoff = ifpot;
71+ if (off_set==0 && rlen==0) {pinfo->fm = 1; br=1; break;}
72+
73+ /*-Get packet info from read data Start-------------------------*/
74+ if (off_set==0) { /* Signature Check */
75+ if (!(*(ifoff+0)==0x47 && *(ifoff+1)==0x49 && *(ifoff+2)==0x46)) {pinfo->fm = 1; return ;}
76+ else if (!((*(ifoff+3)==0x38 && *(ifoff+4)==0x37 && *(ifoff+5)==0x61) ||
77+ (*(ifoff+3)==0x38 && *(ifoff+4)==0x39 && *(ifoff+5)==0x61))) {pinfo->fm = 1; return ;}
78+ pinfo->img_x = (unsigned int)(*(ifoff+7))<<8|(unsigned int)(*(ifoff+6));
79+ pinfo->img_y = (unsigned int)(*(ifoff+9))<<8|(unsigned int)(*(ifoff+8));
80+ if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("img_x: %ld, img_y: %ld\n", pinfo->img_x, pinfo->img_y);}
81+ break;
82+ }
83+
84+ /*-Get packet info from read data End---------------------------*/
85+ for (i=0; i<rlen; i++) {*(ifpot+i) = *(ifoff+i);}
86+ ifoff = ifpot + rlen;
87+ }
88+ if (pinfo->img_x==0 || pinfo->img_y==0) {pinfo->fm = 1;}
89+ /*-Get packet info from input file and dividing flow End----------*/
90+ free (ifpot);
91+
92+ return ;
93+}
94+
--- release/rempic-0.1/Makefile (nonexistent)
+++ release/rempic-0.1/Makefile (revision 1)
@@ -0,0 +1,60 @@
1+#
2+# The MIT License (MIT)
3+#
4+# Copyright (c) 2014 Yuki SAKAI
5+#
6+# Permission is hereby granted, free of charge, to any person obtaining a copy
7+# of this software and associated documentation files (the "Software"), to deal
8+# in the Software without restriction, including without limitation the rights
9+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+# copies of the Software, and to permit persons to whom the Software is
11+# furnished to do so, subject to the following conditions:
12+#
13+# The above copyright notice and this permission notice shall be included in
14+# all copies or substantial portions of the Software.
15+#
16+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+# THE SOFTWARE.
23+################################################################################
24+
25+################################################################################
26+RMFILE = *~ *.core
27+RMFILE +=
28+################################################################################
29+PROG = rempic
30+INSTDIR =
31+################################################################################
32+RMOBJ = rempic.o usage.o option.o stdlib.o open_dir.o remove.o
33+RMOBJ += file_chk.o jpg_chk.o png_chk.o gif_chk.o
34+RMOBJ +=
35+OBJECT = rempic.h macro.h
36+OBJECT += $(RMOBJ)
37+################################################################################
38+# -DDEBUG
39+DMACRO =
40+DOPT = $(DMACRO)
41+DOPT +=
42+LINK =
43+LIB = -L./
44+INCLUDE = -I./
45+CFLAGS = -O2 -Wall $(OPT) $(INCLUDE) $(LIB) $(DOPT)
46+RM = rm -f
47+
48+
49+all: $(PROG)
50+
51+rempic: $(OBJECT)
52+
53+$(PROG): $(OBJECT)
54+ $(CC) $(CFLAGS) -o $@ $(RMOBJ) $(LINK)
55+
56+.c.o:
57+
58+clean:
59+ $(RM) $(PROG) $(RMOBJ) $(RMFILE)
60+
--- release/rempic-0.1/remove.c (nonexistent)
+++ release/rempic-0.1/remove.c (revision 1)
@@ -0,0 +1,220 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
37+# include <unistd.h>
38+#endif
39+#if !defined(_ERRNO_H_) && !defined(_ERRNO_H)
40+# include <errno.h>
41+#endif
42+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
43+# include <sys/types.h>
44+#endif
45+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
46+# include <sys/stat.h>
47+#endif
48+#if !defined(_SYS_FILE_H_) && !defined(_SYS_FILE_H)
49+# include <sys/file.h>
50+#endif
51+#if !defined(_FCNTL_H_) && !defined(_FCNTL_H)
52+# include <fcntl.h>
53+#endif
54+
55+
56+/*******************************************************************************
57+ * read file ******************************************************************/
58+static int read_file (unsigned char *path, picInfo *pinfo)
59+{
60+ int fd;
61+
62+ if ((fd=open ((char *)path, O_RDONLY))==-1) {return 0;}
63+ else if (flock (fd, LOCK_SH)==-1) {close (fd); return 0;}
64+
65+ if (FLGCHK(pinfo->ft, GEXTJPG)) {jpeg_chk (fd, pinfo);}
66+ else if (FLGCHK(pinfo->ft, GEXTJPEG)) {jpeg_chk (fd, pinfo);}
67+ else if (FLGCHK(pinfo->ft, GEXTPNG)) {png_chk (fd, pinfo); }
68+ else if (FLGCHK(pinfo->ft, GEXTGIF)) {gif_chk (fd, pinfo); }
69+
70+ flock (fd, LOCK_UN);
71+ close (fd);
72+
73+ return 1;
74+}
75+
76+/*******************************************************************************
77+ * file extension chk *********************************************************/
78+static unsigned int file_extchk (unsigned char *path)
79+{
80+ unsigned char *pext;
81+ unsigned char ext[10];
82+ (void) memset ((char *)ext, 0, 10);
83+
84+ for (pext = path + strlen ((char *)path) - 1; pext!=path; pext--) {
85+ if (*pext=='.') {break;}
86+ }
87+ if (*pext!='.') {return GEXTERROR;}
88+ else if (strlen ((char *)(pext+1))>9) {return GEXTERROR;}
89+ strncpy ((char *)ext, (char *)(pext+1), 10);
90+ return ext_chk (ext);
91+}
92+
93+/*******************************************************************************
94+ * file size check ************************************************************/
95+static int fsize_chk (off_t size)
96+{
97+ if (FLGCHK(flags, FLGRMUPPERSIZE) && FLGCHK(flags, FLGRMLOWERSIZE)) {
98+ if (UpperSize<=LowerSize) {
99+ if (UpperSize>=size) {return RMCHKREMOVE;}
100+ else if (LowerSize<=size) {return RMCHKREMOVE;}
101+ } else {
102+ if (UpperSize>=size && LowerSize<=size) {return RMCHKREMOVE;}
103+ }
104+ } else if (FLGCHK(flags, FLGRMUPPERSIZE)) {
105+ if (UpperSize>=size) {return RMCHKREMOVE;}
106+ } else if (FLGCHK(flags, FLGRMLOWERSIZE)) {
107+ if (LowerSize<=size) {return RMCHKREMOVE;}
108+ }
109+
110+ return RMCHKINIT;
111+}
112+
113+/*******************************************************************************
114+ * file X check ***************************************************************/
115+static int fx_chk (unsigned long img_x)
116+{
117+ if (FLGCHK(flags, FLGRMUPPERX) && FLGCHK(flags, FLGRMLOWERX)) {
118+ if (UpperX<=LowerX) {
119+ if (UpperX>=img_x) {return RMCHKREMOVE;}
120+ else if (LowerX<=img_x) {return RMCHKREMOVE;}
121+ } else {
122+ if (UpperX>=img_x && LowerX<=img_x) {return RMCHKREMOVE;}
123+ }
124+ } else if (FLGCHK(flags, FLGRMUPPERX)) {
125+ if (UpperX>=img_x) {return RMCHKREMOVE;}
126+ } else if (FLGCHK(flags, FLGRMLOWERX)) {
127+ if (LowerX<=img_x) {return RMCHKREMOVE;}
128+ }
129+
130+ return RMCHKINIT;
131+}
132+
133+/*******************************************************************************
134+ * file Y check ***************************************************************/
135+static int fy_chk (unsigned long img_y)
136+{
137+ if (FLGCHK(flags, FLGRMUPPERY) && FLGCHK(flags, FLGRMLOWERY)) {
138+ if (UpperY<=LowerY) {
139+ if (UpperY>=img_y) {return RMCHKREMOVE;}
140+ else if (LowerY<=img_y) {return RMCHKREMOVE;}
141+ } else {
142+ if (UpperY>=img_y && LowerY<=img_y) {return RMCHKREMOVE;}
143+ }
144+ } else if (FLGCHK(flags, FLGRMUPPERY)) {
145+ if (UpperY>=img_y) {return RMCHKREMOVE;}
146+ } else if (FLGCHK(flags, FLGRMLOWERY)) {
147+ if (LowerY<=img_y) {return RMCHKREMOVE;}
148+ }
149+
150+ return RMCHKINIT;
151+}
152+
153+/*******************************************************************************
154+ * Remove check ***************************************************************/
155+int remove_chk (spname finfo)
156+{
157+ /*****************************************************************************
158+ * if determine remove process(chk!=0), jump remove process ******************
159+ ****************************************************************************/
160+ unsigned int ft;
161+ int chk;
162+ picInfo pinfo;
163+
164+ chk = RMCHKINIT;
165+ ft = GEXTERROR;
166+ (void) memset ((char *)&pinfo, 0, sizeof (picInfo));
167+ pinfo.fsize = finfo.sb.st_size;
168+ /*****************************************************************************
169+ * Analyse filepath name extension ******************************************/
170+ if ((pinfo.ft=file_extchk (finfo.path))==GEXTERROR) {chk = RMCHKSAVE; goto rm_proc;}
171+ else if ((pinfo.ft&TargetFileType)==0) {chk = RMCHKSAVE; goto rm_proc;}
172+ /*****************************************************************************
173+ * File if check ************************************************************/
174+ if ((chk=fsize_chk (pinfo.fsize))!=RMCHKINIT) {goto rm_proc;} /* file size */
175+ else if (!read_file (finfo.path, &pinfo)) {return 0;} /* read file i*/
176+ else if (pinfo.fm) {
177+ if (pinfo.fm==2) {chk = RMCHKSAVE; }
178+ else if (FLGCHK(flags, FLGRMPICBADFILE)) {chk = RMCHKREMOVE;}
179+ else {chk = RMCHKSAVE; }
180+ goto rm_proc;
181+ }
182+ else if (FLGCHK(flags, FLGRMPICBADFILE) && pinfo.fm) {chk = RMCHKSAVE; goto rm_proc;}
183+ else if ((chk=fx_chk (pinfo.img_x))!=RMCHKINIT) {goto rm_proc;} /* file size */
184+ else if ((chk=fy_chk (pinfo.img_y))!=RMCHKINIT) {goto rm_proc;} /* file size */
185+
186+ chk = RMCHKSAVE;
187+ /*****************************************************************************
188+ * Remove Process ***********************************************************/
189+ rm_proc:
190+ if (FLGCHK(flags, FLGDEBUGMODE)) {
191+ /* not remove */
192+ if (chk==RMCHKREMOVE) {fprintf (debugout, "remove: %s\n" , finfo.path);}
193+ else if (chk==RMCHKSAVE) {fprintf (debugout, "save: %s\n" , finfo.path);}
194+ else {fprintf (debugout, "no check: %s\n", finfo.path);}
195+ } else {
196+ if (chk==RMCHKREMOVE && 1) {
197+ errno = 0;
198+ if (unlink ((char *)finfo.path)<0) {
199+ switch (errno) {
200+ case ENOTDIR : fprintf (patherr, "%s: path is include not directory and file name\n", finfo.path); break;
201+ case ENAMETOOLONG: fprintf (patherr, "%s: path name is long\n" , finfo.path); break;
202+ case ENOENT : fprintf (patherr, "%s: no such file\n" , finfo.path); break;
203+ case EACCES : fprintf (patherr, "%s: Can't access\n" , finfo.path); break;
204+ case ELOOP : fprintf (patherr, "%s: Many symbolic link\n" , finfo.path); break;
205+ case EPERM : fprintf (patherr, "%s: Don't permit remove\n" , finfo.path); break;
206+ case EBUSY : fprintf (patherr, "%s: Can't remove for file is busy\n" , finfo.path); break;
207+ case EIO : fprintf (patherr, "%s: I/O error\n" , finfo.path); break;
208+ case EROFS : fprintf (patherr, "%s: file is read only\n" , finfo.path); break;
209+ case EFAULT : fprintf (patherr, "%s: Pointer error\n" , finfo.path); break;
210+ }
211+ fprintf (stdout, "can't rm: %s\n" , finfo.path);
212+ } else {fprintf (stdout, "remove: %s\n" , finfo.path);}
213+ } else {fprintf (stdout, "save : %s\n" , finfo.path);}
214+ }
215+ return 1;
216+}
217+
218+
219+
220+
--- trunk/open_dir.c (nonexistent)
+++ trunk/open_dir.c (revision 1)
@@ -0,0 +1,141 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
37+# include <sys/types.h>
38+#endif
39+#if !defined(_DIRENT_H_) && !defined(_DIRENT_H)
40+# include <dirent.h>
41+#endif
42+#if !defined(_ERRNO_H_) && !defined(_ERRNO_H)
43+# include <errno.h>
44+#endif
45+
46+
47+/*******************************************************************************
48+ * Open directory *************************************************************/
49+int open_dir (spname *pspn)
50+{
51+ struct dirent entry, *result;
52+ DIR *dfd;
53+ int i;
54+
55+ if (pspn->ft!=SPFTDIR) {return PPRABORT;}
56+
57+ errno = 0;
58+ if ((dfd=opendir ((char *)pspn->path))==NULL) {
59+ switch (errno) {
60+ case EACCES : fprintf (patherr, "%s: Can't access this directory\n", pspn->path); break;
61+ case EMFILE : fprintf (patherr, "%s: Can't open file descriptor\n" , pspn->path); break;
62+ case ENFILE : fprintf (patherr, "%s: Many file is open\n" , pspn->path); break;
63+ case ENOENT : fprintf (patherr, "%s: No such file or directory\n" , pspn->path); break;
64+ case ENOMEM : fprintf (patherr, "%s: Empty memory\n" , pspn->path); break;
65+ case ENOTDIR: fprintf (patherr, "%s: Path is not directory\n" , pspn->path); break;
66+ }
67+ return PPRALLKILL;
68+ if (errno==ENOMEM) {
69+ return PPRALLKILL;
70+ }
71+ return PPRABORT;
72+ }
73+
74+ /*****************************************************************************
75+ * path Count in directory **************************************************/
76+ pspn->fnum = 0;
77+ while (1) {
78+ errno = 0;
79+ if (readdir_r (dfd, &entry, &result)!=0) {
80+ switch (errno) {
81+ case EBADF : fprintf (patherr, "%s: Can't read dir\n" , pspn->path); break;
82+ case ENOENT: fprintf (patherr, "%s: Don't open dir\n" , pspn->path); break;
83+ case EFAULT: fprintf (patherr, "%s: Open dir failed\n", pspn->path); break;
84+ }
85+ closedir (dfd);
86+ return PPRABORT;
87+ } else if (result==NULL) {break;}
88+
89+ if (result->d_name[strlen (result->d_name)-1]=='/') {result->d_name[strlen (result->d_name)-1] = 0;}
90+
91+ if (strcmp (result->d_name, "." )==0) {continue;}
92+ else if (strcmp (result->d_name, "..")==0) {continue;}
93+
94+ if (result->d_name[0]=='.' && !FLGCHK(flags, FLGALLFILES)) {continue;}
95+ pspn->fnum++;
96+ }
97+
98+ /*****************************************************************************
99+ * Get path name init *******************************************************/
100+ if (pspn->fnum==0) {pspn->farray = NULL; return PPRABORT;}
101+ else if ((pspn->farray=malloc_init ((sizeof (spname)*pspn->fnum)))==NULL) {
102+ fprintf (stderr, "Memory allocate error for path name\n");
103+ return PPRALLKILL;
104+ }
105+ rewinddir (dfd);
106+ i = 0;
107+
108+ /*****************************************************************************
109+ * Get path name ************************************************************/
110+ while (1) {
111+ errno = 0;
112+ if (readdir_r (dfd, &entry, &result)!=0) {
113+ switch (errno) {
114+ case EBADF : fprintf (patherr, "%s: Can't read dir\n" , pspn->path); break;
115+ case ENOENT: fprintf (patherr, "%s: Don't open dir\n" , pspn->path); break;
116+ case EFAULT: fprintf (patherr, "%s: Open dir failed\n", pspn->path); break;
117+ }
118+ closedir (dfd);
119+ return PPRABORT;
120+ } else if (result==NULL) {
121+
122+ break;}
123+
124+ if (result->d_name[strlen (result->d_name)-1]=='/') {result->d_name[strlen (result->d_name)-1] = 0;}
125+
126+ if (strcmp (result->d_name, "." )==0) {continue;} /* skip "." path */
127+ else if (strcmp (result->d_name, "..")==0) {continue;} /* skip ".." path */
128+ if (result->d_name[0]=='.' && !FLGCHK(flags, FLGALLFILES)) {continue;} /* skip? ".hogehoge" path */
129+
130+ snprintf ((char *)pspn->farray[i].path, MAXPATHLEN-1, "%s/%s", pspn->path, result->d_name);
131+ i++;
132+ }
133+
134+ closedir (dfd);
135+ return 1;
136+}
137+
138+
139+
140+
141+
--- trunk/rempic.c (nonexistent)
+++ trunk/rempic.c (revision 1)
@@ -0,0 +1,114 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
31+# include <sys/stat.h>
32+#endif
33+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
34+# include <stdio.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_ERRNO_H_) && !defined(_ERRNO_H)
40+# include <errno.h>
41+#endif
42+
43+
44+
45+/*******************************************************************************
46+ * Path processing ************************************************************/
47+int path_proc (spname *pArray, unsigned int FileNum)
48+{
49+ int i;
50+ int rtn;
51+
52+ if (pArray==NULL) {fprintf (patherr, "no path\n"); return PPRABORT;}
53+ else if (FileNum==0 ) {fprintf (patherr, "no path\n"); return PPRABORT;}
54+
55+ for (i=0; i<FileNum; i++) {
56+ /***************************************************************************
57+ * Get Path info **********************************************************/
58+ errno = 0;
59+ if (lstat ((char *)pArray[i].path, &(pArray[i].sb))<0) {
60+ switch (errno) {
61+ case EACCES : fprintf (patherr, "%s: Can't access this path\n" , pArray[i].path); break;
62+ case ELOOP : fprintf (patherr, "%s: Symbolic link is many\n" , pArray[i].path); break;
63+ case ENAMETOOLONG: fprintf (patherr, "%s: Path name is long\n" , pArray[i].path); break;
64+ case ENOENT : fprintf (patherr, "%s: No such file or directory\n" , pArray[i].path); break;
65+ case ENOMEM : fprintf (patherr, "%s: Empty memory\n" , pArray[i].path); goto stop_err; break;
66+ case ENOTDIR : fprintf (patherr, "%s: Path is not directory or file\n", pArray[i].path); break;
67+ }
68+ continue;
69+ }
70+ if (S_ISREG(pArray[i].sb.st_mode)) {pArray[i].ft = SPFTFILE; }
71+ else if (S_ISDIR(pArray[i].sb.st_mode)) {pArray[i].ft = SPFTDIR; }
72+ else {pArray[i].ft = SPFTOTHERS;}
73+
74+ /***************************************************************************
75+ * Path processing ********************************************************/
76+ if (pArray[i].ft==SPFTFILE) {
77+ /* remove check and remove process */
78+ remove_chk (pArray[i]);
79+ } else if (pArray[i].ft==SPFTDIR) {
80+ /*=Directory read check=================================================*/
81+ if (FLGCHK(flags, FLGRECURSIVE)) {
82+ rtn = open_dir (&pArray[i]);
83+ if (rtn==PPRABORT) {}
84+ else if (rtn==PPRALLKILL) {goto stop_err;}
85+ else {
86+ rtn = path_proc (pArray[i].farray, pArray[i].fnum);
87+ free (pArray[i].farray);
88+ if (rtn==PPRALLKILL) {goto stop_err;}
89+ }
90+ }
91+ }
92+ }
93+
94+ return 1;
95+
96+ stop_err:
97+ return 0;
98+}
99+
100+
101+/*******************************************************************************
102+ * Main processing ************************************************************/
103+int main (int argc, char **argv)
104+{
105+ /**Option Processing Block***************************************************/
106+ if (opt_proc (argc, argv)<0) {goto non_proc_err;}
107+ else if (path_proc (patharray, FirstPathNum)<0) {goto non_proc_err;}
108+ free (patharray);
109+
110+ return 0;
111+
112+ non_proc_err:
113+ return 1;
114+}
--- trunk/stdlib.c (nonexistent)
+++ trunk/stdlib.c (revision 1)
@@ -0,0 +1,44 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H_)
31+# include <stdlib.h>
32+#endif
33+
34+/*******************************************************************************
35+ * memAllocate ****************************************************************/
36+void * malloc_init (size_t size)
37+{
38+ void *pt, *pp;
39+ size_t i;
40+ if ((pt=malloc (size))==NULL) {return NULL;}
41+ for (pp=pt,i=0; i<size; i++,pp++) {*(unsigned char *)pp = 0;}
42+ return pt;
43+}
44+
--- trunk/file_chk.c (nonexistent)
+++ trunk/file_chk.c (revision 1)
@@ -0,0 +1,57 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+
44+/*******************************************************************************
45+ * Extension check ************************************************************/
46+unsigned int ext_chk (unsigned char *ext)
47+{
48+ if (strcmp ((char *)ext, "jpg" )==0) {return GEXTJPG; }
49+ else if (strcmp ((char *)ext, "JPG" )==0) {return GEXTJPG; }
50+ else if (strcmp ((char *)ext, "jpeg")==0) {return GEXTJPEG;}
51+ else if (strcmp ((char *)ext, "png" )==0) {return GEXTPNG; }
52+ else if (strcmp ((char *)ext, "PNG" )==0) {return GEXTPNG; }
53+ else if (strcmp ((char *)ext, "gif" )==0) {return GEXTGIF; }
54+ else if (strcmp ((char *)ext, "GIF" )==0) {return GEXTGIF; }
55+
56+ return GEXTNOGRAPHIC;
57+}
--- trunk/rempic.h (nonexistent)
+++ trunk/rempic.h (revision 1)
@@ -0,0 +1,149 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+#ifndef REMPIC_H__
26+#define REMPIC_H__ __DATE__
27+
28+/*******************************************************************************
29+ * Include ********************************************************************/
30+#if !defined(MACRO_H_)
31+# include <macro.h>
32+#endif
33+#if !defined(_SYS_PARAM_H_) && !defined(_SYS_PARAM_H)
34+# include <sys/param.h>
35+#endif
36+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
37+# include <stdio.h>
38+#endif
39+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
40+# include <sys/stat.h>
41+#endif
42+
43+
44+/*******************************************************************************
45+ * Define *********************************************************************/
46+/*=Program state==============================================================*/
47+#define VERSION "1.0.0" /* Program version */
48+/*=Option Flags===============================================================*/
49+#define FLGALL 0x000003ff /* All flags bits */
50+#define FLGDEBUGMODE 0x00000001 /* Debug Mode ON (-D) */
51+#define FLGRECURSIVE 0x00000002 /* Directory Recursive ON (-r)*/
52+#define FLGRMPICBADFILE 0x00000004 /* rm picture badfile (-b) */
53+#define FLGALLFILES 0x00000008 /* target is ALL files (-a) */
54+#define FLGRMUPPERSIZE 0x00000010 /* rm upper picture bytes (-S)*/
55+#define FLGRMLOWERSIZE 0x00000020 /* rm lower picture bytes (-s)*/
56+#define FLGRMUPPERX 0x00000040 /* rm upper picture x (-X) */
57+#define FLGRMLOWERX 0x00000080 /* rm lower picture x (-x) */
58+#define FLGRMUPPERY 0x00000100 /* rm upper picture y (-Y) */
59+#define FLGRMLOWERY 0x00000200 /* rm lower picture y (-y) */
60+/*=Path Process Return========================================================*/
61+#define PPRALLKILL -1
62+#define PPRABORT -2
63+/*=Remove check===============================================================*/
64+#define RMCHKINIT 0
65+#define RMCHKREMOVE 1
66+#define RMCHKSAVE 2
67+/*=Graphic extension==========================================================*/
68+#define GEXTERROR 0x00000000
69+#define GEXTNOGRAPHIC 0x00000001
70+#define GEXTGRAPHICALL 0x0000001e
71+#define GEXTJPG 0x00000002
72+#define GEXTPNG 0x00000004
73+#define GEXTJPEG 0x00000008
74+#define GEXTGIF 0x00000010
75+/*=Graphic config=============================================================*/
76+#define MAXMALLOCSIZE 0x1fffff /* Max allocate memory size */
77+/*=Graphic config(JPEG)=======================================================*/
78+#define JPGMARKSOL 0x1
79+#define JPGMARKEOL 0x2
80+
81+/*******************************************************************************
82+ * Save Path name *************************************************************/
83+/*=File Type define===========================================================*/
84+#define SPFTINIT 0x00 /* File type init */
85+#define SPFTFILE 0x01 /* File type is normal */
86+#define SPFTDIR 0x02 /* File type is dir */
87+#define SPFTOTHERS 0x03 /* Other file type */
88+#define SPFTUNKNOWN 0x04 /* File type is unknown */
89+/*=structure==================================================================*/
90+typedef struct SAVEPATHNAME {
91+ struct SAVEPATHNAME *farray;
92+ unsigned char ft; /* File Type */
93+ unsigned char path[MAXPATHLEN]; /* path name */
94+ unsigned int fnum; /* This directory have File number */
95+ struct stat sb;
96+} spname;
97+
98+/*******************************************************************************
99+ * Pic info *******************************************************************/
100+typedef struct {
101+ unsigned char fm;
102+ unsigned int ft;
103+ unsigned char perUnit;
104+ off_t fsize;
105+ unsigned long img_x, img_y;
106+} picInfo;
107+
108+
109+/*******************************************************************************
110+ * Global functions ***********************************************************/
111+/*=file_chk===================================================================*/
112+void jpeg_chk (int fd, picInfo *pinfo);
113+unsigned int ext_chk (unsigned char *ext);
114+/*=open_dir===================================================================*/
115+int open_dir (spname *pspn);
116+/*=option.c===================================================================*/
117+int opt_proc (int argc, char **argv);
118+/*=remove.c===================================================================*/
119+int remove_chk (spname finfo);
120+/*=stdlib.c===================================================================*/
121+void * malloc_init (size_t size);
122+/*=usage.c====================================================================*/
123+void usage (void);
124+/*=jpg_chk====================================================================*/
125+void jpeg_chk (int fd, picInfo *pinfo);
126+/*=png_chk====================================================================*/
127+void png_chk (int fd, picInfo *pinfo);
128+/*=gif_chk====================================================================*/
129+void gif_chk (int fd, picInfo *pinfo);
130+
131+/*******************************************************************************
132+ * Global variables ***********************************************************/
133+/*-Program state--------------------------------------------------------------*/
134+char *pname; /* Program name */
135+/*-Option Process-------------------------------------------------------------*/
136+unsigned int flags;
137+spname *patharray;
138+unsigned int FirstPathNum;
139+unsigned int TargetFileType;
140+off_t UpperSize, LowerSize;
141+unsigned int UpperX, LowerX;
142+unsigned int UpperY, LowerY;
143+/*-Error Output---------------------------------------------------------------*/
144+FILE *debugout;
145+FILE *usageout;
146+FILE *patherr;
147+
148+
149+#endif /* REMPIC_H__ */
--- trunk/usage.c (nonexistent)
+++ trunk/usage.c (revision 1)
@@ -0,0 +1,53 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
34+# include <stdlib.h>
35+#endif
36+
37+/*******************************************************************************
38+ * Usage **********************************************************************/
39+void usage (void)
40+{
41+ usageout = stdout;
42+ fprintf (usageout, "%s [-x LowXSize] [-X UpperXSize] [-y LowYSize] [-Y UpperYSize]\n", pname);
43+ fprintf (usageout, "\t[-s UnderSize] [-S OverSize] [-a] [-b] [-r] [-D] targetname....\n");
44+ fprintf (usageout, "\t-x|-X : Target X-Length, LowXSize<TargetXSize, TargetXSize<UpperXSize\n");
45+ fprintf (usageout, "\t-y|-Y : Target Y-Length, LowYSize<TargetYSize, TargetYSize<UpperYSize\n");
46+ fprintf (usageout, "\t-s|-S : Target Size , UnderSize<TargetFileSize, TargetFileSize<OverSize\n");
47+ fprintf (usageout, "\t-a : Include hide file\n");
48+ fprintf (usageout, "\t-b : Remove Bad format file\n");
49+ fprintf (usageout, "\t-r : Recurcive Directory\n");
50+ fprintf (usageout, "\t-D : Debug mode\n");
51+
52+ exit (1);
53+}
--- trunk/jpg_chk.c (nonexistent)
+++ trunk/jpg_chk.c (revision 1)
@@ -0,0 +1,288 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+/*//========================================================================\\*
44+ *|| Jpeg check ||*
45+ *\\========================================================================//*/
46+/*******************************************************************************
47+ * jpeg check APP0 ************************************************************/
48+static int jpeg_chk_app0 (picInfo *pinfo, unsigned char *data, off_t len)
49+{
50+ data+=2; /* skip head length */
51+ if (strncmp ((char *)data, "JFIF", 4)!=0) {goto err_proc;}
52+ else if (*(data+4)!=0x00) {goto err_proc;}
53+ data+=5;
54+ data+=2; /* skip version */
55+ pinfo->perUnit = *data; data+=1; /* unit */
56+
57+ pinfo->fm = 0;
58+ return 1;
59+ err_proc:
60+ pinfo->fm = 1;
61+ return 0;
62+}
63+/*******************************************************************************
64+ * jpeg check SOF0 ************************************************************/
65+static int jpeg_chk_sof0 (picInfo *pinfo, unsigned char *data, off_t len)
66+{
67+ data+=2; /* skip head length */
68+ /*if (*(data+0)!=0x08) {goto err_proc;}*/
69+ data+=1;
70+ pinfo->img_y = ((unsigned short)(*data)<<8) | ((unsigned short)*(data+1)); data+=2;
71+ pinfo->img_x = ((unsigned short)(*data)<<8) | ((unsigned short)*(data+1)); data+=2;
72+ if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("img_x: %ld, img_y: %ld\n", pinfo->img_x, pinfo->img_y);}
73+
74+ pinfo->fm = 0;
75+ return 1;
76+
77+ pinfo->fm = 1;
78+ return 0;
79+}
80+
81+/*******************************************************************************
82+ * jpeg check(jpg,jpeg) *******************************************************/
83+void jpeg_chk (int fd, picInfo *pinfo)
84+{
85+ unsigned int masize;
86+ unsigned char *ifpot, *ifoff, br;
87+ off_t rlen, off_set, size;
88+ int i, rrtn;
89+
90+ pinfo->fm = 0;
91+ /*******************************************************************
92+ * Get File size and allocate memory ******************************/
93+ masize = MIN((unsigned int)pinfo->fsize, (unsigned int)MAXMALLOCSIZE);
94+ if ((ifpot=(unsigned char *)malloc_init (masize))==NULL) {return ;}
95+ ifoff = ifpot;
96+ br = rlen = off_set = 0;
97+
98+
99+ /*-Get packet info from input file and dividing flow Start--------*/
100+ while ((rrtn=read (fd, ifoff, (masize-rlen)))>=0) {
101+ rlen = (off_t)rrtn + rlen;
102+ if (rlen<0) {free (ifpot); return;}
103+ ifoff = ifpot;
104+ if (off_set==0 && rlen==0) {pinfo->fm = 1; br=1; break;}
105+
106+ /*-Get packet info from read data Start-------------------------*/
107+ while (rlen>=2) {
108+ if (off_set==0) { /* SOL */
109+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOL\n");}
110+ if (!(*ifoff==0xff && *(ifoff+1)==0xd8)) {
111+ pinfo->fm = 1;
112+ br=1; break;
113+ }
114+ size = 2;
115+ } else if (*ifoff==0xff && *(ifoff+1)==0xe0) { /* APP0 */
116+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP0\n");}
117+ if (rlen<4) {break;}
118+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
119+ if (rlen<(size+2)) {break;}
120+ else if (!jpeg_chk_app0 (pinfo, ifoff+2, size)) {br=1; break;}
121+ size+=2;
122+ } else if (*ifoff==0xff && *(ifoff+1)==0xdb) { /* DQT */
123+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("DQT\n");}
124+ if (rlen<4) {break;}
125+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
126+ if (rlen<(size+2)) {break;}
127+ size+=2;
128+ } else if (*ifoff==0xff && *(ifoff+1)==0xc4) { /* DHT */
129+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("DHT\n");}
130+ if (rlen<4) {break;}
131+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
132+ if (rlen<(size+2)) {break;}
133+ size+=2;
134+ } else if (*ifoff==0xff && *(ifoff+1)==0xc0) { /* SOF0 */
135+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOF0\n");}
136+ if (rlen<4) {break;}
137+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
138+ if (rlen<(size+2)) {break;}
139+ else if (!jpeg_chk_sof0 (pinfo, ifoff+2, size)) {br=1; break;}
140+ size+=2;
141+ } else if (*ifoff==0xff && *(ifoff+1)==0xc1) { /* SOF1 */
142+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOF1\n");}
143+ if (rlen<4) {break;}
144+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
145+ if (rlen<(size+2)) {break;}
146+ else if (!jpeg_chk_sof0 (pinfo, ifoff+2, size)) {br=1; break;}
147+ size+=2;
148+ } else if (*ifoff==0xff && *(ifoff+1)==0xc2) { /* SOF2 */
149+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOF2\n");}
150+ if (rlen<4) {break;}
151+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
152+ if (rlen<(size+2)) {break;}
153+ else if (!jpeg_chk_sof0 (pinfo, ifoff+2, size)) {br=1; break;}
154+ size+=2;
155+ } else if (*ifoff==0xff && *(ifoff+1)==0xd9) { /* EOL */
156+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("EOL\n");}
157+ if (rlen<4) {break;}
158+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
159+ if (rlen<(size+2)) {break;}
160+ size+=2;
161+ } else if (*ifoff==0xff && *(ifoff+1)==0xe1) { /* APP1 */
162+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP1\n");}
163+ if (rlen<4) {break;}
164+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
165+ if (rlen<(size+2)) {break;}
166+ size+=2;
167+ } else if (*ifoff==0xff && *(ifoff+1)==0xe2) { /* APP2 */
168+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP1\n");}
169+ if (rlen<4) {break;}
170+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
171+ if (rlen<(size+2)) {break;}
172+ size+=2;
173+ } else if (*ifoff==0xff && *(ifoff+1)==0xe3) { /* APP3 */
174+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP3\n");}
175+ if (rlen<4) {break;}
176+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
177+ if (rlen<(size+2)) {break;}
178+ size+=2;
179+ } else if (*ifoff==0xff && *(ifoff+1)==0xe4) { /* APP4 */
180+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP4\n");}
181+ if (rlen<4) {break;}
182+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
183+ if (rlen<(size+2)) {break;}
184+ size+=2;
185+ } else if (*ifoff==0xff && *(ifoff+1)==0xe5) { /* APP5 */
186+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP5\n");}
187+ if (rlen<4) {break;}
188+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
189+ if (rlen<(size+2)) {break;}
190+ size+=2;
191+ } else if (*ifoff==0xff && *(ifoff+1)==0xe6) { /* APP6 */
192+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP6\n");}
193+ if (rlen<4) {break;}
194+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
195+ if (rlen<(size+2)) {break;}
196+ size+=2;
197+ } else if (*ifoff==0xff && *(ifoff+1)==0xe7) { /* APP7 */
198+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP7\n");}
199+ if (rlen<4) {break;}
200+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
201+ if (rlen<(size+2)) {break;}
202+ size+=2;
203+ } else if (*ifoff==0xff && *(ifoff+1)==0xe8) { /* APP8 */
204+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP8\n");}
205+ if (rlen<4) {break;}
206+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
207+ if (rlen<(size+2)) {break;}
208+ size+=2;
209+ } else if (*ifoff==0xff && *(ifoff+1)==0xe9) { /* APP9 */
210+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APP9\n");}
211+ if (rlen<4) {break;}
212+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
213+ if (rlen<(size+2)) {break;}
214+ size+=2;
215+ } else if (*ifoff==0xff && *(ifoff+1)==0xea) { /* APPa */
216+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPa\n");}
217+ if (rlen<4) {break;}
218+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
219+ if (rlen<(size+2)) {break;}
220+ size+=2;
221+ } else if (*ifoff==0xff && *(ifoff+1)==0xeb) { /* APPb */
222+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPb\n");}
223+ if (rlen<4) {break;}
224+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
225+ if (rlen<(size+2)) {break;}
226+ size+=2;
227+ } else if (*ifoff==0xff && *(ifoff+1)==0xec) { /* APPc */
228+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPc\n");}
229+ if (rlen<4) {break;}
230+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
231+ if (rlen<(size+2)) {break;}
232+ size+=2;
233+ } else if (*ifoff==0xff && *(ifoff+1)==0xed) { /* APPd */
234+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPd\n");}
235+ if (rlen<4) {break;}
236+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
237+ /*printf ("appd size: 0x%4X\n", size);*/
238+ if (rlen<(size+2)) {break;}
239+ size+=2;
240+ } else if (*ifoff==0xff && *(ifoff+1)==0xee) { /* APPe */
241+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPe\n");}
242+ if (rlen<4) {break;}
243+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
244+ /*printf ("appd size: 0x%4X\n", size);*/
245+ if (rlen<(size+2)) {break;}
246+ size+=2;
247+ } else if (*ifoff==0xff && *(ifoff+1)==0xef) { /* APPf */
248+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("APPf\n");}
249+ if (rlen<4) {break;}
250+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
251+ /*printf ("appd size: 0x%4X\n", size);*/
252+ if (rlen<(size+2)) {break;}
253+ size+=2;
254+ } else if (*ifoff==0xff && *(ifoff+1)==0xda) { /* SOS */
255+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("SOS\n");}
256+ if (rlen<4) {break;}
257+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
258+ if (rlen<(size+2)) {break;}
259+ size+=2;
260+ } else if (*ifoff==0xff && *(ifoff+1)==0xfe) { /* comment */
261+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("comment\n");}
262+ if (rlen<4) {break;}
263+ size = *(ifoff+2); size <<=8; size += *(ifoff+3);
264+ if (rlen<(size+2)) {break;}
265+ size+=2;
266+ } else {
267+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("else: 0x%2X%2X\n", *ifoff, *(ifoff+1));}
268+ br=1; break;
269+ }
270+ /*if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("size: 0x%4X%\n", size);}*/
271+
272+ if (pinfo->img_x!=0 && pinfo->img_y!=0) {br=1; break;}
273+ rlen -= size; ifoff += size; off_set += size;
274+ }
275+ if (br) {break;}
276+
277+
278+ /*-Get packet info from read data End---------------------------*/
279+ for (i=0; i<rlen; i++) {*(ifpot+i) = *(ifoff+i);}
280+ ifoff = ifpot + rlen;
281+ }
282+ if (pinfo->img_x==0 || pinfo->img_y==0) {pinfo->fm = 1;}
283+ /*-Get packet info from input file and dividing flow End----------*/
284+ free (ifpot);
285+
286+ return ;
287+}
288+
--- trunk/macro.h (nonexistent)
+++ trunk/macro.h (revision 1)
@@ -0,0 +1,36 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+#ifndef MACRO_H__
26+#define MACRO_H__ __DATE__
27+
28+/*******************************************************************************
29+ * Flagment processing ********************************************************/
30+#define FLGINIT(a) (*a=0) /* Flag initialise */
31+#define FLGSET(a,b) (*a|=b) /* Set flag bit */
32+#define FLGCLR(a,b) (*a^=(*a&b)) /* Clear flag bit */
33+#define FLGTGR(a,b) (*a^=b) /* Toggle flag bit */
34+#define FLGCHK(a,b) ((a&b)==b?1:0) /* Check flag bit */
35+
36+#endif /* MACRO_H__ */
--- trunk/option.c (nonexistent)
+++ trunk/option.c (revision 1)
@@ -0,0 +1,126 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_SYS_PARAM_H_) && !defined(_SYS_PARAM_H)
31+# include <sys/param.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+
44+/*******************************************************************************
45+ * Size transfer **************************************************************/
46+static off_t SizeTransfer (char *str)
47+{
48+ char chk;
49+ int rlen, shift;
50+ unsigned int idx, isize;
51+ double dsize;
52+
53+ shift = chk = 0;
54+ rlen = strlen (str);
55+ for (idx=0; idx<rlen; idx++) {
56+ if (idx==(rlen-1)) {
57+ if ('0'<=str[idx] && str[idx]<='9') {}
58+ else if (str[idx]=='k' || str[idx]=='K') {shift=10; str[idx]=0x00;}
59+ else if (str[idx]=='m' || str[idx]=='M') {shift=20; str[idx]=0x00;}
60+ else if (str[idx]=='g' || str[idx]=='G') {shift=30; str[idx]=0x00;}
61+ } else {
62+ if ('0'<=str[idx] && str[idx]<='9') {}
63+ else if (chk==0 && str[idx]=='.') {chk = 1;}
64+ else {return -1;}
65+ }
66+ }
67+ dsize = strtod (str, NULL);
68+ isize = (int)(dsize * (double)(1<<shift));
69+ /*printf ("size: %u\n", isize);*/
70+ return (off_t)isize;
71+}
72+
73+/*******************************************************************************
74+ * Option *********************************************************************/
75+int opt_proc (int argc, char **argv)
76+{
77+ int i;
78+ int ch;
79+
80+ /*****************************************************************************
81+ * Option init **************************************************************/
82+ pname = *argv;
83+ patherr = stdout;
84+ debugout = stdout;
85+ TargetFileType = 0;
86+ UpperSize = LowerSize = 0;
87+
88+ /*****************************************************************************
89+ * Get Option ***************************************************************/
90+ while ((ch = getopt (argc, argv, "abrS:s:X:x:Y:y:Dh?"))>=0) {
91+ switch (ch) {
92+ case 'a': FLGSET(&flags, FLGALLFILES); break;
93+ case 'b': FLGSET(&flags, FLGRMPICBADFILE); break;
94+ case 'r': FLGSET(&flags, FLGRECURSIVE); break;
95+ case 's': FLGSET(&flags, FLGRMLOWERSIZE); if ((LowerSize = SizeTransfer (optarg))==-1) {usage ();}; break;
96+ case 'S': FLGSET(&flags, FLGRMUPPERSIZE); if ((UpperSize = SizeTransfer (optarg))==-1) {usage ();}; break;
97+ case 'x': FLGSET(&flags, FLGRMLOWERX); LowerX = (unsigned int)atoi (optarg); break;
98+ case 'X': FLGSET(&flags, FLGRMUPPERX); UpperX = (unsigned int)atoi (optarg); break;
99+ case 'y': FLGSET(&flags, FLGRMLOWERY); LowerY = (unsigned int)atoi (optarg); break;
100+ case 'Y': FLGSET(&flags, FLGRMUPPERY); UpperY = (unsigned int)atoi (optarg); break;
101+ case 'D': FLGSET(&flags, FLGDEBUGMODE); break;
102+ case 'h': case '?': default:
103+ usage ();
104+ }
105+ }
106+ argc -= optind;
107+ argv += optind;
108+
109+ /*****************************************************************************
110+ * Option After process *****************************************************/
111+ if (TargetFileType==0) {TargetFileType = GEXTGRAPHICALL;}
112+
113+ FirstPathNum = argc;
114+ if ((patharray=malloc_init ((sizeof (spname)*argc)))==NULL) {
115+ fprintf (stderr, "Memory allocate error for path name\n");
116+ return 0;
117+ }
118+ for (i=0; i<argc; i++) {
119+ memcpy ((patharray+i)->path, *(argv+i), MIN(MAXPATHLEN, strlen (*(argv+i))));
120+ if ((patharray+i)->path[strlen (*(argv+i))-1]=='/') {
121+ (patharray+i)->path[strlen (*(argv+i))-1] = 0;
122+ }
123+ }
124+
125+ return 1;
126+}
--- trunk/png_chk.c (nonexistent)
+++ trunk/png_chk.c (revision 1)
@@ -0,0 +1,130 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+/*//========================================================================\\*
44+ *|| Jpeg check ||*
45+ *\\========================================================================//*/
46+/*******************************************************************************
47+ * png check IHDL *************************************************************/
48+static int png_chk_ihdl (picInfo *pinfo, unsigned char *data, off_t len)
49+{
50+ pinfo->img_x = ((unsigned long)(*data)<<24)|((unsigned long)(*(data+1))<<16)|((unsigned long)(*(data+2))<<8)|(unsigned long)(*(data+3));data+=4;
51+ pinfo->img_y = ((unsigned long)(*data)<<24)|((unsigned long)(*(data+1))<<16)|((unsigned long)(*(data+2))<<8)|(unsigned long)(*(data+3));data+=4;
52+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("img_x: %ld, img_y: %ld\n", pinfo->img_x, pinfo->img_y);}
53+
54+ pinfo->fm = 0;
55+ return 1;
56+
57+ pinfo->fm = 1;
58+ return 0;
59+}
60+
61+/*******************************************************************************
62+ * png check(jpg,jpeg) *******************************************************/
63+void png_chk (int fd, picInfo *pinfo)
64+{
65+ unsigned int masize;
66+ unsigned char *ifpot, *ifoff, br;
67+ off_t rlen, off_set, size;
68+ unsigned int crc, crc_chk, hl;
69+ int i, rrtn;
70+
71+ pinfo->fm = 0;
72+ /*******************************************************************
73+ * Get File size and allocate memory ******************************/
74+ masize = MIN((unsigned int)pinfo->fsize, (unsigned int)MAXMALLOCSIZE);
75+ if ((ifpot=(unsigned char *)malloc_init (masize))==NULL) {return ;}
76+ ifoff = ifpot;
77+ br = rlen = off_set = 0;
78+
79+
80+ /*-Get packet info from input file and dividing flow Start--------*/
81+ while ((rrtn=read (fd, ifoff, (masize-rlen)))>=0) {
82+ rlen = (off_t)rrtn + rlen;
83+ if (rlen<0) {free (ifpot); return;}
84+ ifoff = ifpot;
85+ if (off_set==0 && rlen==0) {pinfo->fm = 1; br=1; break;}
86+
87+ /*-Get packet info from read data Start-------------------------*/
88+ while (rlen>=8) {
89+ if (off_set==0) { /* SOL */
90+ if (rlen<8) {br=1; break;}
91+ if (0 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("PNG identifier\n");}
92+ if (!(*(ifoff+0)==0x89 && *(ifoff+1)==0x50 && *(ifoff+2)==0x4e && *(ifoff+3)==0x47 &&
93+ *(ifoff+4)==0x0d && *(ifoff+5)==0x0a && *(ifoff+6)==0x1a && *(ifoff+7)==0x0a)) {
94+ pinfo->fm = 1;
95+ br=1; break;
96+ }
97+ size = 8;
98+ } else {
99+ hl = ((off_t)*(ifoff+0)<<24)|((off_t)*(ifoff+1)<<16)|((off_t)*(ifoff+2)<<8)|((off_t)*(ifoff+3));
100+ /*printf ("size: 0x%8X, %u\n", hl, hl);*/
101+ if (rlen<(hl+12)) {if ((hl+12)>masize) {br=1; pinfo->fm = 2;}break;}
102+ size = (off_t) (hl+12);
103+ /***** crc check *****/
104+ crc = crc_chk = 0;
105+ crc = ((unsigned int)*(ifoff+hl+8)<<24)|((unsigned int)*(ifoff+hl+9)<<16)|((unsigned int)*(ifoff+hl+10)<<8)|((unsigned int)*(ifoff+hl+11));
106+ crc_chk = crc; /* crc code */
107+ /*printf ("crc: 0x%8X\n", crc);*/
108+ if ((crc^crc_chk)!=0) {br=1; pinfo->fm = 1; break;}
109+
110+ if (*(ifoff+4)=='I' && *(ifoff+5)=='H' && *(ifoff+6)=='D' && *(ifoff+7)=='R') {png_chk_ihdl (pinfo, (ifoff+8), hl);}
111+ }
112+ /*if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("size: 0x%4X%\n", size);}*/
113+
114+ if (pinfo->img_x!=0 && pinfo->img_y!=0) {br=1; break;}
115+ rlen -= size; ifoff += size; off_set += size;
116+ }
117+ if (br) {break;}
118+
119+
120+ /*-Get packet info from read data End---------------------------*/
121+ for (i=0; i<rlen; i++) {*(ifpot+i) = *(ifoff+i);}
122+ ifoff = ifpot + rlen;
123+ }
124+ if (pinfo->img_x==0 || pinfo->img_y==0) {pinfo->fm = 1;}
125+ /*-Get packet info from input file and dividing flow End----------*/
126+ free (ifpot);
127+
128+ return ;
129+}
130+
--- trunk/gif_chk.c (nonexistent)
+++ trunk/gif_chk.c (revision 1)
@@ -0,0 +1,94 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
37+# include <stdlib.h>
38+#endif
39+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
40+# include <unistd.h>
41+#endif
42+
43+/*//========================================================================\\*
44+ *|| GIF check ||*
45+ *\\========================================================================//*/
46+/*******************************************************************************
47+ * gif check(gif) *************************************************************/
48+void gif_chk (int fd, picInfo *pinfo)
49+{
50+ unsigned int masize;
51+ unsigned char *ifpot, *ifoff, br;
52+ off_t rlen, off_set;
53+ int i, rrtn;
54+
55+ pinfo->fm = 0;
56+ /*******************************************************************
57+ * Get File size and allocate memory ******************************/
58+ masize = MIN((unsigned int)pinfo->fsize, (unsigned int)MAXMALLOCSIZE);
59+
60+ if (masize<=20) {pinfo->fm = 1; return ;}
61+ if ((ifpot=(unsigned char *)malloc_init (masize))==NULL) {return ;}
62+ ifoff = ifpot;
63+ br = rlen = off_set = 0;
64+
65+
66+ /*-Get packet info from input file and dividing flow Start--------*/
67+ while ((rrtn=read (fd, ifoff, (masize-rlen)))>=0) {
68+ rlen = (off_t)rrtn + rlen;
69+ if (rlen<0) {free (ifpot); return;}
70+ ifoff = ifpot;
71+ if (off_set==0 && rlen==0) {pinfo->fm = 1; br=1; break;}
72+
73+ /*-Get packet info from read data Start-------------------------*/
74+ if (off_set==0) { /* Signature Check */
75+ if (!(*(ifoff+0)==0x47 && *(ifoff+1)==0x49 && *(ifoff+2)==0x46)) {pinfo->fm = 1; return ;}
76+ else if (!((*(ifoff+3)==0x38 && *(ifoff+4)==0x37 && *(ifoff+5)==0x61) ||
77+ (*(ifoff+3)==0x38 && *(ifoff+4)==0x39 && *(ifoff+5)==0x61))) {pinfo->fm = 1; return ;}
78+ pinfo->img_x = (unsigned int)(*(ifoff+7))<<8|(unsigned int)(*(ifoff+6));
79+ pinfo->img_y = (unsigned int)(*(ifoff+9))<<8|(unsigned int)(*(ifoff+8));
80+ if (1 && FLGCHK(flags, FLGDEBUGMODE)) {printf ("img_x: %ld, img_y: %ld\n", pinfo->img_x, pinfo->img_y);}
81+ break;
82+ }
83+
84+ /*-Get packet info from read data End---------------------------*/
85+ for (i=0; i<rlen; i++) {*(ifpot+i) = *(ifoff+i);}
86+ ifoff = ifpot + rlen;
87+ }
88+ if (pinfo->img_x==0 || pinfo->img_y==0) {pinfo->fm = 1;}
89+ /*-Get packet info from input file and dividing flow End----------*/
90+ free (ifpot);
91+
92+ return ;
93+}
94+
--- trunk/Makefile (nonexistent)
+++ trunk/Makefile (revision 1)
@@ -0,0 +1,60 @@
1+#
2+# The MIT License (MIT)
3+#
4+# Copyright (c) 2014 Yuki SAKAI
5+#
6+# Permission is hereby granted, free of charge, to any person obtaining a copy
7+# of this software and associated documentation files (the "Software"), to deal
8+# in the Software without restriction, including without limitation the rights
9+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+# copies of the Software, and to permit persons to whom the Software is
11+# furnished to do so, subject to the following conditions:
12+#
13+# The above copyright notice and this permission notice shall be included in
14+# all copies or substantial portions of the Software.
15+#
16+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+# THE SOFTWARE.
23+################################################################################
24+
25+################################################################################
26+RMFILE = *~ *.core
27+RMFILE +=
28+################################################################################
29+PROG = rempic
30+INSTDIR =
31+################################################################################
32+RMOBJ = rempic.o usage.o option.o stdlib.o open_dir.o remove.o
33+RMOBJ += file_chk.o jpg_chk.o png_chk.o gif_chk.o
34+RMOBJ +=
35+OBJECT = rempic.h macro.h
36+OBJECT += $(RMOBJ)
37+################################################################################
38+# -DDEBUG
39+DMACRO =
40+DOPT = $(DMACRO)
41+DOPT +=
42+LINK =
43+LIB = -L./
44+INCLUDE = -I./
45+CFLAGS = -O2 -Wall $(OPT) $(INCLUDE) $(LIB) $(DOPT)
46+RM = rm -f
47+
48+
49+all: $(PROG)
50+
51+rempic: $(OBJECT)
52+
53+$(PROG): $(OBJECT)
54+ $(CC) $(CFLAGS) -o $@ $(RMOBJ) $(LINK)
55+
56+.c.o:
57+
58+clean:
59+ $(RM) $(PROG) $(RMOBJ) $(RMFILE)
60+
--- trunk/remove.c (nonexistent)
+++ trunk/remove.c (revision 1)
@@ -0,0 +1,220 @@
1+/*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ ******************************************************************************/
24+
25+/*******************************************************************************
26+ * Include ********************************************************************/
27+#if !defined(REMPIC_H__)
28+# include <rempic.h>
29+#endif
30+#if !defined(_STDIO_H_) && !defined(_STDIO_H)
31+# include <stdio.h>
32+#endif
33+#if !defined(_STRING_H_) && !defined(_STRING_H)
34+# include <string.h>
35+#endif
36+#if !defined(_UNISTD_H_) && !defined(_UNISTD_H)
37+# include <unistd.h>
38+#endif
39+#if !defined(_ERRNO_H_) && !defined(_ERRNO_H)
40+# include <errno.h>
41+#endif
42+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
43+# include <sys/types.h>
44+#endif
45+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
46+# include <sys/stat.h>
47+#endif
48+#if !defined(_SYS_FILE_H_) && !defined(_SYS_FILE_H)
49+# include <sys/file.h>
50+#endif
51+#if !defined(_FCNTL_H_) && !defined(_FCNTL_H)
52+# include <fcntl.h>
53+#endif
54+
55+
56+/*******************************************************************************
57+ * read file ******************************************************************/
58+static int read_file (unsigned char *path, picInfo *pinfo)
59+{
60+ int fd;
61+
62+ if ((fd=open ((char *)path, O_RDONLY))==-1) {return 0;}
63+ else if (flock (fd, LOCK_SH)==-1) {close (fd); return 0;}
64+
65+ if (FLGCHK(pinfo->ft, GEXTJPG)) {jpeg_chk (fd, pinfo);}
66+ else if (FLGCHK(pinfo->ft, GEXTJPEG)) {jpeg_chk (fd, pinfo);}
67+ else if (FLGCHK(pinfo->ft, GEXTPNG)) {png_chk (fd, pinfo); }
68+ else if (FLGCHK(pinfo->ft, GEXTGIF)) {gif_chk (fd, pinfo); }
69+
70+ flock (fd, LOCK_UN);
71+ close (fd);
72+
73+ return 1;
74+}
75+
76+/*******************************************************************************
77+ * file extension chk *********************************************************/
78+static unsigned int file_extchk (unsigned char *path)
79+{
80+ unsigned char *pext;
81+ unsigned char ext[10];
82+ (void) memset ((char *)ext, 0, 10);
83+
84+ for (pext = path + strlen ((char *)path) - 1; pext!=path; pext--) {
85+ if (*pext=='.') {break;}
86+ }
87+ if (*pext!='.') {return GEXTERROR;}
88+ else if (strlen ((char *)(pext+1))>9) {return GEXTERROR;}
89+ strncpy ((char *)ext, (char *)(pext+1), 10);
90+ return ext_chk (ext);
91+}
92+
93+/*******************************************************************************
94+ * file size check ************************************************************/
95+static int fsize_chk (off_t size)
96+{
97+ if (FLGCHK(flags, FLGRMUPPERSIZE) && FLGCHK(flags, FLGRMLOWERSIZE)) {
98+ if (UpperSize<=LowerSize) {
99+ if (UpperSize>=size) {return RMCHKREMOVE;}
100+ else if (LowerSize<=size) {return RMCHKREMOVE;}
101+ } else {
102+ if (UpperSize>=size && LowerSize<=size) {return RMCHKREMOVE;}
103+ }
104+ } else if (FLGCHK(flags, FLGRMUPPERSIZE)) {
105+ if (UpperSize>=size) {return RMCHKREMOVE;}
106+ } else if (FLGCHK(flags, FLGRMLOWERSIZE)) {
107+ if (LowerSize<=size) {return RMCHKREMOVE;}
108+ }
109+
110+ return RMCHKINIT;
111+}
112+
113+/*******************************************************************************
114+ * file X check ***************************************************************/
115+static int fx_chk (unsigned long img_x)
116+{
117+ if (FLGCHK(flags, FLGRMUPPERX) && FLGCHK(flags, FLGRMLOWERX)) {
118+ if (UpperX<=LowerX) {
119+ if (UpperX>=img_x) {return RMCHKREMOVE;}
120+ else if (LowerX<=img_x) {return RMCHKREMOVE;}
121+ } else {
122+ if (UpperX>=img_x && LowerX<=img_x) {return RMCHKREMOVE;}
123+ }
124+ } else if (FLGCHK(flags, FLGRMUPPERX)) {
125+ if (UpperX>=img_x) {return RMCHKREMOVE;}
126+ } else if (FLGCHK(flags, FLGRMLOWERX)) {
127+ if (LowerX<=img_x) {return RMCHKREMOVE;}
128+ }
129+
130+ return RMCHKINIT;
131+}
132+
133+/*******************************************************************************
134+ * file Y check ***************************************************************/
135+static int fy_chk (unsigned long img_y)
136+{
137+ if (FLGCHK(flags, FLGRMUPPERY) && FLGCHK(flags, FLGRMLOWERY)) {
138+ if (UpperY<=LowerY) {
139+ if (UpperY>=img_y) {return RMCHKREMOVE;}
140+ else if (LowerY<=img_y) {return RMCHKREMOVE;}
141+ } else {
142+ if (UpperY>=img_y && LowerY<=img_y) {return RMCHKREMOVE;}
143+ }
144+ } else if (FLGCHK(flags, FLGRMUPPERY)) {
145+ if (UpperY>=img_y) {return RMCHKREMOVE;}
146+ } else if (FLGCHK(flags, FLGRMLOWERY)) {
147+ if (LowerY<=img_y) {return RMCHKREMOVE;}
148+ }
149+
150+ return RMCHKINIT;
151+}
152+
153+/*******************************************************************************
154+ * Remove check ***************************************************************/
155+int remove_chk (spname finfo)
156+{
157+ /*****************************************************************************
158+ * if determine remove process(chk!=0), jump remove process ******************
159+ ****************************************************************************/
160+ unsigned int ft;
161+ int chk;
162+ picInfo pinfo;
163+
164+ chk = RMCHKINIT;
165+ ft = GEXTERROR;
166+ (void) memset ((char *)&pinfo, 0, sizeof (picInfo));
167+ pinfo.fsize = finfo.sb.st_size;
168+ /*****************************************************************************
169+ * Analyse filepath name extension ******************************************/
170+ if ((pinfo.ft=file_extchk (finfo.path))==GEXTERROR) {chk = RMCHKSAVE; goto rm_proc;}
171+ else if ((pinfo.ft&TargetFileType)==0) {chk = RMCHKSAVE; goto rm_proc;}
172+ /*****************************************************************************
173+ * File if check ************************************************************/
174+ if ((chk=fsize_chk (pinfo.fsize))!=RMCHKINIT) {goto rm_proc;} /* file size */
175+ else if (!read_file (finfo.path, &pinfo)) {return 0;} /* read file i*/
176+ else if (pinfo.fm) {
177+ if (pinfo.fm==2) {chk = RMCHKSAVE; }
178+ else if (FLGCHK(flags, FLGRMPICBADFILE)) {chk = RMCHKREMOVE;}
179+ else {chk = RMCHKSAVE; }
180+ goto rm_proc;
181+ }
182+ else if (FLGCHK(flags, FLGRMPICBADFILE) && pinfo.fm) {chk = RMCHKSAVE; goto rm_proc;}
183+ else if ((chk=fx_chk (pinfo.img_x))!=RMCHKINIT) {goto rm_proc;} /* file size */
184+ else if ((chk=fy_chk (pinfo.img_y))!=RMCHKINIT) {goto rm_proc;} /* file size */
185+
186+ chk = RMCHKSAVE;
187+ /*****************************************************************************
188+ * Remove Process ***********************************************************/
189+ rm_proc:
190+ if (FLGCHK(flags, FLGDEBUGMODE)) {
191+ /* not remove */
192+ if (chk==RMCHKREMOVE) {fprintf (debugout, "remove: %s\n" , finfo.path);}
193+ else if (chk==RMCHKSAVE) {fprintf (debugout, "save: %s\n" , finfo.path);}
194+ else {fprintf (debugout, "no check: %s\n", finfo.path);}
195+ } else {
196+ if (chk==RMCHKREMOVE && 1) {
197+ errno = 0;
198+ if (unlink ((char *)finfo.path)<0) {
199+ switch (errno) {
200+ case ENOTDIR : fprintf (patherr, "%s: path is include not directory and file name\n", finfo.path); break;
201+ case ENAMETOOLONG: fprintf (patherr, "%s: path name is long\n" , finfo.path); break;
202+ case ENOENT : fprintf (patherr, "%s: no such file\n" , finfo.path); break;
203+ case EACCES : fprintf (patherr, "%s: Can't access\n" , finfo.path); break;
204+ case ELOOP : fprintf (patherr, "%s: Many symbolic link\n" , finfo.path); break;
205+ case EPERM : fprintf (patherr, "%s: Don't permit remove\n" , finfo.path); break;
206+ case EBUSY : fprintf (patherr, "%s: Can't remove for file is busy\n" , finfo.path); break;
207+ case EIO : fprintf (patherr, "%s: I/O error\n" , finfo.path); break;
208+ case EROFS : fprintf (patherr, "%s: file is read only\n" , finfo.path); break;
209+ case EFAULT : fprintf (patherr, "%s: Pointer error\n" , finfo.path); break;
210+ }
211+ fprintf (stdout, "can't rm: %s\n" , finfo.path);
212+ } else {fprintf (stdout, "remove: %s\n" , finfo.path);}
213+ } else {fprintf (stdout, "save : %s\n" , finfo.path);}
214+ }
215+ return 1;
216+}
217+
218+
219+
220+