home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OBJASM.ZIP / OUGET.C < prev    next >
Text File  |  1990-02-25  |  1KB  |  91 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "o.h"
  4.  
  5. unsigned char get_byte()
  6. {
  7.     int     ch;
  8.  
  9.     ch = fgetc( o_file );
  10.     if( ch == EOF ) {
  11.         fprintf(stderr, "%s: Premature end of file\n");
  12.         exit(3);
  13.     }
  14.     return( (unsigned char)ch );
  15. }
  16.  
  17. int get_int()
  18. {
  19.     int    ch;
  20.  
  21.     ch = get_byte();
  22.     ch += get_byte() << 8;
  23.  
  24.     return( ch );
  25. }
  26.  
  27. unsigned int get_word()
  28. {
  29.     unsigned int    ch;
  30.  
  31.     ch = get_byte();
  32.     ch += get_byte() << 8;
  33.  
  34.     return( ch );
  35. }
  36.  
  37. unsigned long get_long()
  38. {
  39.     unsigned long   ch;
  40.  
  41.     ch = get_byte();
  42.     ch += get_byte() << 8;
  43.     ch += get_byte() << 16;
  44.     ch += get_byte() << 24;
  45.     return( ch );
  46. }
  47.  
  48. void get_str( length, dest_string )
  49.     int     length;
  50.     char    *dest_string;
  51. {
  52.     int     count;
  53.  
  54.     count = length;
  55.  
  56.     while( count ) {
  57.       *dest_string++ = get_byte();
  58.       --count;
  59.     }
  60.     *dest_string = '\0';
  61. }
  62.  
  63.  
  64. int get_name( dest_string )
  65.     char    *dest_string;
  66. {
  67.     int     length;
  68.  
  69.     length = get_byte();
  70.     get_str( length, dest_string );
  71.  
  72.     return( length+1 );
  73. }
  74.  
  75. int get_index( data )
  76.     int     *data;
  77. {
  78.     unsigned int ch;
  79.  
  80.     ch = get_byte();
  81.     if ( ch > 0x7F ) {
  82.         ch = ((ch & 0x7F) << 8) + get_byte();
  83.         *data = ch;
  84.         return( 2 );
  85.     } else {
  86.         *data = ch;
  87.         return( 1 );
  88.     }
  89. }
  90. 
  91.