|
Lines 1-201
Link Here
|
| 1 |
--- src/iat.c.orig 2008-11-02 05:00:31.000000000 +0300 |
|
|
| 2 |
+++ src/iat.c 2008-11-02 05:01:16.000000000 +0300 |
| 3 |
@@ -14,12 +14,20 @@ |
| 4 |
along with this program; if not, write to the |
| 5 |
Free Software Foundation, Inc., |
| 6 |
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 7 |
-*/ |
| 8 |
+ */ |
| 9 |
|
| 10 |
/* Support Large File */ |
| 11 |
|
| 12 |
+/* |
| 13 |
+ * Modified by Dmitry E. Oboukhov <dimka@avanto.org> |
| 14 |
+ * [+] Use 'getopt' function; |
| 15 |
+ * [+] Use STDOUT as output file (if not defined); |
| 16 |
+ * [*] Fix percent output. |
| 17 |
+ */ |
| 18 |
+ |
| 19 |
#define _FILE_OFFSET_BITS 64 |
| 20 |
|
| 21 |
+#include <unistd.h> |
| 22 |
#include <getopt.h> |
| 23 |
#include <stdio.h> |
| 24 |
#include <stdlib.h> |
| 25 |
@@ -29,6 +37,12 @@ |
| 26 |
#define VERSION "0.1.3" |
| 27 |
#define BLOCK_ISO_CD 2048 |
| 28 |
|
| 29 |
+ |
| 30 |
+#define OPTIONS_LIST "h" |
| 31 |
+ |
| 32 |
+ |
| 33 |
+static char *input_file=0, *output_file=0; |
| 34 |
+ |
| 35 |
/* Signature for Image ISO-9660 */ |
| 36 |
const char ISO_9660_START[] = { |
| 37 |
(char) 0x01, |
| 38 |
@@ -91,7 +105,7 @@ |
| 39 |
}; |
| 40 |
|
| 41 |
|
| 42 |
-long img_size; |
| 43 |
+off_t img_size; |
| 44 |
int img_detect = 2; |
| 45 |
|
| 46 |
int img_header = 0; |
| 47 |
@@ -106,35 +120,49 @@ |
| 48 |
|
| 49 |
int previous_percent=-1; |
| 50 |
void main_percent (int percent_bar) |
| 51 |
-// Prints a progress bar, takes a percentage as argument. |
| 52 |
+ // Prints a progress bar, takes a percentage as argument. |
| 53 |
{ |
| 54 |
//int progress_bar, progress_space; |
| 55 |
|
| 56 |
if (percent_bar==previous_percent) return; // Nothing changed, don't waste CPU cycles. |
| 57 |
|
| 58 |
- printf("%3d%% [:%.*s>%.*s:]\r",percent_bar,percent_bar/5,"====================", |
| 59 |
- 20-(percent_bar/5)," "); |
| 60 |
- |
| 61 |
+ if (isatty(fileno(stderr))) |
| 62 |
+ { |
| 63 |
+ fprintf(stderr, |
| 64 |
+ "\r%3d%% [:%.*s>%.*s:]", |
| 65 |
+ percent_bar, |
| 66 |
+ percent_bar/5, |
| 67 |
+ "====================", |
| 68 |
+ 20-(percent_bar/5), |
| 69 |
+ " "); |
| 70 |
+ } |
| 71 |
+ else |
| 72 |
+ { |
| 73 |
+ if (previous_percent==-1) fprintf(stderr, "Working "); |
| 74 |
+ if ((percent_bar/5)*5==percent_bar) fprintf(stderr, "."); |
| 75 |
+ } |
| 76 |
+ previous_percent=percent_bar; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
-void |
| 81 |
+ void |
| 82 |
usage () |
| 83 |
{ |
| 84 |
- |
| 85 |
- printf ("Web : http://developer.berlios.de/projects/iat\n"); |
| 86 |
- printf ("Email : salvatore.santagati@gmail.com\n"); |
| 87 |
- printf ("Irc : irc.freenode.net #ignus\n"); |
| 88 |
- printf ("Note : What's My Age Again? \n"); |
| 89 |
- |
| 90 |
- printf ("Usage :\n"); |
| 91 |
- printf ("iat OPTIONS[inputfile] OPTIONS[outputfile]\n\n"); |
| 92 |
-// printf ("OPTIONS\n"); |
| 93 |
-// printf ("\t-i --iso Generate iso image from bin image\n"); |
| 94 |
-// printf ("\t-l --log Generate log for debug image\n"); |
| 95 |
-// printf ("\t-v --verbose Print verbose messages\n"); |
| 96 |
-// printf ("\t-o --output filename Write output to file\n"); |
| 97 |
- printf ("\t-h --help Display this notice\n\n"); |
| 98 |
+ fprintf (stderr, "Web : http://developer.berlios.de/projects/iat\n"); |
| 99 |
+ fprintf (stderr, "Email : salvatore.santagati@gmail.com\n"); |
| 100 |
+ fprintf (stderr, "Irc : irc.freenode.net #ignus\n\n"); |
| 101 |
+ |
| 102 |
+ fprintf (stderr, "Usage : "); |
| 103 |
+ fprintf (stderr, "iat input_file [output_file.iso]\n\n"); |
| 104 |
+ fprintf (stderr, "\tIf output file name is not defined, \n" |
| 105 |
+ "\tthen stdout will be used instead.\n"); |
| 106 |
+ // printf ("OPTIONS\n"); |
| 107 |
+ // printf ("\t-i --iso Generate iso image from bin image\n"); |
| 108 |
+ // printf ("\t-l --log Generate log for debug image\n"); |
| 109 |
+ // printf ("\t-v --verbose Print verbose messages\n"); |
| 110 |
+ // printf ("\t-o --output filename Write output to file\n"); |
| 111 |
+ fprintf (stderr, "\nOptions :\n"); |
| 112 |
+ fprintf (stderr, "\t-h Display this notice\n\n"); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
@@ -142,15 +170,15 @@ |
| 117 |
int image_convert() |
| 118 |
{ |
| 119 |
|
| 120 |
- long source_length, i; |
| 121 |
+ off_t source_length, i; |
| 122 |
char buf[2448]; |
| 123 |
|
| 124 |
|
| 125 |
- fseek (fsource, 0L, SEEK_END); |
| 126 |
- source_length = (ftell (fsource) - img_offset) / img_size_sector; |
| 127 |
+ fseeko (fsource, 0L, SEEK_END); |
| 128 |
+ source_length = (ftello (fsource) - img_offset) / img_size_sector; |
| 129 |
|
| 130 |
|
| 131 |
- fseek (fsource, img_offset, SEEK_SET); |
| 132 |
+ fseeko (fsource, img_offset, SEEK_SET); |
| 133 |
|
| 134 |
{ |
| 135 |
for (i = 0; i < source_length; i++) |
| 136 |
@@ -158,26 +186,29 @@ |
| 137 |
{ |
| 138 |
main_percent(i*100/source_length); |
| 139 |
|
| 140 |
- fseek (fsource, img_header, SEEK_CUR); |
| 141 |
+ fseeko (fsource, img_header, SEEK_CUR); |
| 142 |
if (fread (buf, sizeof (char), BLOCK_ISO_CD, fsource)); |
| 143 |
|
| 144 |
else |
| 145 |
{ |
| 146 |
- printf ("%s\n", strerror (errno)); |
| 147 |
+ fprintf (stderr, "%s\n", strerror (errno)); |
| 148 |
exit (EXIT_FAILURE); |
| 149 |
}; |
| 150 |
if (fwrite (buf, sizeof (char), BLOCK_ISO_CD, fdest)); |
| 151 |
|
| 152 |
else |
| 153 |
{ |
| 154 |
- printf ("%s\n", strerror (errno)); |
| 155 |
+ fprintf (stderr, "%s\n", strerror (errno)); |
| 156 |
exit (EXIT_FAILURE); |
| 157 |
}; |
| 158 |
- fseek (fsource, img_ecc, SEEK_CUR); |
| 159 |
+ fseeko (fsource, img_ecc, SEEK_CUR); |
| 160 |
} |
| 161 |
} |
| 162 |
- printf ("100%% [:=====================:]\n"); |
| 163 |
-return 0; |
| 164 |
+ if (isatty(fileno(stderr))) |
| 165 |
+ fprintf (stderr, "\rDone \n"); |
| 166 |
+ else |
| 167 |
+ fprintf (stderr, " Done\n"); |
| 168 |
+ return 0; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
@@ -196,23 +227,23 @@ |
| 173 |
int raw_check = 0; |
| 174 |
|
| 175 |
|
| 176 |
- fseek(fsource, 0L, SEEK_END); |
| 177 |
- img_size = (((ftell(fsource))) / 8); |
| 178 |
+ fseeko(fsource, 0L, SEEK_END); |
| 179 |
+ img_size = (((ftello(fsource))) / 8); |
| 180 |
for (i = 0; img_detect == 2; i = i + 1) |
| 181 |
{ |
| 182 |
- fseek(fsource, 0L, SEEK_SET); |
| 183 |
- fseek(fsource, i, SEEK_CUR); |
| 184 |
+ fseeko(fsource, 0L, SEEK_SET); |
| 185 |
+ fseeko(fsource, i, SEEK_CUR); |
| 186 |
fread(buf, sizeof(char), 8, fsource); |
| 187 |
fread(raw, sizeof(char), 12, fsource); |
| 188 |
|
| 189 |
if (!memcmp(ISO_9660_START, buf, 8)) |
| 190 |
{ |
| 191 |
- printf("Detect Signature ISO9660 START at %d\n", i); |
| 192 |
+ fprintf(stderr, "Detect Signature ISO9660 START at %d\n", i); |
| 193 |
if (block_image_start == 0) block_image_start = i ; |
| 194 |
} |
| 195 |
if (!memcmp(ISO_9660, buf, 8)) |
| 196 |
{ |
| 197 |
- printf("Detect Signature ISO9660 at %d\n", i); |
| 198 |
+ fprintf(stderr, "Detect Signature ISO9660 at %d\n", i); |
| 199 |
if (block_image_end == 0) |
| 200 |
{ |
| 201 |
block_image_end = i; |