int init_keyb(void) { console_options.title = "\pBCPL Cintcode"; console_options.pause_atexit = 0; cshow(stdin); csetmode(C_RAW, stdin); return 0; }
main( int argc, char **argv ) { long i, i2, num; unsigned long len; int tag; char *str, *s1, *s2; BerElement ber; Sockbuf sb; extern char *optarg; #ifdef MACOS ccommand( &argv ); cshow( stdout ); #endif /* MACOS */ bzero( &sb, sizeof(sb) ); sb.sb_sd = 0; sb.sb_ber.ber_buf = NULL; if ( (tag = ber_get_next( &sb, &len, &ber )) == -1 ) { perror( "ber_get_next" ); exit( 1 ); } printf( "message has tag 0x%x and length %ld\n", tag, len ); if ( ber_scanf( &ber, "i", &i ) == -1 ) { fprintf( stderr, "ber_scanf returns -1\n" ); exit( 1 ); } printf( "got int %d\n", i ); return( 0 ); }
void RTinit() /* set up Linebuf, Midibuf & ready the input files */ { /* callable once from main.c */ extern int Linein, Midiin; extern char *Linename, *Midiname; if (Linein) { Linevtblk = (EVTBLK *) mcalloc((long)sizeof(EVTBLK)); Linebuf = mcalloc((long)LBUFSIZ); Linebufend = Linebuf + LBUFSIZ; Linep = Linebuf; if (strcmp(Linename,"stdin") == 0) { #ifdef THINK_C console_options.top += 10; console_options.left += 10; console_options.title = "\pRT Line_events"; console_options.nrows = 10; console_options.ncols = 50; Linecons = fopenc(); cshow(Linecons); #else if (fcntl(Linefd, F_SETFL, fcntl(Linefd, F_GETFL, 0) | O_NDELAY) < 0) die("-R stdin fcntl failed"); #endif } else if ((Linefd = open(Linename, O_RDONLY | O_NDELAY)) < 0) dies("cannot open %s", Linename); } if (Midiin) { Midevtblk = (EVTBLK *) mcalloc((long)sizeof(EVTBLK)); Midibuf = mcalloc((long)MBUFSIZ); Midibufend = Midibuf + MBUFSIZ; Midip = Midibuf; if (strcmp(Midiname,"stdin") == 0) { #ifdef THINK_C dieu("RT Midi_event Console not implemented"); #else if (fcntl(Midifd, F_SETFL, fcntl(Midifd, F_GETFL, 0) | O_NDELAY) < 0) die("-M stdin fcntl failed"); #endif } else if ((Midifd = open(Midiname, O_RDONLY | O_NDELAY)) < 0) dies("cannot open %s", Midiname); } }
int main( int argc, char **argv ) { char *s; int fd, rc; BerElement *ber; Sockbuf *sb; /* enable debugging */ int ival = -1; ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ival ); if ( argc < 2 ) { usage( argv[0] ); return( EXIT_FAILURE ); } #ifdef HAVE_CONSOLE_H ccommand( &argv ); cshow( stdout ); if (( fd = open( "lber-test", O_WRONLY|O_CREAT|O_TRUNC|O_BINARY )) < 0 ) { perror( "open" ); return( EXIT_FAILURE ); } #else fd = fileno(stdout); #endif sb = ber_sockbuf_alloc(); ber_sockbuf_add_io( sb, &ber_sockbuf_io_fd, LBER_SBIOD_LEVEL_PROVIDER, (void *)&fd ); if( sb == NULL ) { perror( "ber_sockbuf_alloc_fd" ); return( EXIT_FAILURE ); } if ( (ber = ber_alloc_t( LBER_USE_DER )) == NULL ) { perror( "ber_alloc" ); return( EXIT_FAILURE ); } fprintf(stderr, "encode: start\n" ); if( ber_printf( ber, "{" /*}*/ ) ) { perror( "ber_printf {" /*}*/ ); return( EXIT_FAILURE ); } for ( s = argv[1]; *s; s++ ) { char *buf; char fmt[2]; fmt[0] = *s; fmt[1] = '\0'; fprintf(stderr, "encode: %s\n", fmt ); switch ( *s ) { case 'i': /* int */ case 'b': /* boolean */ case 'e': /* enumeration */ buf = getbuf(); rc = ber_printf( ber, fmt, atoi(buf) ); break; case 'n': /* null */ case '{': /* begin sequence */ case '}': /* end sequence */ case '[': /* begin set */ case ']': /* end set */ rc = ber_printf( ber, fmt ); break; case 'o': /* octet string (non-null terminated) */ case 'B': /* bit string */ buf = getbuf(); rc = ber_printf( ber, fmt, buf, strlen(buf) ); break; case 's': /* string */ case 't': /* tag for the next element */ buf = getbuf(); rc = ber_printf( ber, fmt, buf ); break; default: fprintf( stderr, "encode: unknown fmt %c\n", *fmt ); rc = -1; break; } if( rc == -1 ) { perror( "ber_printf" ); return( EXIT_FAILURE ); } } fprintf(stderr, "encode: end\n" ); if( ber_printf( ber, /*{*/ "N}" ) == -1 ) { perror( /*{*/ "ber_printf }" ); return( EXIT_FAILURE ); } if ( ber_flush( sb, ber, 1 ) == -1 ) { perror( "ber_flush" ); return( EXIT_FAILURE ); } ber_sockbuf_free( sb ); return( EXIT_SUCCESS ); }
int main( int argc, char **argv ) { char *s; ber_tag_t tag; ber_len_t len; BerElement *ber; Sockbuf *sb; int fd; /* enable debugging */ int ival = -1; ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ival ); if ( argc < 2 ) { usage( argv[0] ); return( EXIT_FAILURE ); } #ifdef HAVE_CONSOLE_H ccommand( &argv ); cshow( stdout ); #endif sb = ber_sockbuf_alloc(); fd = fileno( stdin ); ber_sockbuf_add_io( sb, &ber_sockbuf_io_fd, LBER_SBIOD_LEVEL_PROVIDER, (void *)&fd ); ber = ber_alloc_t(LBER_USE_DER); if( ber == NULL ) { perror( "ber_alloc_t" ); return( EXIT_FAILURE ); } for (;;) { tag = ber_get_next( sb, &len, ber); if( tag != LBER_ERROR ) break; if( errno == EWOULDBLOCK ) continue; if( errno == EAGAIN ) continue; perror( "ber_get_next" ); return( EXIT_FAILURE ); } printf("decode: message tag 0x%lx and length %ld\n", (unsigned long) tag, (long) len ); for( s = argv[1]; *s; s++ ) { char buf[128]; char fmt[2]; fmt[0] = *s; fmt[1] = '\0'; printf("decode: format %s\n", fmt ); len = sizeof(buf); tag = ber_scanf( ber, fmt, &buf[0], &len ); if( tag == LBER_ERROR ) { perror( "ber_scanf" ); return( EXIT_FAILURE ); } } ber_sockbuf_free( sb ); return( EXIT_SUCCESS ); }