def_t dict_search(dict_t dict, word_t word) { assert(dict != NULL && word != NULL && dict_exists(dict, word)); index_t palabra = NULL; palabra = index_from_string(word); data_t definition = list_search(dict->list, palabra); def_t result = data_to_string(definition); palabra = index_destroy(palabra); assert(result != NULL); return (result); }
def_t dict_search(dict_t dict, word_t word) { index_t index = index_from_string(word); assert(dict != NULL && word != NULL && dict_exists(dict,word)); def_t result = NULL; result = data_to_string(list_search(dict->data,index)); free(index); index=NULL; assert(result != NULL); return result; }
SEXP R_gpg_export(SEXP id, SEXP secret){ gpgme_data_t keydata = NULL; bail(gpgme_data_new(&keydata), "initiatie keydata"); #ifdef GPGME_EXPORT_MODE_SECRET gpgme_export_mode_t mode = asLogical(secret) * GPGME_EXPORT_MODE_SECRET; #else int mode = 0; #ifndef CHECK_OLD_GPGME if(asLogical(secret)) Rf_error("gpgme is too old, GPGME_EXPORT_MODE_SECRET not supported"); #endif #endif bail(gpgme_op_export(ctx, CHAR(STRING_ELT(id, 0)), mode, keydata), "export key"); return data_to_string(keydata); }
def_t dict_search(dict_t dict, word_t word) { /*Precondition verification*/ assert(dict != NULL); assert(word != NULL); assert( dict_exists(dict, word) ); index_t index = index_from_string(word); data_t data = bst_search(dict->data, index); def_t definicion = data_to_string(data); index_destroy(index); /*Postcondition verification*/ assert(definicion != NULL); return (definicion); }
void list_dump(list_t list, FILE * fd) { list_t current = list; char* index; char* data; while(current!=NULL) { index = index_to_string(pair_fst(current->elem)); data = data_to_string(pair_snd(current->elem)); fprintf(fd,"%s: %s",index,data); current = current->next; if(current!=NULL) { fprintf(fd,"\n"); } free(index); free(data); index = NULL; data = NULL; } }
int main (int argc, char **argv) { char* filename = 0; char* outfilename = 0; int c; logging_init(); opterr = 0; while ((c = getopt (argc, argv, "vqf:o:")) != -1) switch (c) { case 'v': verbose++; break; case 'q': verbose--; break; case 'f': if (filename != 0) { logging_info( "Overriding previous -f flag '%s' with '%s'.\n", filename, optarg ); } filename = optarg; break; case 'o': if (outfilename != 0) { logging_info( "Overriding previous -o flag '%s' with '%s'.\n", outfilename, optarg ); } outfilename = optarg; break; case '?': if ((optopt == 'f') || (optopt == 'o') || (optopt == 'd')) fprintf (stderr, "Option -%c requires an argument.\n", optopt); else if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); fprintf( stderr, "rtl_868, Copyright (C) 2015 Clemens Helfmeier\n" "rtl_868 comes with ABSOLUTELY NO WARRANTY; for details see the\n" "LICENSE file distributed with the program.\n" "This is free software, and you are welcome to redistribute it\n" "under certain conditions; see the LICENSE file for details.\n" "\n" "Usage: \n" " rtl_868 [PARAMETERS] [FILENAME]\n" " [FILENAME] read input data from there. Defaults to stdin.\n" " [PARAMETERS] Unix style parameters with possible values:\n" " -v be more verbose. accumulates when given multiple times.\n" " -q be less verbose.\n" " -f file open file instead of stdin.\n" " -o file open file instead of stdout.\n" "\n" ); return 1; default: abort (); } if ((argc - 1 == optind) && (filename == 0)) { logging_verbose( "Using positional argument '%s' as input filename.\n", argv[optind] ); // if there is a single remaining argument, use it as filename filename = argv[optind]; } else { int index; for (index = optind; index < argc; index++) { logging_error( "Unkown non-option argument %s\n", argv[index] ); return 1; } } if (filename == 0) { filename = "-"; } if (outfilename == 0){ outfilename = "-"; } logging_verbose( "decode.c version 0, verbose %i, filename %s -> %s.\n", verbose, filename, outfilename ); logging_info( "rtl_868, Copyright (C) 2015 Clemens Helfmeier\n" "rtl_868 comes with ABSOLUTELY NO WARRANTY; for details see the\n" "LICENSE file distributed with the program.\n" "This is free software, and you are welcome to redistribute it\n" "under certain conditions; see the LICENSE file for details.\n" ); FILE *in, *out; if ((filename == 0) || (strcmp( filename, "-" ) == 0)) in = stdin; else in = fopen( filename, "r" ); if (in == 0) { if (filename == 0) { logging_error( "Could not open stdin as input file.\n" ); } else { logging_error( "Could not open input file '%s'.\n", filename ); } return 1; } if ((outfilename == 0) || (strcmp( outfilename, "-" ) == 0)) out = stdout; else out = fopen( outfilename, "a" ); if (out == 0) { if (outfilename == 0) { logging_error( "Could not open stdout as output file.\n" ); } else { logging_error( "Could not open output file '%s'.\n", outfilename ); } return 1; } int duplicate_stream_input( int transmission[], unsigned int length ) { if ((ws300.input( transmission, length) == 0) || (tx29.input(transmission, length) == 0)) return 0; else if (verbose > 1) { if (length < 6) return -1; fprintf( out, "__, %i, ", length ); while (length-- > 0) fprintf( out, "%02x ", *transmission++ ); fprintf( out, "\n" ); fflush(out); return 0; } else { return 0; } } stream_decoder_t mysd = { .init = 0, .input = &duplicate_stream_input }; // construct the signal chain /* transmission decoder */ td.init( &nrz ); /* nrz */ nrz.init( &mysd ); /* ws300 and tx29 */ ws300.init( &dl_file ); tx29.init( &dl_file ); /* dl_file */ dl_file.init( out ); uint16_t d[1024]; unsigned long long int ndata = 0; unsigned long long int last_ndata = 0; struct timespec last_status; clock_gettime( CLOCK_MONOTONIC, &last_status ); // read from stdin S16LE data while (1) { /* read a chunk */ int n = fread( d, sizeof(d[0]), sizeof(d)/sizeof(d[0]), in ); if (n != sizeof(d)/sizeof(d[0])) { logging_error( "\nError during read: %x.\n", n ); break; } else { ndata += n; } struct timespec now; clock_gettime( CLOCK_MONOTONIC, &now ); // if time is over, redisplay status float dt = 1.0 * (now.tv_sec - last_status.tv_sec) + 1.0 * (now.tv_nsec - last_status.tv_nsec) / 1e9; if (dt > 1) { // calculate new throughput float throughput = (ndata - last_ndata) / dt; last_ndata = ndata; /* update status display */ char nd_e; float nd_b; data_to_string( (float)ndata, &nd_b, &nd_e ); char tp_e; float tp_b; data_to_string( throughput, &tp_b, &tp_e ); logging_status( 0, "%s -> %s, %1.1f%c, %1.1f%c", filename, outfilename, nd_b, nd_e, tp_b, tp_e ); logging_restatus(); last_status.tv_sec = now.tv_sec; last_status.tv_nsec = now.tv_nsec; } /* and put the chunk into the transmission decoder */ int i; for (i = 0; i<sizeof(d)/sizeof(d[0]); i++) { td.input( d[i] ); } } fclose(in); }