Skip to content
Snippets Groups Projects
Select Git revision
  • 04756989a19be92cdec494d15f55df8e6913f9c5
  • master default
  • labcomm2014
  • labcomm2006
  • python_sig_hash
  • typedefs
  • anders.blomdell
  • typeref
  • pragma
  • compiler-refactoring
  • labcomm2013
  • v2014.6
  • v2015.0
  • v2014.5
  • v2014.4
  • v2006.0
  • v2014.3
  • v2014.2
  • v2014.1
  • v2014.0
  • v2013.0
21 results

PrettyPrint.jrag

  • example_decoder.c 2.42 KiB
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <labcomm_fd_reader.h>
    #include <labcomm_default_error_handler.h>
    #include <labcomm_default_memory.h>
    #include <labcomm_default_scheduler.h>
    #include "gen/simple.h"
    #include <stdio.h>
    
    static void handle_simple_theTwoInts(simple_TwoInts *v,void *context) {
      printf("Got theTwoInts. a=%d, b=%d\n", v->a, v->b);
    }
    
    static void handle_simple_anotherTwoInts(simple_TwoInts *v,void *context) {
      printf("Got anotherTwoInts. a=%d, b=%d\n", v->a, v->b);
    }
    
    static void handle_simple_IntString(simple_IntString *v,void *context) {
      printf("Got IntString. x=%d, s=%s\n", v->x, v->s);
    }
    
    static void handle_simple_TwoArrays(simple_TwoArrays *d,void *context) {
      printf("Got TwoArrays:");
      int i,j;
        for(i=0; i<2; i++) {
            printf("%d ",d->fixed.a[i]);
        }
        printf("\n");
        for(i=0; i<2; i++) {
          for(j=0; j<d->variable.n_1; j++) {
    	printf("%d ",d->variable.a[i *d->variable.n_1 + j]);
          }
          printf("\n");
        }
        printf("\n");
    }
    
    static void handle_simple_TwoFixedArrays(simple_TwoFixedArrays *d,void *context) {
      printf("Got TwoFixedArrays:");
      int i,j;
        for(i=0; i<2; i++) {
            printf("%d ",d->a.a[i]);
        }
        printf("\n");
        for(i=0; i<2; i++) {
          for(j=0; j<3; j++) {
    	printf("%d ",d->b.a[i][j]);
          }
          printf("\n");
        }
    }
    
    int main(int argc, char *argv[]) {
      int fd;
      struct labcomm_decoder *decoder;
      void  *context = NULL;
    
      char *filename = argv[1];
      printf("C decoder reading from %s\n", filename);
      fd = open(filename, O_RDONLY);
      decoder = labcomm_decoder_new(labcomm_fd_reader_new(
    				  labcomm_default_memory, fd, 1), 
    				labcomm_default_error_handler, 
    				labcomm_default_memory,
    				labcomm_default_scheduler);
      if (!decoder) { 
        printf("Failed to allocate decoder %s:%d\n", __FUNCTION__, __LINE__);
        return 1;
      }
    
      labcomm_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context);
      labcomm_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context);
      labcomm_decoder_register_simple_IntString(decoder, handle_simple_IntString, context);
      labcomm_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context);
      labcomm_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context);
    
      printf("Decoding:\n");
      labcomm_decoder_run(decoder);
      printf("--- End Of File ---:\n");
      labcomm_decoder_free(decoder);
    
      return 0;
    }