home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / wais / config.c next >
Encoding:
C/C++ Source or Header  |  1995-05-09  |  2.2 KB  |  115 lines

  1. /* config.c: 
  2.  *  creates a header file with details on a machine's representation of 
  3.  *  numbers, alignment requirements, etc, etc.
  4.  */
  5.  
  6. #include <stdio.h>
  7.  
  8. #define SHORT_CODE 0
  9. #define INT_CODE   1
  10. #define LONG_CODE  2
  11. #define CHAR_CODE  3
  12.  
  13. typedef struct _short_test {
  14.   char c;
  15.   unsigned short s;
  16. } short_test;
  17.  
  18. typedef struct _long_test {
  19.   char c;
  20.   unsigned long l;
  21. } long_test;
  22.  
  23. typedef struct _int_test {
  24.   char c;
  25.   unsigned int i;
  26. } int_test;
  27.  
  28.  
  29. int main() 
  30. {
  31.  
  32.   short_test st;
  33.   long_test lt;
  34.   int_test it;
  35.  
  36.   int four_byte;
  37.   int two_byte;
  38.   int one_byte;
  39.  
  40.   unsigned int i,*ip;
  41.   unsigned long l,*lp;
  42.   unsigned short s,*sp;
  43.   char c;
  44.   unsigned char *cp;
  45.  
  46.  
  47.   if(sizeof(char) == 1) {
  48.     printf("#define ONE_BYTE char\n");
  49.     one_byte = CHAR_CODE;
  50.   } else {
  51.     fprintf(stderr,
  52.         "Error: chars are %d bytes long. Can't define ONE_BYTE\n",sizeof(char));
  53.     exit(1);
  54.   }
  55.  
  56.   if(sizeof(int) == 2) {
  57.     printf("#define TWO_BYTE int\n");
  58.     two_byte = INT_CODE;
  59.   } else {
  60.     if(sizeof(short) == 2) {
  61.       printf("#define TWO_BYTE short\n");
  62.       two_byte = SHORT_CODE;
  63.     } else {
  64.       fprintf(stderr,"Error: don't know how to define TWO_BYTE\n");
  65.       exit(1);
  66.     }
  67.   }
  68.  
  69.   if(sizeof(int) == 4) {
  70.     printf("#define FOUR_BYTE int\n");
  71.     four_byte = INT_CODE;
  72.   } else {
  73.     if(sizeof(long) == 4) {
  74.       printf("#define FOUR_BYTE long\n");
  75.       four_byte = LONG_CODE;
  76.      } else {
  77.        fprintf(stderr,"Error: don't know how to define FOUR_BYTE\n");
  78.      }
  79.   }
  80.     
  81.       
  82.   if(two_byte == SHORT_CODE) {
  83.     printf("#define TWO_BYTE_ALIGN %d\n",(int)(&st.s)-(int)(&st.c));
  84.   } else {
  85.     if (two_byte == INT_CODE) {
  86.       printf("#define TWO_BYTE_ALIGN %d\n",(int)(&it.i)-(int)(&it.c));
  87.     }
  88.   }
  89.   if(four_byte == INT_CODE) {
  90.     printf("#define FOUR_BYTE_ALIGN %d\n",(int)(&it.i)-(int)(&it.c));
  91.   } else {
  92.     if(four_byte == LONG_CODE) {
  93.       printf("#define FOUR_BYTE_ALIGN %d\n",(int)(<.l)-(int)(<.c));
  94.     }
  95.   }
  96.  
  97.   l=0xdeadbeef;
  98.  
  99.   
  100.   cp=(unsigned char*)&l;
  101.  
  102.   if(*cp == 0xde) {
  103.     printf("#define BIG_ENDIAN\n");
  104.   } else {
  105.     if(*cp == 0xef) {
  106.       printf("#define LITTLE_ENDIAN\n");
  107.       } else {
  108.     fprintf(stderr,"Error: can't find out byte order\n");
  109.     exit(1);
  110.       }
  111.   }
  112.   exit(0);
  113. }
  114.   
  115.