sweet.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  3. * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
  4. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5. */
  6. /*$Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/sweet.c,v 1.2 1996/07/02 10:15:53 jutta Exp $*/
  7. /* Generate code to unpack a bit array from name:#bits description */
  8. #include <stdio.h>
  9. #include "taste.h"
  10. #include "proto.h"
  11. void write_code P2((s_spex, n_spex), struct spex * s_spex, int n_spex)
  12. {
  13. struct spex * sp = s_spex;
  14. int bits = 8;
  15. int vars;
  16. if (!n_spex) return;
  17. vars = sp->varsize;
  18. while (n_spex) {
  19. if (vars == sp->varsize) {
  20. printf("\t%s = ", sp->var);
  21. } else printf("\t%s |= ", sp->var);
  22. if (vars == bits) {
  23. if (bits == 8) printf( "*c++;\n" );
  24. else printf( "*c++ & 0x%lX;\n",
  25. ~(0xfffffffe << (bits - 1)) );
  26. if (!-- n_spex) break;
  27. sp++;
  28. vars = sp->varsize;
  29. bits = 8;
  30. } else if (vars < bits) {
  31. printf( "(*c >> %d) & 0x%lX;\n",
  32. bits - vars,
  33. ~(0xfffffffe << (vars - 1)));
  34. bits -= vars;
  35. if (!--n_spex) break;
  36. sp++;
  37. vars = sp->varsize;
  38. } else {
  39. /* vars > bits. We're eating lower-all of c,
  40. * but we must shift it.
  41. */
  42. printf( "(*c++ & 0x%X) << %d;\n",
  43. ~(0xfffffffe << (bits - 1)),
  44. vars - bits );
  45. vars -= bits;
  46. bits = 8;
  47. }
  48. }
  49. }