Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for libplaton/utils/strconv/strconv.c between version 1.3 and 1.4

version 1.3, 2003/12/05 18:47:07 version 1.4, 2003/12/11 12:32:50
Line 11 
Line 11 
 */  */
   
 #define BUFSIZE 512  #define BUFSIZE 512
   #if 0
   #  define ARGV0 (strrchr(argv[0], '/') != NULL \
                   ? strrchr(argv[0], '/') + 1 : argv[0])
   #endif
   
 struct charset_struct  struct charset_struct
 {  {
Line 40  int main(int argc, char **argv)
Line 44  int main(int argc, char **argv)
 {  {
         FILE *f;          FILE *f;
         char buf[BUFSIZE], *src_charset, *dest_charset;          char buf[BUFSIZE], *src_charset, *dest_charset;
         register int i, count;          register int i, idx, count, errors;
   #ifndef ARGV0
           char *ARGV0 = strrchr(argv[0], '/') != NULL
                   ? strrchr(argv[0], '/') + 1 : argv[0];
   #endif
   
         if (argc > 1 && ! strcmp(argv[1], "-l")) {          if (argc > 1 && ! strcmp(argv[1], "-l")) {
                 char *tmp_charset = NULL;                  char *tmp_charset = NULL;
Line 59  int main(int argc, char **argv)
Line 67  int main(int argc, char **argv)
         }          }
   
         if (argc < 4) {          if (argc < 4) {
                 fprintf(stderr, "Usage: %s [ -l ] <src_charset> <dest_charset> <filename>\n",                  fprintf(stderr, "Usage: %s [ -l ] <src_charset> <dest_charset> <filename> ...\n",
                                 argv[0]);                                  ARGV0);
                 return 1;                  return 1;
         }          }
   
Line 77  int main(int argc, char **argv)
Line 85  int main(int argc, char **argv)
                 }                  }
         }          }
         if (src_charset == NULL) {          if (src_charset == NULL) {
                 fprintf(stderr, "%s: unknown source charset: %s\n", argv[1]);                  fprintf(stderr, "%s: unknown source charset: %s\n", ARGV0, argv[1]);
                 return 2;                  return 4;
         }          }
   
         /* Destination charset initialization */          /* Destination charset initialization */
Line 93  int main(int argc, char **argv)
Line 101  int main(int argc, char **argv)
                         break;                          break;
                 }                  }
         }          }
         if (src_charset == NULL) {          if (dest_charset == NULL) {
                 fprintf(stderr, "%s: unknown destination charset: %s\n", argv[2]);                  fprintf(stderr, "%s: unknown destination charset: %s\n", ARGV0, argv[2]);
                 return 2;                  return 4;
         }          }
   
         if ((f = fopen(argv[3], "r+")) == NULL) {          if (src_charset == dest_charset) {
                 fprintf(stderr, "%s: can't open file '%s'.\n", argv[0], argv[3]);                  fprintf(stderr, "%s: source and destination charsets are the same\n", ARGV0);
                 return 4;                  return 8;
         }          }
   
         i = -1;          /*
         count = 0;           * Main loop
            */
   
           for (errors = 0, idx = 3; idx < argc; idx++) {
   
         do {                  if ((f = fopen(argv[idx], "r+")) == NULL) {
                 count = fread(buf, sizeof(char), BUFSIZE - 1, f);                          fprintf(stderr, "%s: can't open file '%s'\n", ARGV0, argv[3]);
                 buf[count] = '\0';                          errors++;
                           continue;
                   }
   
                 strconv(buf, src_charset, dest_charset);                  i = -1;
                   count = 0;
   
                 fseek(f, -count, SEEK_CUR);                  do {
                           count = fread(buf, sizeof(char), BUFSIZE - 1, f);
                           buf[count] = '\0';
   
                           strconv(buf, src_charset, dest_charset);
   
                           fseek(f, -count, SEEK_CUR);
   
                           if (count != fwrite(buf, sizeof(char), count, f)) {
                                   fclose(f);
                                   fprintf(stderr, "%s: file '%s' write error\n", ARGV0, argv[idx]);
                                   i = -1;
                                   break;
                           }
   
                 if (count != fwrite(buf, sizeof(char), count, f)) {                          i++;
                         fclose(f);                  } while (count == BUFSIZE - 1);
                         fprintf(stderr, "%s: write error\n", argv[0]);  
                         return 128;  
                 }  
   
                 i++;                  fclose(f);
         } while (count == BUFSIZE - 1);  
   
         fclose(f);                  if (i < 0) {
                           errors++;
                           continue;
                   }
   
         printf("%s: file '%s' with size %ld successfully converted\n",                  printf("%s: file '%s' with size %ld successfully converted\n",
                                                         argv[0], argv[3],                                  ARGV0, argv[idx],
                                                         (long) (i * (BUFSIZE - 1)) + (long) count);                                  (long) (i * (BUFSIZE - 1)) + (long) count);
           }
   
         return 0;          return errors ? 2 : 0;
 }  }
   

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top