home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / IFF2PBM.ZIP / APAL2BIN.C < prev    next >
C/C++ Source or Header  |  1994-01-10  |  2KB  |  89 lines

  1. /*****************************************************************************
  2. **  Listing :   APAL2BIN.C                                                  **
  3. **  Funtion :   Convert ASCII .PAL file to binary palette file.             **
  4. **  Author  :   JuHu (cn1.serv2.inf.tu-dresden.de)                          **
  5. **                                                                          **
  6. **  (C) 27/9/1993 ViNaSoft ***************************************************/
  7.  
  8.  
  9. #include <stdio.h>
  10. #include <conio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14.  
  15. char  inname[80];
  16. char  outname[80];
  17. FILE   *in, *out;
  18.  
  19. void process_args (int argc, char *argv[]);
  20. void split(char *satz);
  21.  
  22. void main(int argc, char *argv[])
  23. {   char   string[256];
  24.     char   *temp;
  25.     int    i=0;
  26.  
  27.     process_args (argc, argv);   /* Handle the command line args */
  28.  
  29.     if ((in = fopen (inname, "rt")) == NULL) {
  30.     printf ("Cannot open input file %s!\n", inname);
  31.     exit (1);
  32.     }
  33.  
  34.     if ((out = fopen (outname, "wb")) == NULL) {
  35.     printf ("Cannot open output file %s!\n", outname);
  36.     exit (1);
  37.     }
  38.     fgets(string, 256, in);
  39.     if(!strstr(string,"PAL")){
  40.     printf("%s is'nt .PAL file !\n",inname);
  41.     exit(1);
  42.     }
  43.     fgets(string, 256, in);
  44.     printf("Input  :   %s\n",inname);
  45.     printf("Output :   %s\n",outname);
  46.     printf("Colors :   %d\n\n",atoi(string));
  47.     printf("Please wait...\n");
  48.  
  49.     while (fgets (string, 256, in) != NULL) {
  50.       temp = string;
  51.       for(i=0;i<3;i++){
  52.         split(temp);
  53.         fputc(atoi(temp)/4,out);
  54.         temp+=strlen(temp)+1;
  55.       }
  56.     }
  57.  
  58.    fclose(in);
  59.    fclose(out);
  60.    printf("Done.\n");
  61. }
  62.  
  63. void process_args (int argc, char *argv[])
  64. {
  65.     int i;
  66.     printf("APAL2BIN 1.1 (C) 27.09.93 ViNaSoft by JuHu:-)\n");
  67.     printf("ASCII .PAL file -> binary palette file. \n\n");
  68.  
  69.     if (argc < 2) {
  70.         printf("Usage  : APAL2BIN <infile> <outfile>\n");
  71.         exit(1);
  72.     }
  73.  
  74.     strcpy (inname, argv[1]);
  75.     strcpy (outname,argv[2]);
  76. }
  77.  
  78. void split(char *satz)
  79. {
  80.   while(*satz==' ') satz++;
  81.   while(*satz)
  82.   { if(*satz==' ')
  83.       *satz = '\0';
  84.     else
  85.      satz++;
  86.   }
  87. }
  88.  
  89.