home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / misc / WHDLoad_dev.lha / WHDLoad / Src / gci / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-20  |  2.4 KB  |  120 lines

  1. /*****************************************************************************
  2. ;  :Module.    misc.c
  3. ;  :Author.    Bert Jahn
  4. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  5. ;  :Version.    $Id: misc.c 1.3 2002/02/19 21:15:21 wepl Exp wepl $
  6. ;  :History.    28.03.00 extracted from whdloadgci.c
  7. ;  :Copyright.    All Rights Reserved
  8. ;  :Language.    C
  9. ;  :Translator.    GCC
  10. ****************************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #include "WHDLoadGCI.h"
  16.  
  17. /****************************************************************************/
  18.  
  19. /*
  20.  *    create string containing right aligned hexadecimal representation of value
  21.  */
  22. STRPTR val2hexr(ULONG value) {
  23.     static char s[12];
  24.     sprintf(s,"\33r%s",val2hex(value));
  25.     return s;
  26. }
  27.  
  28. /*
  29.  *    create string containing right aligned hexadecimal representation of value
  30.  */
  31. STRPTR val2hex64r(ULONG value1, ULONG value2) {
  32.     static char s[20];
  33.     if (value1) {
  34.         sprintf(s,"\33r$%x%08x",value1,value2);
  35.         return s;
  36.     } else {
  37.         return val2hexr(value2);
  38.     }
  39. }
  40.  
  41. /*
  42.  *    return string containing hexadecimal representation of value
  43.  */
  44. STRPTR val2hex(ULONG value) {
  45.     static char s[10];
  46.     sprintf(s,value < 16 ? "%d" : "$%x",value);
  47.     return s;
  48. }
  49.  
  50. /*
  51.  *    create string for "String"
  52.  */
  53. STRPTR val2hex4(UWORD val) {
  54.     static char s[6];
  55.     if (val < 16) {
  56.         sprintf(s,"%d",val);
  57.     } else {
  58.         sprintf(s,"$%x",val);
  59.     }
  60.     return s;
  61. }
  62. STRPTR val2hex8(ULONG val) {
  63.     static char s[10];
  64.     if (val < 16) {
  65.         sprintf(s,"%ld",val);
  66.     } else {
  67.         sprintf(s,"$%lx",val);
  68.     }
  69.     return s;
  70. }
  71. /*
  72.  *    create string for "Text"
  73.  */
  74. STRPTR val2hex1t(UBYTE val) {
  75.     static char s[3];
  76.     sprintf(s,"\33r%ld",val);
  77.     return s;
  78. }
  79. STRPTR val2hex4t(UWORD val) {
  80.     static char s[6];
  81.     if (val < 16) {
  82.         sprintf(s,"\33r%d",val);
  83.     } else {
  84.         sprintf(s,"\33r$%x",val);
  85.     }
  86.     return s;
  87. }
  88. STRPTR val2hex8t(ULONG val) {
  89.     static char s[10];
  90.     if (val < 16) {
  91.         sprintf(s,"\33r%ld",val);
  92.     } else {
  93.         sprintf(s,"\33r$%lx",val);
  94.     }
  95.     return s;
  96. }
  97. /*
  98.  *    set contents of "String"
  99.  */
  100. void sethex4(APTR gad, UWORD val) {
  101.     set(gad,MUIA_String_Contents,val2hex4(val));
  102. }
  103. void sethex8(APTR gad, ULONG val) {
  104.     set(gad,MUIA_String_Contents,val2hex8(val));
  105.     set(gad,MUIA_Text_Contents,val2hex8(val));
  106. }
  107. /*
  108.  *    set contents of "Text"
  109.  */
  110. void sethex1t(APTR gad, UBYTE val) {
  111.     set(gad,MUIA_Text_Contents,val2hex1t(val));
  112. }
  113. void sethex4t(APTR gad, UWORD val) {
  114.     set(gad,MUIA_Text_Contents,val2hex4t(val));
  115. }
  116. void sethex8t(APTR gad, ULONG val) {
  117.     set(gad,MUIA_Text_Contents,val2hex8t(val));
  118. }
  119.  
  120.