void test_seq_nonacgt(){ seq_t S; seq_init( &S, "11ACGTNN7682394689NNTGCA11", "name"); seq_subject_init( &S); g_assert_cmpstr(S.S, ==, "ACGTTGCA"); g_assert_cmpuint(S.len, ==, 8 ); g_assert( FLAGS & F_NON_ACGT); g_assert_cmpstr(S.RS, ==, "TGCAACGT#ACGTTGCA"); g_assert_cmpuint(S.RSlen, ==, 8*2+1); g_assert( S.gc == 0.5); seq_free( &S); FLAGS = F_NONE; seq_init( &S, "@ACGT_!0TGCA ", "name"); seq_subject_init( &S); g_assert_cmpstr(S.S, ==, "ACGT!TGCA"); g_assert_cmpuint(S.len, ==, 9 ); g_assert( FLAGS & F_NON_ACGT); g_assert_cmpstr(S.RS, ==, "TGCA;ACGT#ACGT!TGCA"); g_assert_cmpuint(S.RSlen, ==, 9*2+1); seq_free( &S); FLAGS = F_NONE; }
void main() { // Current Functionality: // Very functional gate/trigger sequencer: // - Mode toggles current encoder value, indicated by mode led // - 0 (No light): Clear gate // - 1 (Solid): Set gate // - 2 (All Flash): Set CV // - 3 (Double Flash): Set Preset // - Target selects active pattern (none, 1, 2, 3), indicated by target led // - When Target = none, Set stores encoder to global gate length // - Otherwise, Set triggers write of encoder value to current step in target pattern (depending on mode) // - Clock/RST 1 controlls pattern 1 // - Clock/RST 2 ticks patterns 2 and 3 // - DIR 1 controls direction on all patterns // - DIR 2 controlls gate length offset on patterns 2 and 3; pattern 1 is 'trigger' only // - CV edit from A/D LVL input // // Next Steps: // - Sequence Presets (selected by encoder and applied by set?) // setup(); seq_init(16); leds_init(); while (1) { clock_check(); buttons_check(); } }
int main (int argc, char *argv[]) { if( argc != 3 ) { usage( "%s <errors|noerrors> <gaps|nogaps>", argv[0]); return -1; } MrfEntry *currEntry; MrfBlock *currBlock; int i, error, errorCode, numErrors; int gaps = 0; if( strEqual( "gaps", argv[2] ) ) gaps = 1; seq_init(); mrf_init ("-"); printf( "%s\n", mrf_writeHeader()); numErrors = 0; while (currEntry = mrf_nextEntry ()) { error = 0; for( i=0; i<arrayMax(currEntry->read1.blocks); i++) { currBlock=arrp( currEntry->read1.blocks, i, MrfBlock); if( i==0 ) { errorCode = processBlock ( currBlock, NULL, gaps ); } else { errorCode = processBlock ( currBlock, arrp( currEntry->read1.blocks, i-1, MrfBlock ), gaps ); } if( errorCode != 0 ) { warn( "Error code (read1): %d\t%s:%c:%d:%d:%d:%d", errorCode, currBlock->targetName, currBlock->strand, currBlock->targetStart, currBlock->targetEnd, currBlock->queryStart, currBlock->queryEnd); error++; } } if (currEntry->isPairedEnd & error == 0) { for( i=0; i<arrayMax(currEntry->read2.blocks); i++) { currBlock=arrp( currEntry->read2.blocks, i, MrfBlock); if( i==0 ) { errorCode = processBlock ( currBlock, NULL , gaps ); } else { errorCode = processBlock (currBlock, arrp( currEntry->read2.blocks, i-1, MrfBlock) , gaps); } if( errorCode !=0 ) { warn( "Error code (read2): %d\t%s:%c:%d:%d:%d:%d", errorCode, currBlock->targetName, currBlock->strand, currBlock->targetStart, currBlock->targetEnd, currBlock->queryStart, currBlock->queryEnd); error++; } } } if( error > 0 && strEqual(argv[1], "errors")) { printf( "%s\n", mrf_writeEntry( currEntry )); error=0; numErrors++; } if( error == 0 && strEqual(argv[1], "noerrors")) printf( "%s\n", mrf_writeEntry( currEntry )); } mrf_deInit (); warn("%s: done", argv[0]); return 0; }
void OpenEmUp(void) { randomize(); seq_init(); GV(&vhptr, 320, 200); // Allocate only Virtual Buffer letter_dat = slurp_gamedat("letter.dat"); }
void test_seq_basic(){ seq_t S; seq_init( &S, "ACGT", "name"); g_assert_cmpstr(S.S, ==, "ACGT"); g_assert_cmpstr(S.name, ==, "name"); g_assert_cmpuint(S.len, ==, 4); seq_free( &S); }
void test_seq_full(){ seq_t S; seq_init( &S, "ACGTTGCA", "name"); int check = seq_subject_init( &S); g_assert_cmpint(check, ==, 0); g_assert_cmpstr(S.RS, ==, "TGCAACGT#ACGTTGCA"); g_assert_cmpuint(S.RSlen, ==, 8*2+1); g_assert( S.gc == 0.5); seq_free( &S); }
int main() { seqlist* l; int i; l=seq_init(); srand(time(NULL)); for(i=0;i<50;i++) l->data[++l->last]=rand()%150; printf("排列前:\n"); for(i=0;i<=l->last;i++) printf("%d ",l->data[i]); printf("\n排列后:"); part(l); for(i=0;i<=l->last;i++) printf("%d ",l->data[i]); getchar(); return 0; }
/** * Performs simple tests for abstract types implementations * * @return void */ static void test(void) { char a = 'b'; stack_ptr stack = NULL; seq_ptr seq = NULL; seq_prepare(&seq, "sequence.test"); seq_write(&seq, 'o'); seq_init(&seq); log_info("main", "Character written in sequence: %c", a = seq_read_first(&seq)); seq_close(&seq); stack_create(&stack); log_info("main", "Stack is: %s", stack_empty(&stack) ? "Empty" : "Not empty"); stack_push(&stack, a); log_info("main", "Stack is: %s", stack_empty(&stack) ? "Empty" : "Not empty"); log_info("main", "First character in stack: %c", stack_pop(&stack)); log_info("main", "Stack is: %s", stack_empty(&stack) ? "Empty" : "Not empty"); }
static void seq_private (struct msgs *mp) { int i, j, alen, plen; char *cp; struct node *np; alen = strlen ("atr-"); plen = strlen (mp->foldpath) + 1; for (np = m_defs; np; np = np->n_next) { if (ssequal ("atr-", np->n_name) && (j = strlen (np->n_name) - plen) > alen && *(np->n_name + j) == '-' && strcmp (mp->foldpath, np->n_name + j + 1) == 0) { cp = getcpy (np->n_name + alen); *(cp + j - alen) = '\0'; if ((i = seq_init (mp, cp, getcpy (np->n_field))) != -1) make_seq_private (mp, i); } } }
/*@ guards \true; @ depends \noact; @ assigns \nothing; @ reads \nothing; @*/ $atomic_f void create(cqueue* q) { q = (cqueue*)$malloc(root, sizeof(cqueue)); q->owner=$proc_null; $seq_init(&q->data, 0, NULL); }
int main(int argc, char *argv[]) { int opt; int saw_files = 0; int status = 0; FILE *file; int which; int lineno; int error; seq_t seq = NULL; int seq_cmd, parse_mode; progname = basename(argv[0]); #if POSIXLY_CORRECT cmd_line_options = POSIXLY_CMD_LINE_OPTIONS; cmd_line_spec = _(POSIXLY_CMD_LINE_SPEC); #else if (getenv(POSIXLY_CORRECT_STR)) posixly_correct = 1; if (!posixly_correct) { cmd_line_options = CMD_LINE_OPTIONS; cmd_line_spec = _(CMD_LINE_SPEC); } else { cmd_line_options = POSIXLY_CMD_LINE_OPTIONS; cmd_line_spec = _(POSIXLY_CMD_LINE_SPEC); } #endif setlocale(LC_CTYPE, ""); setlocale(LC_MESSAGES, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); while ((opt = getopt_long(argc, argv, cmd_line_options, long_options, NULL)) != -1) { /* we remember the two REMOVE_ACL commands of the set operations because we may later need to delete them. */ cmd_t seq_remove_default_acl_cmd = NULL; cmd_t seq_remove_acl_cmd = NULL; if (opt != '\1' && saw_files) { if (seq) { seq_free(seq); seq = NULL; } saw_files = 0; } if (seq == NULL) { if (!(seq = seq_init())) ERRNO_ERROR(1); } switch (opt) { case 'b': /* remove all extended entries */ if (seq_append_cmd(seq, CMD_REMOVE_EXTENDED_ACL, ACL_TYPE_ACCESS) || seq_append_cmd(seq, CMD_REMOVE_ACL, ACL_TYPE_DEFAULT)) ERRNO_ERROR(1); break; case 'k': /* remove default ACL */ if (seq_append_cmd(seq, CMD_REMOVE_ACL, ACL_TYPE_DEFAULT)) ERRNO_ERROR(1); break; case 'n': /* do not recalculate mask */ opt_recalculate = -1; break; case 'r': /* force recalculate mask */ opt_recalculate = 1; break; case 'd': /* operations apply to default ACL */ opt_promote = 1; break; case 's': /* set */ if (seq_append_cmd(seq, CMD_REMOVE_ACL, ACL_TYPE_ACCESS)) ERRNO_ERROR(1); seq_remove_acl_cmd = seq->s_last; if (seq_append_cmd(seq, CMD_REMOVE_ACL, ACL_TYPE_DEFAULT)) ERRNO_ERROR(1); seq_remove_default_acl_cmd = seq->s_last; seq_cmd = CMD_ENTRY_REPLACE; parse_mode = SEQ_PARSE_WITH_PERM | SEQ_PARSE_NO_RELATIVE; goto set_modify_delete; case 'm': /* modify */ seq_cmd = CMD_ENTRY_REPLACE; parse_mode = SEQ_PARSE_WITH_PERM; #if POSIXLY_CORRECT || 1 parse_mode |= SEQ_PARSE_NO_RELATIVE; #else if (posixly_correct) parse_mode |= SEQ_PARSE_NO_RELATIVE; else parse_mode |= SEQ_PARSE_ANY_RELATIVE; #endif goto set_modify_delete; case 'x': /* delete */ seq_cmd = CMD_REMOVE_ENTRY; parse_mode = SEQ_PARSE_NO_RELATIVE; #if POSIXLY_CORRECT parse_mode |= SEQ_PARSE_ANY_PERM; #else if (posixly_correct) parse_mode |= SEQ_PARSE_ANY_PERM; else parse_mode |= SEQ_PARSE_NO_PERM; #endif goto set_modify_delete; set_modify_delete: if (!posixly_correct) parse_mode |= SEQ_PARSE_DEFAULT; if (opt_promote) parse_mode |= SEQ_PROMOTE_ACL; if (parse_acl_seq(seq, optarg, &which, seq_cmd, parse_mode) != 0) { if (which < 0 || (size_t) which >= strlen(optarg)) { fprintf(stderr, _( "%s: Option " "-%c incomplete\n"), progname, opt); } else { fprintf(stderr, _( "%s: Option " "-%c: %s near " "character %d\n"), progname, opt, strerror(errno), which+1); } status = 2; goto cleanup; } break; case 'S': /* set from file */ if (seq_append_cmd(seq, CMD_REMOVE_ACL, ACL_TYPE_ACCESS)) ERRNO_ERROR(1); seq_remove_acl_cmd = seq->s_last; if (seq_append_cmd(seq, CMD_REMOVE_ACL, ACL_TYPE_DEFAULT)) ERRNO_ERROR(1); seq_remove_default_acl_cmd = seq->s_last; seq_cmd = CMD_ENTRY_REPLACE; parse_mode = SEQ_PARSE_WITH_PERM | SEQ_PARSE_NO_RELATIVE; goto set_modify_delete_from_file; case 'M': /* modify from file */ seq_cmd = CMD_ENTRY_REPLACE; parse_mode = SEQ_PARSE_WITH_PERM; #if POSIXLY_CORRECT || 1 parse_mode |= SEQ_PARSE_NO_RELATIVE; #else if (posixly_correct) parse_mode |= SEQ_PARSE_NO_RELATIVE; else parse_mode |= SEQ_PARSE_ANY_RELATIVE; #endif goto set_modify_delete_from_file; case 'X': /* delete from file */ seq_cmd = CMD_REMOVE_ENTRY; parse_mode = SEQ_PARSE_NO_RELATIVE; #if POSIXLY_CORRECT parse_mode |= SEQ_PARSE_ANY_PERM; #else if (posixly_correct) parse_mode |= SEQ_PARSE_ANY_PERM; else parse_mode |= SEQ_PARSE_NO_PERM; #endif goto set_modify_delete_from_file; set_modify_delete_from_file: if (!posixly_correct) parse_mode |= SEQ_PARSE_DEFAULT; if (opt_promote) parse_mode |= SEQ_PROMOTE_ACL; if (strcmp(optarg, "-") == 0) { file = stdin; } else { file = fopen(optarg, "r"); if (file == NULL) { fprintf(stderr, "%s: %s: %s\n", progname, xquote(optarg), strerror(errno)); status = 2; goto cleanup; } } lineno = 0; error = read_acl_seq(file, seq, seq_cmd, parse_mode, &lineno, NULL); if (file != stdin) { fclose(file); } if (error) { if (!errno) errno = EINVAL; if (file != stdin) { fprintf(stderr, _( "%s: %s in line " "%d of file %s\n"), progname, strerror(errno), lineno, xquote(optarg)); } else { fprintf(stderr, _( "%s: %s in line " "%d of standard " "input\n"), progname, strerror(errno), lineno); } status = 2; goto cleanup; } break; case '\1': /* file argument */ if (seq_empty(seq)) goto synopsis; saw_files = 1; status = next_file(optarg, seq); break; case 'B': /* restore ACL backup */ saw_files = 1; if (strcmp(optarg, "-") == 0) file = stdin; else { file = fopen(optarg, "r"); if (file == NULL) { fprintf(stderr, "%s: %s: %s\n", progname, xquote(optarg), strerror(errno)); status = 2; goto cleanup; } } status = restore(file, (file == stdin) ? NULL : optarg); if (file != stdin) fclose(file); if (status != 0) goto cleanup; break; case 'R': /* recursive */ opt_recursive = 1; break; case 'L': /* follow symlinks */ opt_walk_logical = 1; opt_walk_physical = 0; break; case 'P': /* do not follow symlinks */ opt_walk_logical = 0; opt_walk_physical = 1; break; case 't': /* test mode */ opt_test = 1; break; case 'v': /* print version and exit */ printf("%s " VERSION "\n", progname); status = 0; goto cleanup; case 'h': /* help! */ help(); status = 0; goto cleanup; case ':': /* option missing */ case '?': /* unknown option */ default: goto synopsis; } if (seq_remove_acl_cmd) { /* This was a set operation. Check if there are actually entries of ACL_TYPE_ACCESS; if there are none, we need to remove this command! */ if (!has_any_of_type(seq_remove_acl_cmd->c_next, ACL_TYPE_ACCESS)) seq_delete_cmd(seq, seq_remove_acl_cmd); } if (seq_remove_default_acl_cmd) { /* This was a set operation. Check if there are actually entries of ACL_TYPE_DEFAULT; if there are none, we need to remove this command! */ if (!has_any_of_type(seq_remove_default_acl_cmd->c_next, ACL_TYPE_DEFAULT)) seq_delete_cmd(seq, seq_remove_default_acl_cmd); } } while (optind < argc) { if (seq_empty(seq)) goto synopsis; saw_files = 1; status = next_file(argv[optind++], seq); } if (!saw_files) goto synopsis; goto cleanup; synopsis: fprintf(stderr, _("Usage: %s %s\n"), progname, cmd_line_spec); fprintf(stderr, _("Try `%s --help' for more information.\n"), progname); status = 2; goto cleanup; errno_error: fprintf(stderr, "%s: %s\n", progname, strerror(errno)); goto cleanup; cleanup: if (seq) seq_free(seq); return status; }
int main(int argc, char *argv[]) { int debug = 1; int ch; char *file_path = NULL; static struct option long_options[] = { { "test", no_argument, 0, 't' }, { "input", no_argument, 0, 'i' }, { "debug", no_argument, 0, 'd' }, { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { 0 }, { 0 } }; while (1) { int option_index = 0; ch = getopt_long(argc, argv, "hvdtD:i:", long_options, &option_index); if (ch == -1) break; switch (ch) { case 'h': usage(); exit(0); break; case 'v': fprintf(stdout, "%s\n", PACKAGE_VERSION); exit(0); break; case 'd': debug++; break; case 'D': log_accept(optarg); break; case 'i': file_path = optarg; break; case 't': log_init(2, __progname); test(); exit(0); break; default: fprintf(stderr, "unknown option `%c'\n", ch); usage(); exit(1); } } // Setup program log_init(debug, __progname); log_info("main", "hello world!"); description(); // Create abstract types variables seq_ptr seq = NULL; stack_ptr stack = NULL; // Initialize and solve exercise if(file_path == NULL) { seq_prepare(&seq, TMP_SEQUENCE); prompt_user(&seq); seq_init(&seq); } else { seq_prepare(&seq, file_path); } stack_create(&stack); solve_exercise(&seq, &stack); printf("[OUTPUT] The result for the algorithm is the following:\n"); stack_output(&stack); // Clean up and return success if(file_path == NULL) remove(TMP_SEQUENCE); return EXIT_SUCCESS; }
int main (int argc, char **argv) { LineStream ls; Texta tokens = NULL; char *line; int hasQual = 0; int hasSeqs = 0; int start=1; ls = ls_createFromFile ("-"); while (line = ls_nextLine (ls)) { // Put all the lines of the SAM header in comments if (line[0] == '@') { printf ("# %s\n", line); continue; } // Parse each SAM entry and store into array tokens = textFieldtokP (line, "\t"); if (arrayMax (tokens) < 11) { textDestroy( tokens ); ls_destroy (ls); die ("Invalid SAM entry: %s", line); } SamEntry *currSamE = NULL; SamEntry *mateSamE = NULL; AllocVar(currSamE ); int ret = generateSamEntry( tokens, currSamE, &hasSeqs, &hasQual ); textDestroy( tokens ); if ( ret==0 ) { if ( isPaired ( currSamE ) ) ls_nextLine( ls ); // discarding next entry too (the mate) destroySamEntry( currSamE ); freeMem( currSamE ); continue; } if ( isPaired( currSamE ) ) { int hasQual2, hasSeq2; AllocVar( mateSamE ); Texta secondEnd = NULL; secondEnd = textFieldtok (ls_nextLine( ls ) , "\t"); ret = generateSamEntry( secondEnd, mateSamE, &hasSeq2, &hasQual2 ); textDestroy( secondEnd ); if( ret == 0 ) { destroySamEntry( currSamE ); destroySamEntry( mateSamE ); freeMem( currSamE ); freeMem( mateSamE ); continue; } if (strcmp (currSamE->qname, mateSamE->qname) != 0) { die ("Please note that for paired-end data, sam2mrf requires the mate pairs to be on subsequent lines. You may want to sort the SAM file first.\nEx: sort -r file.sam | sam2mrf > file.mrf\n"); } } // Print MRF headers if( start ) { printf ("%s", MRF_COLUMN_NAME_BLOCKS); if (hasSeqs) printf("\t%s", MRF_COLUMN_NAME_SEQUENCE); if (hasQual) printf("\t%s", MRF_COLUMN_NAME_QUALITY_SCORES); printf ("\t%s\n", MRF_COLUMN_NAME_QUERY_ID); start=0; } // Print AlignmentBlocks printMrfAlignBlocks (currSamE, R_FIRST); if( isPaired ( currSamE ) ) { printf ("|"); printMrfAlignBlocks (mateSamE, R_SECOND); } seq_init(); // Print Sequence if (hasSeqs) { if (!currSamE->seq) die ("Entry missing sequence column\n"); if( currSamE->flags & S_QUERY_STRAND ) seq_reverseComplement( currSamE->seq, strlen(currSamE->seq)); printf ("\t%s", currSamE->seq); if (mateSamE) { if (!mateSamE->seq) die ("Entry missing sequence column\n"); if( mateSamE->flags & S_MATE_STRAND ) seq_reverseComplement( mateSamE->seq, strlen(mateSamE->seq)); printf ("|%s", mateSamE->seq); } } // Print quality scores if (hasQual) { if (!currSamE->qual) die ("Entry missing quality scores column\n"); printf ("\t%s", currSamE->qual); if (mateSamE) { if (!mateSamE->qual) die ("Entry missing quality scores column\n"); printf ("|%s", mateSamE->qual); } } // Print queryID if (mateSamE) { printf ("\t%s|%s", currSamE->qname,"2"); // No need to print out both IDs, but need the pipe symbol for consistency } else { printf ("\t%s", currSamE->qname); } printf("\n"); destroySamEntry( currSamE ); freeMem( currSamE ); if( isPaired( currSamE ) ) { destroySamEntry ( mateSamE ); freeMem( mateSamE ); } } // clean up ls_destroy (ls); return EXIT_SUCCESS; }
void play_hmi (void * arg) { int i; int pos = 0x308; int n_chunks = 0; int low_dtime; int low_chunk; int csec, lcsec; int qid; int ipc_read = 0; int k=0; struct msgbuf *rcv; Track_info *t_info; con_printf(CON_DEBUG,"play_hmi\n"); stop = 0; ipc_read=0; rcv=malloc(sizeof(long) + 16); rcv->mtype=1; rcv->mtext[0]='0'; qid=msgget ((key_t) ('l'<<24) | ('d'<<16) | ('e'<<8) | 's', 0660); if(qid == -1) { return; } do { ipc_read=do_ipc(qid,rcv,0); } while(rcv->mtext[0] != 'p'); stop=0; rcv->mtext[0] = '0'; seq_init(); n_chunks=data[0x30]; t_info = malloc(sizeof(Track_info)*n_chunks); while(1) { for(i=0;i<n_chunks;i++) { t_info[i].position = pos + 12; t_info[i].status = PLAYING; t_info[i].time = get_dtime(data,&t_info[i].position); pos += (( (0xff & data[pos + 5]) << 8 ) + (0xff & data[pos + 4])); } lcsec = 0; SEQ_START_TIMER(); do { low_chunk = -1; k++; i=0; do { if (t_info[i].status == PLAYING) low_chunk = i; i++; } while((low_chunk <=0) && (i<n_chunks)); if (low_chunk == -1) break; low_dtime = t_info[low_chunk].time; for(i=1;i<n_chunks;i++) { if ((t_info[i].time < low_dtime) && (t_info[i].status == PLAYING)) { low_dtime = t_info[i].time; low_chunk = i; } } if (low_dtime < 0) con_printf(CON_URGENT,"Serious warning: d_time negative!!!!!!\n"); csec = 0.86 * low_dtime; //flush sequencer buffer after 20 events if (k == 20) { ioctl(seqfd, SNDCTL_SEQ_SYNC); k = 0; } #ifdef WANT_AWE32 cut_trough(); #endif if (csec != lcsec) { SEQ_WAIT_TIME(csec); } lcsec = csec; t_info[low_chunk].status = do_track_event(data,&t_info[low_chunk].position); if (t_info[low_chunk].status == 3) { con_printf(CON_URGENT,"Error playing data in chunk %d\n",low_chunk); t_info[low_chunk].status = STOPPED; } if (t_info[low_chunk].status == PLAYING) t_info[low_chunk].time += get_dtime(data,&t_info[low_chunk].position); //Check if the song has reached the end stop = t_info[0].status; for(i=1;i<n_chunks;i++) stop &= t_info[i].status; if((do_ipc(qid,rcv,IPC_NOWAIT) > 0) && (rcv->mtext[0]=='p')) { n_chunks=data[0x30]; t_info = realloc(t_info,sizeof(Track_info)*n_chunks); stop = 1; rcv->mtext[0] = '0'; stop_all(); } } while(!stop); SEQ_STOP_TIMER(); if( stop == 2) { stop_all(); do { ipc_read=do_ipc(qid,rcv,0); } while(rcv->mtext[0] != 'p'); rcv->mtext[0] = '0'; n_chunks=data[0x30]; t_info = realloc(t_info,sizeof(Track_info)*n_chunks); stop = 0; } pos=0x308; } free(data); free(t_info); free(rcv); }
int main( int argc, char *argv[] ) { int i, k, t_num, arg_offset; long j; float f; pthread_t *t; thread_arg *thd_arg; timer_t timer; struct itimerval itval; struct sigaction sigact; int port= 3306; int fd, seed; printf("***************************************\n"); printf("*** ###easy### TPC-C Load Generator ***\n"); printf("***************************************\n"); /* initialize */ hist_init(); activate_transaction = 1; counting_on = 0; for ( i=0; i<5; i++ ){ success[i]=0; late[i]=0; retry[i]=0; failure[i]=0; prev_s[i]=0; prev_l[i]=0; max_rt[i]=0.0; } /* dummy initialize*/ num_ware = 1; num_conn = 10; num_neword_per_10_sec = 10; lampup_time = 10; measure_time = 20; strcpy( db_string, "tpcc" ); /* number of node (default 0) */ num_node = 0; arg_offset = 0; /* alarm initialize */ time_count = 0; itval.it_interval.tv_sec = PRINT_INTERVAL; itval.it_interval.tv_usec = 0; itval.it_value.tv_sec = PRINT_INTERVAL; itval.it_value.tv_usec = 0; sigact.sa_handler = alarm_handler; sigact.sa_flags = 0; sigemptyset(&sigact.sa_mask); /* setup handler&timer */ if( sigaction( SIGALRM, &sigact, NULL ) == -1 ) { fprintf(stderr, "error in sigaction()\n"); exit(1); } clk_tck = sysconf(_SC_CLK_TCK); /* Parse args */ if ((num_node == 0)&&(argc == 14)) { /* hidden mode */ valuable_flg = 1; } printf("argc = %d\n",argc); if ((num_node == 0)&&(valuable_flg == 0)&&(argc != 11)) { fprintf(stderr, "\n usage: tpcc_start [server] [DB] [user] [pass] [warehouse] [connection] [rampup] [measure] [neword-per-ten-sec] [socket]\n"); exit(1); } if ( strlen(argv[1]) >= DB_STRING_MAX ) { fprintf(stderr, "\n server phrase is too long\n"); exit(1); } if ( strlen(argv[2]) >= DB_STRING_MAX ) { fprintf(stderr, "\n DBname phrase is too long\n"); exit(1); } if ( strlen(argv[3]) >= DB_STRING_MAX ) { fprintf(stderr, "\n user phrase is too long\n"); exit(1); } if ( strlen(argv[4]) >= DB_STRING_MAX ) { fprintf(stderr, "\n pass phrase is too long\n"); exit(1); } if ((num_ware = atoi(argv[5 + arg_offset])) <= 0) { fprintf(stderr, "\n expecting positive number of warehouses\n"); exit(1); } if ((num_conn = atoi(argv[6 + arg_offset])) <= 0) { fprintf(stderr, "\n expecting positive number of connections\n"); exit(1); } if ((lampup_time = atoi(argv[7 + arg_offset])) < 0) { fprintf(stderr, "\n expecting positive number of lampup_time [sec]\n"); exit(1); } if ((measure_time = atoi(argv[8 + arg_offset])) < 0) { fprintf(stderr, "\n expecting positive number of measure_time [sec]\n"); exit(1); } if ((num_neword_per_10_sec = atoi(argv[9 + arg_offset])) < 0) { fprintf(stderr, "\n expecting positive number of neword-per-ten-sec\n"); exit(1); } if (parse_host_get_port(&port, argv[1]) < 0) { fprintf(stderr, "cannot prase the host: %s\n", argv[1]); exit(1); } strcpy( db_string, argv[2] ); strcpy( db_user, argv[3] ); strcpy( db_password, argv[4] ); strcpy( db_socket, argv[10] ); if(strcmp(argv[1],"localhost")==0){ is_local = 1; }else{ is_local = 0; } if(valuable_flg==1){ if( (atoi(argv[9 + arg_offset]) < 0)||(atoi(argv[10 + arg_offset]) < 0)||(atoi(argv[11 + arg_offset]) < 0) ||(atoi(argv[12 + arg_offset]) < 0)||(atoi(argv[13 + arg_offset]) < 0) ) { fprintf(stderr, "\n expecting positive number of ratio parameters\n"); exit(1); } } if( num_node > 0 ){ if( num_ware % num_node != 0 ){ fprintf(stderr, "\n [warehouse] value must be devided by [num_node].\n"); exit(1); } if( num_conn % num_node != 0 ){ fprintf(stderr, "\n [connection] value must be devided by [num_node].\n"); exit(1); } } printf("<Parameters>\n"); if(is_local==0) { printf(" [server]: "); for (i = 0; i < count_connect_strings; i++) { printf("%s%s", i ? ", " : "", connect_strings[i]); } printf("\n"); } if(is_local==0)printf(" [port]: %d\n", port); if(is_local==1)printf(" [socket]: %s\n", db_socket); printf(" [DBname]: %s\n", db_string); printf(" [user]: %s\n", db_user); printf(" [pass]: %s\n", db_password); printf(" [warehouse]: %d\n", num_ware); printf(" [connection]: %d\n", num_conn); printf(" [rampup]: %d (sec.)\n", lampup_time); printf(" [measure]: %d (sec.)\n", measure_time); printf("[neword-per-ten-sec]: %d\n", num_neword_per_10_sec); if(valuable_flg==1){ printf(" [ratio]: %d:%d:%d:%d:%d\n", atoi(argv[9 + arg_offset]), atoi(argv[10 + arg_offset]), atoi(argv[11 + arg_offset]), atoi(argv[12 + arg_offset]), atoi(argv[13 + arg_offset]) ); } fd = open("/dev/urandom", O_RDONLY); if (fd == -1) { fd = open("/dev/random", O_RDONLY); if (fd == -1) { struct timeval tv; gettimeofday(&tv, NULL); seed = (tv.tv_sec ^ tv.tv_usec) * tv.tv_sec * tv.tv_usec ^ tv.tv_sec; }else{ read(fd, &seed, sizeof(seed)); close(fd); } }else{ read(fd, &seed, sizeof(seed)); close(fd); } SetSeed(seed); if(valuable_flg==0){ seq_init(10,10,1,1,1); /* normal ratio */ }else{ seq_init( atoi(argv[9 + arg_offset]), atoi(argv[10 + arg_offset]), atoi(argv[11 + arg_offset]), atoi(argv[12 + arg_offset]), atoi(argv[13 + arg_offset]) ); } /* set up each counter */ for ( i=0; i<5; i++ ){ success2[i] = malloc( sizeof(int) * num_conn ); late2[i] = malloc( sizeof(int) * num_conn ); retry2[i] = malloc( sizeof(int) * num_conn ); failure2[i] = malloc( sizeof(int) * num_conn ); for ( k=0; k<num_conn; k++ ){ success2[i][k] = 0; late2[i][k] = 0; retry2[i][k] = 0; failure2[i][k] = 0; } } /* set up threads */ t = malloc( sizeof(pthread_t) * num_conn ); if ( t == NULL ){ fprintf(stderr, "error at malloc(pthread_t)\n"); exit(1); } thd_arg = malloc( sizeof(thread_arg) * num_conn ); if( thd_arg == NULL ){ fprintf(stderr, "error at malloc(thread_arg)\n"); exit(1); } ctx = malloc( sizeof(MYSQL *) * num_conn ); stmt = malloc( sizeof(MYSQL_STMT **) * num_conn ); for( i=0; i < num_conn; i++ ){ stmt[i] = malloc( sizeof(MYSQL_STMT *) * 40 ); } if ( ctx == NULL ){ fprintf(stderr, "error at malloc(sql_context)\n"); exit(1); } /* EXEC SQL WHENEVER SQLERROR GOTO sqlerr; */ for( i=0; i < num_conn; i++ ){ ctx[i] = mysql_init(NULL); if(!ctx[i]) goto sqlerr; } for( t_num=0; t_num < num_conn; t_num++ ){ thd_arg[t_num].port= port; thd_arg[t_num].number= t_num; pthread_create( &t[t_num], NULL, (void *)thread_main, (void *)&(thd_arg[t_num]) ); } printf("\nRAMP-UP TIME.(%d sec.)\n",lampup_time); fflush(stdout); sleep(lampup_time); printf("\nMEASURING START.\n\n"); fflush(stdout); /* sleep(measure_time); */ /* start timer */ #ifndef _SLEEP_ONLY_ if( setitimer(ITIMER_REAL, &itval, NULL) == -1 ) { fprintf(stderr, "error in setitimer()\n"); } #endif counting_on = 1; /* wait signal */ for(i = 0; i < (measure_time / PRINT_INTERVAL); i++ ) { #ifndef _SLEEP_ONLY_ pause(); #else sleep(PRINT_INTERVAL); alarm_dummy(); #endif } counting_on = 0; #ifndef _SLEEP_ONLY_ /* stop timer */ itval.it_interval.tv_sec = 0; itval.it_interval.tv_usec = 0; itval.it_value.tv_sec = 0; itval.it_value.tv_usec = 0; if( setitimer(ITIMER_REAL, &itval, NULL) == -1 ) { fprintf(stderr, "error in setitimer()\n"); } #endif printf("\nSTOPPING THREADS"); activate_transaction = 0; /* wait threads' ending and close connections*/ for( i=0; i < num_conn; i++ ){ pthread_join( t[i], NULL ); } printf("\n"); free(ctx); for( i=0; i < num_conn; i++ ){ free(stmt[i]); } free(stmt); free(t); free(thd_arg); hist_report(); printf("\n<Raw Results>\n"); for ( i=0; i<5; i++ ){ printf(" [%d] sc:%d lt:%d rt:%d fl:%d \n", i, success[i], late[i], retry[i], failure[i]); } printf(" in %d sec.\n", (measure_time / PRINT_INTERVAL) * PRINT_INTERVAL); printf("\n<Raw Results2(sum ver.)>\n"); for( i=0; i<5; i++ ){ success2_sum[i] = 0; late2_sum[i] = 0; retry2_sum[i] = 0; failure2_sum[i] = 0; for( k=0; k<num_conn; k++ ){ success2_sum[i] += success2[i][k]; late2_sum[i] += late2[i][k]; retry2_sum[i] += retry2[i][k]; failure2_sum[i] += failure2[i][k]; } } for ( i=0; i<5; i++ ){ printf(" [%d] sc:%d lt:%d rt:%d fl:%d \n", i, success2_sum[i], late2_sum[i], retry2_sum[i], failure2_sum[i]); } printf("\n<Constraint Check> (all must be [OK])\n [transaction percentage]\n"); for ( i=0, j=0; i<5; i++ ){ j += (success[i] + late[i]); } f = 100.0 * (float)(success[1] + late[1])/(float)j; printf(" Payment: %3.2f%% (>=43.0%%)",f); if ( f >= 43.0 ){ printf(" [OK]\n"); }else{ printf(" [NG] *\n"); } f = 100.0 * (float)(success[2] + late[2])/(float)j; printf(" Order-Status: %3.2f%% (>= 4.0%%)",f); if ( f >= 4.0 ){ printf(" [OK]\n"); }else{ printf(" [NG] *\n"); } f = 100.0 * (float)(success[3] + late[3])/(float)j; printf(" Delivery: %3.2f%% (>= 4.0%%)",f); if ( f >= 4.0 ){ printf(" [OK]\n"); }else{ printf(" [NG] *\n"); } f = 100.0 * (float)(success[4] + late[4])/(float)j; printf(" Stock-Level: %3.2f%% (>= 4.0%%)",f); if ( f >= 4.0 ){ printf(" [OK]\n"); }else{ printf(" [NG] *\n"); } printf(" [response time (at least 90%% passed)]\n"); f = 100.0 * (float)success[0]/(float)(success[0] + late[0]); printf(" New-Order: %3.2f%% ",f); if ( f >= 90.0 ){ printf(" [OK]\n"); }else{ printf(" [NG] *\n"); } f = 100.0 * (float)success[1]/(float)(success[1] + late[1]); printf(" Payment: %3.2f%% ",f); if ( f >= 90.0 ){ printf(" [OK]\n"); }else{ printf(" [NG] *\n"); } f = 100.0 * (float)success[2]/(float)(success[2] + late[2]); printf(" Order-Status: %3.2f%% ",f); if ( f >= 90.0 ){ printf(" [OK]\n"); }else{ printf(" [NG] *\n"); } f = 100.0 * (float)success[3]/(float)(success[3] + late[3]); printf(" Delivery: %3.2f%% ",f); if ( f >= 90.0 ){ printf(" [OK]\n"); }else{ printf(" [NG] *\n"); } f = 100.0 * (float)success[4]/(float)(success[4] + late[4]); printf(" Stock-Level: %3.2f%% ",f); if ( f >= 90.0 ){ printf(" [OK]\n"); }else{ printf(" [NG] *\n"); } printf("\n<TpmC>\n"); f = (float)(success[0] + late[0]) * 60.0 / (float)((measure_time / PRINT_INTERVAL) * PRINT_INTERVAL); printf(" %.3f TpmC\n",f); exit(0); sqlerr: fprintf(stdout, "error at main\n"); error(ctx[i],0); exit(1); }
static void seq_public (struct msgs *mp, int lockflag) { int state; char *cp, seqfile[PATH_MAX]; char name[NAMESZ], field[BUFSIZ]; FILE *fp; m_getfld_state_t gstate = 0; /* * If mh_seq == NULL or if *mh_seq == '\0' (the user has defined * the "mh-sequences" profile entry, but left it empty), * then just return, and do not initialize any public sequences. */ if (mh_seq == NULL || *mh_seq == '\0') return; /* get filename of sequence file */ snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq); if ((fp = lkfopendata (seqfile, lockflag ? "r+" : "r")) == NULL) return; /* Use m_getfld to scan sequence file */ for (;;) { int fieldsz = sizeof field; switch (state = m_getfld (&gstate, name, field, &fieldsz, fp)) { case FLD: case FLDPLUS: if (state == FLDPLUS) { cp = getcpy (field); while (state == FLDPLUS) { fieldsz = sizeof field; state = m_getfld (&gstate, name, field, &fieldsz, fp); cp = add (field, cp); } seq_init (mp, getcpy (name), trimcpy (cp)); free (cp); } else { seq_init (mp, getcpy (name), trimcpy (field)); } continue; case BODY: lkfclosedata (fp, seqfile); adios (NULL, "no blank lines are permitted in %s", seqfile); /* fall */ case FILEEOF: break; default: lkfclosedata (fp, seqfile); adios (NULL, "%s is poorly formatted", seqfile); } break; /* break from for loop */ } m_getfld_state_destroy (&gstate); if (lockflag) { mp->seqhandle = fp; mp->seqname = getcpy(seqfile); } else { lkfclosedata (fp, seqfile); } }
int main (int argc, char *argv[]) { Array intervals; Interval *currInterval; SubInterval *currSubInterval; int h,i,j; Array seqs; Seq *currSeq,testSeq; int index; Stringa buffer; Array geneTranscriptEntries; Texta geneTranscriptIds; Array alterations; Alteration *currAlteration,*nextAlteration; char *proteinSequenceBeforeIndel; char *proteinSequenceAfterIndel; int numDisabledTranscripts; Stringa disabledTranscripts; int seqLength,refLength,altLength; char *sequenceBeforeIndel = NULL; int overlapMode; int numOverlaps; int sizeIndel,indelOffset; int overlap; Array coordinates; VcfEntry *currVcfEntry; VcfGenotype *currVcfGenotype; int position; Texta alternateAlleles; int flag1,flag2; if (argc != 3) { usage ("%s <annotation.interval> <annotation.fa>",argv[0]); } intervalFind_addIntervalsToSearchSpace (argv[1],0); geneTranscriptEntries = util_getGeneTranscriptEntries (intervalFind_getAllIntervals ()); seq_init (); fasta_initFromFile (argv[2]); seqs = fasta_readAllSequences (0); fasta_deInit (); arraySort (seqs,(ARRAYORDERF)util_sortSequencesByName); buffer = stringCreate (100); disabledTranscripts = stringCreate (100); alterations = arrayCreate (100,Alteration); vcf_init ("-"); stringPrintf (buffer,"##INFO=<ID=VA,Number=.,Type=String,Description=\"Variant Annotation, %s\">",argv[1]); vcf_addComment (string (buffer)); puts (vcf_writeMetaData ()); puts (vcf_writeColumnHeaders ()); while (currVcfEntry = vcf_nextEntry ()) { if (vcf_isInvalidEntry (currVcfEntry)) { continue; } flag1 = 0; flag2 = 0; position = currVcfEntry->position - 1; // make zero-based alternateAlleles = vcf_getAlternateAlleles (currVcfEntry); for (h = 0; h < arrayMax (alternateAlleles); h++) { refLength = strlen (currVcfEntry->referenceAllele); altLength = strlen (textItem (alternateAlleles,h)); sizeIndel = abs (refLength - altLength); indelOffset = MAX (refLength,altLength) - 1; util_clearAlterations (alterations); intervals = intervalFind_getOverlappingIntervals (currVcfEntry->chromosome,position,position + indelOffset); for (i = 0; i < arrayMax (intervals); i++) { currInterval = arru (intervals,i,Interval*); overlapMode = OVERLAP_NONE; numOverlaps = 0; for (j = 0; j < arrayMax (currInterval->subIntervals); j++) { currSubInterval = arrp (currInterval->subIntervals,j,SubInterval); overlap = rangeIntersection (position,position + indelOffset,currSubInterval->start,currSubInterval->end); if (currSubInterval->start <= position && (position + indelOffset) < currSubInterval->end) { overlapMode = OVERLAP_FULLY_CONTAINED; numOverlaps++; } else if (j == 0 && overlap > 0 && position < currSubInterval->start) { overlapMode = OVERLAP_START; numOverlaps++; } else if (j == (arrayMax (currInterval->subIntervals) - 1) && overlap > 0 && (position + indelOffset) >= currSubInterval->end) { overlapMode = OVERLAP_END; numOverlaps++; } else if (overlap > 0 && overlap <= indelOffset) { overlapMode = OVERLAP_SPLICE; numOverlaps++; } } if (overlapMode == OVERLAP_NONE) { continue; } currAlteration = arrayp (alterations,arrayMax (alterations),Alteration); if (numOverlaps > 1) { util_addAlteration (currAlteration,currInterval->name,"multiExonHit",currInterval,position,0); continue; } else if (numOverlaps == 1 && overlapMode == OVERLAP_SPLICE) { util_addAlteration (currAlteration,currInterval->name,"spliceOverlap",currInterval,position,0); continue; } else if (numOverlaps == 1 && overlapMode == OVERLAP_START) { util_addAlteration (currAlteration,currInterval->name,"startOverlap",currInterval,position,0); continue; } else if (numOverlaps == 1 && overlapMode == OVERLAP_END) { util_addAlteration (currAlteration,currInterval->name,"endOverlap",currInterval,position,0); continue; } else if (numOverlaps == 1 && overlapMode == OVERLAP_FULLY_CONTAINED && altLength > refLength) { if ((sizeIndel % 3) == 0) { util_addAlteration (currAlteration,currInterval->name,"insertionNFS",currInterval,position,0); } else { util_addAlteration (currAlteration,currInterval->name,"insertionFS",currInterval,position,0); } } else if (numOverlaps == 1 && overlapMode == OVERLAP_FULLY_CONTAINED && altLength < refLength) { if ((sizeIndel % 3) == 0) { util_addAlteration (currAlteration,currInterval->name,"deletionNFS",currInterval,position,0); } else { util_addAlteration (currAlteration,currInterval->name,"deletionFS",currInterval,position,0); } } else if (numOverlaps == 1 && overlapMode == OVERLAP_FULLY_CONTAINED && altLength == refLength) { util_addAlteration (currAlteration,currInterval->name,"substitution",currInterval,position,0); } else { die ("Unexpected type: %d %s %s %s", currVcfEntry->position,currVcfEntry->chromosome, currVcfEntry->referenceAllele,currVcfEntry->alternateAllele); } if ((sizeIndel % 3) != 0 && altLength != refLength) { continue; } // Only run the remaining block of code if the indel is fully contained (insertion or deletion) AND does not cause a frameshift OR // if it is a substitution that is fully contained in the coding sequence stringPrintf (buffer,"%s|%s|%c|",currInterval->name,currInterval->chromosome,currInterval->strand); for (j = 0; j < arrayMax (currInterval->subIntervals); j++) { currSubInterval = arrp (currInterval->subIntervals,j,SubInterval); stringAppendf (buffer,"%d|%d%s",currSubInterval->start,currSubInterval->end,j < arrayMax (currInterval->subIntervals) - 1 ? "|" : ""); } testSeq.name = hlr_strdup (string (buffer)); if (!arrayFind (seqs,&testSeq,&index,(ARRAYORDERF)util_sortSequencesByName)) { die ("Expected to find %s in seqs",string (buffer)); } hlr_free (testSeq.name); currSeq = arrp (seqs,index,Seq); strReplace (&sequenceBeforeIndel,currSeq->sequence); seqLength = strlen (sequenceBeforeIndel); coordinates = util_getCoordinates (currInterval); // arraySort (coordinates,(ARRAYORDERF)util_sortCoordinatesByChromosomeAndTranscriptPosition); Array is already sorted by definition j = 0; stringClear (buffer); while (j < seqLength) { if (util_getGenomicCoordinate (coordinates,j,currVcfEntry->chromosome) == position) { if (altLength > refLength) { stringCat (buffer,textItem (alternateAlleles,h)); j++; continue; } else if (altLength < refLength) { stringCatChar (buffer,sequenceBeforeIndel[j]); j = j + refLength - altLength + 1; continue; } else { stringCat (buffer,textItem (alternateAlleles,h)); j = j + altLength; continue; } } stringCatChar (buffer,sequenceBeforeIndel[j]); j++; } util_destroyCoordinates (coordinates); proteinSequenceBeforeIndel = hlr_strdup (util_translate (currInterval,sequenceBeforeIndel)); proteinSequenceAfterIndel = hlr_strdup (util_translate (currInterval,string (buffer))); addSubstitution (currAlteration,proteinSequenceBeforeIndel,proteinSequenceAfterIndel,indelOffset); hlr_free (proteinSequenceBeforeIndel); hlr_free (proteinSequenceAfterIndel); } if (arrayMax (alterations) == 0) { continue; } arraySort (alterations,(ARRAYORDERF)util_sortAlterationsByGeneIdAndType); stringClear (buffer); i = 0; while (i < arrayMax (alterations)) { currAlteration = arrp (alterations,i,Alteration); stringAppendf (buffer,"%s%d:%s:%s:%c:%s",stringLen (buffer) == 0 ? "" : ",",h + 1,currAlteration->geneName,currAlteration->geneId,currAlteration->strand,currAlteration->type); stringClear (disabledTranscripts); if (currAlteration->substitution[0] != '\0') { stringAppendf (disabledTranscripts,"%s:%s:%d_%d_%s",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength,currAlteration->relativePosition,currAlteration->substitution); } else if (strEqual (currAlteration->type,"multiExonHit") || strEqual (currAlteration->type,"spliceOverlap") || strEqual (currAlteration->type,"startOverlap") || strEqual (currAlteration->type,"endOverlap")) { stringAppendf (disabledTranscripts,"%s:%s:%d",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength); } else { stringAppendf (disabledTranscripts,"%s:%s:%d_%d",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength,currAlteration->relativePosition); } numDisabledTranscripts = 1; j = i + 1; while (j < arrayMax (alterations)) { nextAlteration = arrp (alterations,j,Alteration); if (strEqual (currAlteration->geneId,nextAlteration->geneId) && strEqual (currAlteration->type,nextAlteration->type)) { if (nextAlteration->substitution[0] != '\0') { stringAppendf (disabledTranscripts,":%s:%s:%d_%d_%s",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength,nextAlteration->relativePosition,nextAlteration->substitution); } else if (strEqual (nextAlteration->type,"multiExonHit") || strEqual (nextAlteration->type,"spliceOverlap") || strEqual (nextAlteration->type,"startOverlap") || strEqual (nextAlteration->type,"endOverlap")) { stringAppendf (disabledTranscripts,":%s:%s:%d",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength); } else { stringAppendf (disabledTranscripts,":%s:%s:%d_%d",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength,nextAlteration->relativePosition); } numDisabledTranscripts++; } else { break; } j++; } i = j; geneTranscriptIds = util_getTranscriptIdsForGeneId (geneTranscriptEntries,currAlteration->geneId); stringAppendf (buffer,":%d/%d:%s",numDisabledTranscripts,arrayMax (geneTranscriptIds),string (disabledTranscripts)); } if (flag1 == 0) { printf ("%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s;VA=", currVcfEntry->chromosome,currVcfEntry->position,currVcfEntry->id, currVcfEntry->referenceAllele,currVcfEntry->alternateAllele, currVcfEntry->quality,currVcfEntry->filter,currVcfEntry->info); flag1 = 1; } printf ("%s%s",flag2 == 1 ? "," : "",string (buffer)); flag2 = 1; } if (flag1 == 1) { for (i = 0; i < arrayMax (currVcfEntry->genotypes); i++) { currVcfGenotype = arrp (currVcfEntry->genotypes,i,VcfGenotype); if (i == 0) { printf ("\t%s\t",currVcfEntry->genotypeFormat); } printf ("%s%s%s%s",currVcfGenotype->genotype, currVcfGenotype->details[0] != '\0' ? ":" : "", currVcfGenotype->details[0] != '\0' ? currVcfGenotype->details : "", i < arrayMax (currVcfEntry->genotypes) - 1 ? "\t" : ""); } puts (""); } } vcf_deInit (); return 0; }
int restore( FILE *file, const char *filename) { char *path_p; struct stat stat; uid_t uid; gid_t gid; seq_t seq = NULL; int line = 0, backup_line; int error, status = 0; memset(&stat, 0, sizeof(stat)); for(;;) { backup_line = line; error = read_acl_comments(file, &line, &path_p, &uid, &gid); if (error < 0) goto fail; if (error == 0) return 0; if (path_p == NULL) { if (filename) { fprintf(stderr, _("%s: %s: No filename found " "in line %d, aborting\n"), progname, xquote(filename), backup_line); } else { fprintf(stderr, _("%s: No filename found in " "line %d of standard input, " "aborting\n"), progname, backup_line); } goto getout; } if (!(seq = seq_init())) goto fail; if (seq_append_cmd(seq, CMD_REMOVE_ACL, ACL_TYPE_ACCESS) || seq_append_cmd(seq, CMD_REMOVE_ACL, ACL_TYPE_DEFAULT)) goto fail; error = read_acl_seq(file, seq, CMD_ENTRY_REPLACE, SEQ_PARSE_WITH_PERM | SEQ_PARSE_NO_RELATIVE | SEQ_PARSE_DEFAULT | SEQ_PARSE_MULTI, &line, NULL); if (error != 0) { fprintf(stderr, _("%s: %s: %s in line %d\n"), progname, xquote(filename), strerror(errno), line); goto getout; } error = lstat(path_p, &stat); if (opt_test && error != 0) { fprintf(stderr, "%s: %s: %s\n", progname, xquote(path_p), strerror(errno)); status = 1; } stat.st_uid = uid; stat.st_gid = gid; error = do_set(path_p, &stat, seq); if (error != 0) { status = 1; goto resume; } if (!opt_test && (uid != ACL_UNDEFINED_ID || gid != ACL_UNDEFINED_ID)) { if (chown(path_p, uid, gid) != 0) { fprintf(stderr, _("%s: %s: Cannot change " "owner/group: %s\n"), progname, xquote(path_p), strerror(errno)); status = 1; } } resume: if (path_p) { free(path_p); path_p = NULL; } if (seq) { seq_free(seq); seq = NULL; } } getout: if (path_p) { free(path_p); path_p = NULL; } if (seq) { seq_free(seq); seq = NULL; } return status; fail: fprintf(stderr, "%s: %s: %s\n", progname, xquote(filename), strerror(errno)); status = 1; goto getout; }
void play_hmi (void * arg) { int i; int pos = 0x308; int n_chunks = 0; int low_dtime; int low_chunk; int csec; // pid_t loc_pid; int qid; int ipc_read = 0; int k=0; struct msgbuf *rcv; Track_info *t_info; //printf ("play_hmi\n");//######### stop = 0; ipc_read=0; // loc_pid=fork(); /* switch (loc_pid) { case 0: break; case -1: return -1; default: atexit(kill_ipc); return loc_pid; }*/ // signal(SIGTERM, my_quit); rcv=d_malloc(sizeof(long) + 16); rcv->mtype=1; rcv->mtext[0]='0'; sleep(2); qid=msgget ((key_t) ('l'<<24) | ('d'<<16) | ('e'<<8) | 's', 0660); if(qid == -1) { return; } do { ipc_read=do_ipc(qid,rcv,0); } while(rcv->mtext[0] != 'p'); stop=0; rcv->mtext[0] = '0'; seq_init(); n_chunks=data[0x30]; t_info = d_malloc(sizeof(Track_info)*n_chunks); while(1) { for(i=0;i<n_chunks;i++) { t_info[i].position = pos + 12; t_info[i].status = PLAYING; t_info[i].time = get_dtime(data,&t_info[i].position); pos += (( (0xff & data[pos + 5]) << 8 ) + (0xff & data[pos + 4]); } SEQ_START_TIMER(); do { low_chunk = -1; k++; i=0; do { if (t_info[i].status == PLAYING) low_chunk = i; i++; } while((low_chunk <=0) && (i<n_chunks); if (low_chunk == -1) break; low_dtime = t_info[low_chunk].time; for(i=1;i<n_chunks;i++) { if ((t_info[i].time < low_dtime) && (t_info[i].status == PLAYING)) { low_dtime = t_info[i].time; low_chunk = i; } } //if (low_dtime < 0) //printf("Serious warning: d_time negative!!!!!!\n"); csec = 0.86 * low_dtime; //flush sequencer buffer after 20 events if (k == 20) { ioctl(seqfd, SNDCTL_SEQ_SYNC); k = 0; } SEQ_WAIT_TIME(csec); t_info[low_chunk].status = do_track_event(data,&t_info[low_chunk].position); if (t_info[low_chunk].status == 3) { //printf("Error playing data in chunk %d\n",low_chunk); t_info[low_chunk].status = STOPPED; } if (t_info[low_chunk].status == PLAYING) t_info[low_chunk].time += get_dtime(data,&t_info[low_chunk].position); //Check if the song has reached the end stop = t_info[0].status; for(i=1;i<n_chunks;i++) stop &= t_info[i].status; if((do_ipc(qid,rcv,IPC_NOWAIT) > 0) && (rcv->mtext[0]=='p')) { n_chunks=data[0x30]; t_info = realloc(t_info,sizeof(Track_info)*n_chunks); stop = 1; rcv->mtext[0] = '0'; stop_all(); } } while(!stop); SEQ_STOP_TIMER(); if( stop == 2) { stop_all(); do { ipc_read=do_ipc(qid,rcv,0); } while(rcv->mtext[0] != 'p'); rcv->mtext[0] = '0'; n_chunks=data[0x30]; t_info = realloc(t_info,sizeof(Track_info)*n_chunks); stop = 0; } pos=0x308; } d_free(data); d_free(t_info); d_free(rcv); }
int restore( FILE *file, const char *filename) { char *path_p; struct stat st; uid_t uid; gid_t gid; mode_t mask, flags; struct do_set_args args = { }; int line = 0, backup_line; int error, status = 0; int chmod_required = 0; memset(&st, 0, sizeof(st)); for(;;) { backup_line = line; error = read_acl_comments(file, &line, &path_p, &uid, &gid, &flags); if (error < 0) { error = -error; goto fail; } if (error == 0) return status; if (path_p == NULL) { if (filename) { fprintf(stderr, _("%s: %s: No filename found " "in line %d, aborting\n"), progname, xquote(filename, "\n\r"), backup_line); } else { fprintf(stderr, _("%s: No filename found in " "line %d of standard input, " "aborting\n"), progname, backup_line); } status = 1; goto getout; } if (!(args.seq = seq_init())) goto fail_errno; if (seq_append_cmd(args.seq, CMD_REMOVE_ACL, ACL_TYPE_ACCESS) || seq_append_cmd(args.seq, CMD_REMOVE_ACL, ACL_TYPE_DEFAULT)) goto fail_errno; error = read_acl_seq(file, args.seq, CMD_ENTRY_REPLACE, SEQ_PARSE_WITH_PERM | SEQ_PARSE_DEFAULT | SEQ_PARSE_MULTI, &line, NULL); if (error != 0) { fprintf(stderr, _("%s: %s: %s in line %d\n"), progname, xquote(filename, "\n\r"), strerror(errno), line); status = 1; goto getout; } error = stat(path_p, &st); if (opt_test && error != 0) { fprintf(stderr, "%s: %s: %s\n", progname, xquote(path_p, "\n\r"), strerror(errno)); status = 1; } args.mode = 0; error = do_set(path_p, &st, 0, &args); if (error != 0) { status = 1; goto resume; } if (uid != ACL_UNDEFINED_ID && uid != st.st_uid) st.st_uid = uid; else st.st_uid = -1; if (gid != ACL_UNDEFINED_ID && gid != st.st_gid) st.st_gid = gid; else st.st_gid = -1; if (!opt_test && (st.st_uid != -1 || st.st_gid != -1)) { if (chown(path_p, st.st_uid, st.st_gid) != 0) { fprintf(stderr, _("%s: %s: Cannot change " "owner/group: %s\n"), progname, xquote(path_p, "\n\r"), strerror(errno)); status = 1; } /* chown() clears setuid/setgid so force a chmod if * S_ISUID/S_ISGID was expected */ if ((st.st_mode & flags) & (S_ISUID | S_ISGID)) chmod_required = 1; } mask = S_ISUID | S_ISGID | S_ISVTX; if (chmod_required || ((st.st_mode & mask) != (flags & mask))) { if (!args.mode) args.mode = st.st_mode; args.mode &= (S_IRWXU | S_IRWXG | S_IRWXO); if (chmod(path_p, flags | args.mode) != 0) { fprintf(stderr, _("%s: %s: Cannot change " "mode: %s\n"), progname, xquote(path_p, "\n\r"), strerror(errno)); status = 1; } } resume: if (path_p) { free(path_p); path_p = NULL; } if (args.seq) { seq_free(args.seq); args.seq = NULL; } } getout: if (path_p) { free(path_p); path_p = NULL; } if (args.seq) { seq_free(args.seq); args.seq = NULL; } return status; fail_errno: error = errno; fail: fprintf(stderr, "%s: %s: %s\n", progname, xquote(filename, "\n\r"), strerror(error)); status = 1; goto getout; }