Date: Thu, 29 Mar 2007 14:20:11 GMT From: Dmitry Marakasov <amdmi3@amdmi3.ru> To: freebsd-ports-bugs@FreeBSD.org Subject: Re: ports/111010: [NEW PORT] sysutils/iat: Converter of many types of CD-ROM image file formats into ISO-9660 Message-ID: <200703291420.l2TEKB5S035040@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR ports/111010; it has been noted by GNATS. From: Dmitry Marakasov <amdmi3@amdmi3.ru> To: bug-followup@FreeBSD.org Cc: Subject: Re: ports/111010: [NEW PORT] sysutils/iat: Converter of many types of CD-ROM image file formats into ISO-9660 Date: Thu, 29 Mar 2007 18:19:33 +0400 --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=koi8-r Content-Disposition: inline * Dmitry Marakasov (amdmi3@amdmi3.ru) wrote: Here's also patch from berlios bug tracker, which adds some more functionality. I guess it'll be included into next release of iat, but I think it would be wise to add it to the port for now, just like guys from Debian did. The file attached should be placed under iat/files/ -- Best regards, Dmitry Marakasov mailto:amdmi3@amdmi3.ru --mP3DRpeJDSE+ciuQ Content-Type: text/x-csrc; charset=koi8-r Content-Disposition: attachment; filename="patch-src-iat.c" --- src/iat.c 2007-03-08 18:39:49.000000000 +0300 +++ src/iat.c.new 2007-03-28 16:34:58.000000000 +0400 @@ -14,12 +14,20 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ + */ /* Support Large File */ +/* + * Modified by Dmitry E. Oboukhov <dimka@avanto.org> + * [+] Use 'getopt' function; + * [+] Use STDOUT as output file (if not defined); + * [*] Fix percent output. + */ + #define _FILE_OFFSET_BITS 64 +#include <unistd.h> #include <getopt.h> #include <stdio.h> #include <stdlib.h> @@ -29,6 +38,12 @@ #define VERSION "0.1.3" #define BLOCK_ISO_CD 2048 + +#define OPTIONS_LIST "h" + + +static char *input_file=0, *output_file=0; + /* Signature for Image ISO-9660 */ const char ISO_9660_START[] = { (char) 0x01, @@ -106,35 +121,49 @@ int previous_percent=-1; void main_percent (int percent_bar) -// Prints a progress bar, takes a percentage as argument. + // Prints a progress bar, takes a percentage as argument. { //int progress_bar, progress_space; if (percent_bar==previous_percent) return; // Nothing changed, don't waste CPU cycles. - printf("%3d%% [:%.*s>%.*s:]\r",percent_bar,percent_bar/5,"====================", - 20-(percent_bar/5)," "); - + if (isatty(fileno(stderr))) + { + fprintf(stderr, + "\r%3d%% [:%.*s>%.*s:]", + percent_bar, + percent_bar/5, + "====================", + 20-(percent_bar/5), + " "); + } + else + { + if (previous_percent==-1) fprintf(stderr, "Working "); + if ((percent_bar/5)*5==percent_bar) fprintf(stderr, "."); + } + previous_percent=percent_bar; } -void + void usage () { - - printf ("Web : http://developer.berlios.de/projects/iat\n"); - printf ("Email : salvatore.santagati@gmail.com\n"); - printf ("Irc : irc.freenode.net #ignus\n"); - printf ("Note : What's My Age Again? \n"); - - printf ("Usage :\n"); - printf ("iat OPTIONS[inputfile] OPTIONS[outputfile]\n\n"); -// printf ("OPTIONS\n"); -// printf ("\t-i --iso Generate iso image from bin image\n"); -// printf ("\t-l --log Generate log for debug image\n"); -// printf ("\t-v --verbose Print verbose messages\n"); -// printf ("\t-o --output filename Write output to file\n"); - printf ("\t-h --help Display this notice\n\n"); + fprintf (stderr, "Web : http://developer.berlios.de/projects/iat\n"); + fprintf (stderr, "Email : salvatore.santagati@gmail.com\n"); + fprintf (stderr, "Irc : irc.freenode.net #ignus\n\n"); + + fprintf (stderr, "Usage : "); + fprintf (stderr, "iat input_file [output_file.iso]\n\n"); + fprintf (stderr, "\tIf output file name is not defined, \n" + "\tthen stdout will be used instead.\n"); + // printf ("OPTIONS\n"); + // printf ("\t-i --iso Generate iso image from bin image\n"); + // printf ("\t-l --log Generate log for debug image\n"); + // printf ("\t-v --verbose Print verbose messages\n"); + // printf ("\t-o --output filename Write output to file\n"); + fprintf (stderr, "\nOptions :\n"); + fprintf (stderr, "\t-h Display this notice\n\n"); } @@ -163,21 +192,24 @@ else { - printf ("%s\n", strerror (errno)); + fprintf (stderr, "%s\n", strerror (errno)); exit (EXIT_FAILURE); }; if (fwrite (buf, sizeof (char), BLOCK_ISO_CD, fdest)); else { - printf ("%s\n", strerror (errno)); + fprintf (stderr, "%s\n", strerror (errno)); exit (EXIT_FAILURE); }; fseek (fsource, img_ecc, SEEK_CUR); } } - printf ("100%% [:=====================:]\n"); -return 0; + if (isatty(fileno(stderr))) + fprintf (stderr, "\rDone \n"); + else + fprintf (stderr, " Done\n"); + return 0; } @@ -207,12 +239,12 @@ if (!memcmp(ISO_9660_START, buf, 8)) { - printf("Detect Signature ISO9660 START at %d\n", i); + fprintf(stderr, "Detect Signature ISO9660 START at %d\n", i); if (block_image_start == 0) block_image_start = i ; } if (!memcmp(ISO_9660, buf, 8)) { - printf("Detect Signature ISO9660 at %d\n", i); + fprintf(stderr, "Detect Signature ISO9660 at %d\n", i); if (block_image_end == 0) { block_image_end = i; @@ -220,9 +252,11 @@ } img_detect++; - } if (!memcmp(ISO_9660_END, buf, 8)) + } + + if (!memcmp(ISO_9660_END, buf, 8)) { - printf("Detect Signature ISO9660 END at %d\n", i); + fprintf(stderr, "Detect Signature ISO9660 END at %d\n", i); if (block_image_end == 0) { block_image_end = i; @@ -234,7 +268,7 @@ if (!memcmp(SYNC_RAW_2, buf, 8)) { - printf("Detect Signature RAW 2 at %d\n", i); + fprintf(stderr, "Detect Signature RAW 2 at %d\n", i); if (raw_2_check == 0) { img_header = img_header + 8; @@ -244,7 +278,7 @@ } if (!memcmp(SYNC_RAW, raw, 12)) { - printf("Detect Signature RAW at %d\n", i); + fprintf(stderr, "Detect Signature RAW at %d\n", i); if (raw_check == 0) { img_header = img_header + 16; @@ -256,7 +290,7 @@ if ((img_size * 8) <= i) { img_detect = -1; - printf("Image is broken\n"); + fprintf(stderr, "Image is broken\n"); return 0; } } @@ -318,48 +352,90 @@ img_offset = block_image_start - block_image * 16 - img_header; - printf("\n Image offset start at %d", img_offset); - printf("\n Sector header %d bit", img_header); - printf("\n Sector ECC %d bit", img_ecc); - printf("\n Block %d\n", block_image); + fprintf(stderr, "\n Image offset start at %d", img_offset); + fprintf(stderr, "\n Sector header %d bit", img_header); + fprintf(stderr, "\n Sector ECC %d bit", img_ecc); + fprintf(stderr, "\n Block %d\n", block_image); return 1; +} + + +void parse_options(int argc, char ** argv) +{ + int c; + + for (c=getopt(argc, argv, OPTIONS_LIST); + c!=-1; + c=getopt(argc, argv, OPTIONS_LIST)) + { + switch(c) + { + case 'h': + usage(); + exit(0); + + case '?': + break; + + default: + fprintf (stderr, "?? getopt returned character code 0%o ??\n", c); + + } + } + + if (argc-optind<1 || argc-optind>2) + { + usage(); + exit(EXIT_FAILURE); } + input_file=argv[optind]; + if (argc-optind==2) output_file=argv[optind+1]; +} + + int main(int argc, char **argv) { + fprintf(stderr, + "Iso9660 Analyzer Tool v%s by Salvatore Santagati\n", VERSION); + fprintf(stderr, "Licensed under GPL v2 or later\n\n"); - printf("Iso9660 Analyzer Tool v%s by Salvatore Santagati\n", VERSION); - printf("Licensed under GPL v2 or later\n"); - + parse_options(argc, argv); - if ((fsource = fopen(argv[1], "rb")) != NULL) + if ((fsource = fopen(input_file, "rb")) != NULL) { if (image_detection() == 0) - printf("This image is not CD IMAGE\n"); - else if (argc > 2) { - if ((fdest = fopen(argv[2],"wb")) != NULL) - { - image_convert(); - fclose(fdest); + fprintf(stderr, "This image is not CD IMAGE\n"); + exit(EXIT_FAILURE); } else { - printf("%s\n", strerror(errno)); + if (output_file) + { + if (!(fdest = fopen(output_file, "wb"))) + { + fprintf(stderr, "%s\n", strerror(errno)); usage(); + exit(EXIT_FAILURE); } } - + else + { + fdest=stdout; + } + image_convert(); + fclose(fdest); + } } else { - printf("%s\n", strerror(errno)); + fprintf(stderr, "%s\n", strerror(errno)); usage(); exit(EXIT_FAILURE); } - return 1; - + return 0; } --mP3DRpeJDSE+ciuQ--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200703291420.l2TEKB5S035040>