home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / as / src / c / mkendian < prev    next >
Encoding:
Text File  |  1992-08-28  |  1.2 KB  |  54 lines

  1. /*
  2.  * make endiandef.h include file for this host
  3.  * 
  4.  * Andy Duplain, August 1992.
  5.  */
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8.  
  9. union {
  10.   int i;
  11.   char c[4];
  12. } word;
  13.  
  14. int main(void)
  15. {
  16.   FILE *ofp;
  17.   register i;
  18.  
  19.   if (sizeof(int) != 4) {
  20.     fprintf(stderr, "Sorry pal, you cannot use this program on this host (sizeof(int) != 4)\n");
  21.     exit(1);
  22.   }
  23. #ifdef UNIX
  24.   ofp = fopen("endiandef.h", "w");
  25. #else
  26.   ofp = fopen("h.endiandef", "w");
  27. #endif
  28.   if (!ofp) {
  29.     perror("endiandef.h");
  30.     exit(1);
  31.   }
  32.   word.i = 0x01020304;
  33.  
  34.   fprintf(ofp, "/*\n * endiandef.h\tdefines for local host byte sex.\n */\n");
  35.   fprintf(ofp, "#ifndef __ENDIANDEF_H\n#define __ENDIANDEF_H\n");
  36.   for (i = 0; i < 4; i++) {
  37.     fprintf(ofp, "#define BYTE%dSHIFT %d\n", i, (word.c[i] - 1) * 8);
  38.   }
  39.  
  40.   if (word.c[0] == 1 && word.c[1] == 2 && word.c[2] == 3 && word.c[3] == 4)
  41.     fprintf(ofp, "#define BIGENDIAN\n");
  42.   else
  43.     fprintf(ofp, "#undef BIGENDIAN\n");
  44.  
  45.   if (word.c[0] == 4 && word.c[1] == 3 && word.c[2] == 2 && word.c[3] == 1)
  46.     fprintf(ofp, "#define LITTLEENDIAN\n");
  47.   else
  48.     fprintf(ofp, "#undef LITTLEENDIAN\n");
  49.  
  50.   fprintf(ofp, "#endif /* __ENDIANDEF_H */\n");
  51.   fclose(ofp);
  52.   exit(0);
  53. }
  54.