static rc_t CC CGEvidenceIntervals20_Read(const CGEvidenceIntervals15* cself, TEvidenceIntervalsData* data) { rc_t rc = 0; CG_LINE_START(cself->file, b, len, p); if( b == NULL || len == 0) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcDone); break; } /*DEBUG_MSG(10, ("evidenceIntervals: '%.*s'\n", len, b));*/ CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, data->interval_id, sizeof(data->interval_id)); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, data->chr, sizeof(data->chr)); CG_LINE_NEXT_FIELD(b, len, p); rc = str2i32(b, p - b, &data->offset); CG_LINE_NEXT_FIELD(b, len, p); rc = str2u32(b, p - b, &data->length); CG_LINE_NEXT_FIELD(b, len, p); rc = str2u16(b, p - b, &data->ploidy); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, data->allele_indexes, sizeof(data->allele_indexes)); CG_LINE_NEXT_FIELD(b, len, p); rc = str2i32(b, p - b, &data->scoreVAF); data->score = data->scoreVAF; /***TODO: do we need re-calculation? ***/ CG_LINE_NEXT_FIELD(b, len, p); rc = str2i32(b, p - b, &data->scoreEAF); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, data->allele[0], sizeof(data->allele[0])); data->allele_length[0] = p - b; CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, data->allele[1], sizeof(data->allele[1])); data->allele_length[1] = p - b; CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, data->allele[2], sizeof(data->allele[2])); data->allele_length[2] = p - b; CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, data->allele[3], sizeof(data->allele[3])); data->allele_length[3] = p - b; CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, data->allele_alignment[1], sizeof(data->allele_alignment[1])); data->allele_alignment_length[1] = p - b; CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, data->allele_alignment[2], sizeof(data->allele_alignment[2])); data->allele_alignment_length[2] = p - b; CG_LINE_LAST_FIELD(b, len, p); rc = str2buf(b, p - b, data->allele_alignment[3], sizeof(data->allele_alignment[3])); data->allele_alignment_length[3] = p - b; ((CGEvidenceIntervals15*)cself)->records++; DEBUG_MSG(10, ( "evidenceIntervals: '%s'\t'%s'\t%i\t%u\t%u\t%s\t%u\t%u\t'%s'\t'%s'\t'%s'\t'%s'\t'%s'\t'%s'\t'%s'\n", data->interval_id, data->chr, data->offset, data->length, data->ploidy, data->allele_indexes, data->scoreVAF, data->scoreEAF, data->allele[0], data->allele[1], data->allele[2], data->allele[3], data->allele_alignment[1], data->allele_alignment[2], data->allele_alignment[3])); CG_LINE_END(); return rc; }
static rc_t CC CGReads15_Read(const CGReads15* cself, TReadsData* data) { rc_t rc = 0; if( cself->start_rowid == 0 ) { ((CGReads15*)cself)->start_rowid = data->rowid; } CG_LINE_START(cself->file, b, len, p); if( b == NULL || len == 0) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcDone); break; } /*DEBUG_MSG(10, ("reads: '%.*s'\n", len, b));*/ CG_LINE_NEXT_FIELD(b, len, p); if( (rc = str2u16(b, p - b, &data->flags)) != 0 ) { } else if( data->flags > 10 ) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcOutofrange); } else if( (data->flags & 0x03) == 3 || (data->flags & 0x07) == 7 ) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcInvalid); } CG_LINE_NEXT_FIELD(b, len, p); data->seq.sequence.elements = p - b; if( data->seq.sequence.elements != CG_READS_SPOT_LEN ) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcInvalid); } else { rc = str2buf(b, data->seq.sequence.elements, data->read, sizeof(data->read)); /* clear cache, set in algnment writer */ data->reverse[0] = '\0'; data->reverse[CG_READS_SPOT_LEN / 2] = '\0'; } CG_LINE_LAST_FIELD(b, len, p); data->seq.quality.elements = p - b; if( data->seq.quality.elements != CG_READS_SPOT_LEN ) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcInvalid); } else { rc = str2buf(b, data->seq.quality.elements, data->qual, sizeof(data->qual)); } if( cself->records == 0 ) { size_t w; #if 0 rc = string_printf(((CGReads15*)cself)->spot_group, sizeof(cself->spot_group), &w, "%s:%s:%s:%04u", cself->assembly_id, cself->slide, cself->lane, cself->batch_file_number); #else rc = string_printf(((CGReads15*)cself)->spot_group, sizeof(cself->spot_group), &w, "%s-%s", cself->slide, cself->lane); #endif data->seq.spot_group.buffer = cself->spot_group; data->seq.spot_group.elements = w; } ((CGReads15*)cself)->records++; DEBUG_MSG(10, ("reads: %u\t'%s'\t'%s'\n", data->flags, data->read, data->qual)); CG_LINE_END(); return rc; }
EXPORT_CODE long CONVENTION get_parameter_information_string(const char *param, char * Output, int n) { try{ int key = CoolProp::get_parameter_index(param); if (key >= 0){ std::string s = CoolProp::get_parameter_information(key, Output); return str2buf(s, Output, n) ? 1 : 0; } else{ str2buf(format("parameter is invalid: %s", param), Output, n); } } catch(...){} return 0; }
EXPORT_CODE long CONVENTION get_fluid_param_string(const char *fluid, const char *param, char * Output, int n) { try{ std::string s = CoolProp::get_fluid_param_string(std::string(fluid), std::string(param)); return str2buf(s, Output, n) ? 1 : 0; } catch(...){ return 0; } }
EXPORT_CODE long CONVENTION get_fluid_param_string(const char *fluid, const char *param, char * Output, int n) { try{ std::string s = CoolProp::get_fluid_param_string(std::string(fluid), std::string(param)); str2buf(s, Output, n); return 1; } catch (std::exception &e){ CoolProp::set_error_string(e.what()); } catch (...){ CoolProp::set_error_string("Undefined error"); } return 0; }
EXPORT_CODE long CONVENTION PhaseSI(const char *Name1, double Prop1, const char *Name2, double Prop2, const char * FluidName, char *phase, int n) { fpu_reset_guard guard; try{ std::string s = CoolProp::PhaseSI(std::string(Name1), Prop1, std::string(Name2), Prop2, std::string(FluidName)); str2buf(s, phase, n); return 1; } catch (std::exception &e){ CoolProp::set_error_string(e.what()); } catch (...){ CoolProp::set_error_string("Undefined error"); } return 0; }
static int read_link_keys(uint16_t index, uint16_t nb_keys, bdaddr_t bdaddrs[nb_keys], unsigned char keys[nb_keys][16]) { char file_path[PATH_MAX]; bdaddr_t ba; char dongle_bdaddr[18]; if(bt_device_abs_get(bt_abs_value)->get_bdaddr(index, &ba) < 0) { fprintf(stderr, "can't read device bdaddr\n"); return -1; } ba2str(&ba, dongle_bdaddr); snprintf(file_path, sizeof(file_path), "%s%s%s%s/%s", gimx_params.homedir, GIMX_DIR, BT_DIR, dongle_bdaddr, "linkkeys"); char line[LINE_MAX]; FILE* file = fopen(file_path, "r"); int i = 0; if (!file) { fprintf(stderr, "Can't open '%s'.\n", file_path); return -1; } else { while (fgets(line, LINE_MAX, file) && i < nb_keys) { line[17] = '\0'; str2ba(line, bdaddrs+i); str2buf(line+18, keys[i], sizeof(keys[i])); ++i; } fclose(file); } return 0; }
static rc_t CC CGReads15_Header(const CGReads15* cself, const char* buf, const size_t len) { rc_t rc = 0; size_t slen; CGReads15* self = (CGReads15*)cself; if( strncmp("ASSEMBLY_ID\t", buf, slen = 12) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->assembly_id, sizeof(self->assembly_id)); } else if( strncmp("BATCH_FILE_NUMBER\t", buf, slen = 18) == 0 ) { rc = str2u32(&buf[slen], len - slen, &self->batch_file_number); if( self->batch_file_number < 1 ) { rc = RC(rcRuntime, rcFile, rcConstructing, rcItem, rcOutofrange); } } else if( strncmp("BATCH_OFFSET\t", buf, slen = 13) == 0 ) { rc = str2u64(&buf[slen], len - slen, &self->batch_offset); } else if( strncmp("FIELD_SIZE\t", buf, slen = 11) == 0 ) { rc = str2u32(&buf[slen], len - slen, &self->field_size); } else if( strncmp("GENERATED_AT\t", buf, slen = 13) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->generated_at, sizeof(self->generated_at)); } else if( strncmp("GENERATED_BY\t", buf, slen = 13) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->generated_by, sizeof(self->generated_by)); } else if( strncmp("LANE\t", buf, slen = 5) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->lane, sizeof(self->lane)); } else if( strncmp("LIBRARY\t", buf, slen = 8) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->library, sizeof(self->library)); } else if( strncmp("SAMPLE\t", buf, slen = 7) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->sample, sizeof(self->sample)); } else if( strncmp("SLIDE\t", buf, slen = 6) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->slide, sizeof(self->slide)); } else if( strncmp("SOFTWARE_VERSION\t", buf, slen = 17) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->software_version, sizeof(self->software_version)); } else { rc = RC(rcRuntime, rcFile, rcConstructing, rcName, rcUnrecognized); } return rc; }
EXPORT_CODE long CONVENTION get_parameter_information_string(const char *param, char * Output, int n) { try{ int key = CoolProp::get_parameter_index(param); std::string s = CoolProp::get_parameter_information(key, Output); str2buf(s, Output, n); return 1; } catch (std::exception& e){ // if param is wrong, CoolProp::get_parameter_index throws string like // "Your input name [%s] is not valid in get_parameter_index (names are case sensitive)" // CoolProp::get_parameter_information throws string like // "Bad info string [%s] to get_parameter_information" (if Output is wrong) // or "Unable to match the key [%d] in get_parameter_information for info [%s]" // (see src/DataStructures.cpp) // if n is too small, str2buf throws string // "Buffer size is too small" CoolProp::set_error_string(format("get_parameter_information_string(\"%s\", \"%s\", %d): %s", param, Output, n, e.what())); } catch(...){ CoolProp::set_error_string(format("get_parameter_information_string(\"%s\", \"%s\", %d): Undefined error", param, Output, n)); } return 0; }
static rc_t CC CGEvidenceIntervals15_Header(const CGEvidenceIntervals15* cself, const char* buf, const size_t len) { rc_t rc = 0; size_t slen; CGEvidenceIntervals15* self = (CGEvidenceIntervals15*)cself; if( strncmp("ASSEMBLY_ID\t", buf, slen = 12) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->assembly_id, sizeof(self->assembly_id)); } else if( strncmp("CHROMOSOME\t", buf, slen = 11) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->chromosome, sizeof(self->chromosome)); } else if( strncmp("GENERATED_AT\t", buf, slen = 13) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->generated_at, sizeof(self->generated_at)); } else if( strncmp("GENERATED_BY\t", buf, slen = 13) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->generated_by, sizeof(self->generated_by)); } else if( strncmp("SAMPLE\t", buf, slen = 7) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->sample, sizeof(self->sample)); } else if( strncmp("SOFTWARE_VERSION\t", buf, slen = 17) == 0 ) { rc = str2buf(&buf[slen], len - slen, self->software_version, sizeof(self->software_version)); } else { rc = RC(rcRuntime, rcFile, rcConstructing, rcName, rcUnrecognized); } return rc; }
static rc_t CC CGReads25_Header(const CGReads15* cself, const char* buf, const size_t len) { rc_t rc = 0; size_t slen = 0; CGReads15* self = (CGReads15*)cself; /* from SRA-2617 files */ if (strncmp("APPROVAL\t", buf, slen = 9) == 0) { } else if (strncmp("TITLE\t", buf, slen = 6) == 0) { } else if (strncmp("ADDRESS\t", buf, slen = 8) == 0) { } /* From Table 1: Header Metadata Present in all Data Files */ else if (strncmp("CUSTOMER_SAMPLE_ID\t", buf, slen = 19) == 0) { } else if (strncmp("SAMPLE_SOURCE\t", buf, slen = 14) == 0) { } else if (strncmp("REPORTED_GENDER\t", buf, slen = 16) == 0) { } else if (strncmp("CALLED_GENDER\t", buf, slen = 14) == 0) { } else if (strncmp("TUMOR_STATUS\t", buf, slen = 13) == 0) { } else if (strncmp("LIBRARY_TYPE\t", buf, slen = 13) == 0) { } else if (strncmp("LIBRARY_SOURCE\t", buf, slen = 13) == 0) { } else if (strncmp("ASSEMBLY_ID\t", buf, slen = 12) == 0) { rc = str2buf(&buf[slen], len - slen, self->assembly_id, sizeof(self->assembly_id)); } else if (strncmp("BATCH_FILE_NUMBER\t", buf, slen = 18) == 0) { rc = str2u32(&buf[slen], len - slen, &self->batch_file_number); if (self->batch_file_number < 1) { rc = RC(rcRuntime, rcFile, rcConstructing, rcItem, rcOutofrange); } } else if (strncmp("BATCH_OFFSET\t", buf, slen = 13) == 0) { rc = str2u64(&buf[slen], len - slen, &self->batch_offset); } else if (strncmp("FIELD_SIZE\t", buf, slen = 11) == 0) { rc = str2u32(&buf[slen], len - slen, &self->field_size); } else if (strncmp("GENERATED_AT\t", buf, slen = 13) == 0) { rc = str2buf(&buf[slen], len - slen, self->generated_at, sizeof(self->generated_at)); } else if (strncmp("GENERATED_BY\t", buf, slen = 13) == 0) { rc = str2buf(&buf[slen], len - slen, self->generated_by, sizeof(self->generated_by)); } else if (strncmp("LANE\t", buf, slen = 5) == 0) { rc = str2buf(&buf[slen], len - slen, self->lane, sizeof(self->lane)); } else if (strncmp("LIBRARY\t", buf, slen = 8) == 0) { rc = str2buf(&buf[slen], len - slen, self->library, sizeof(self->library)); } else if (strncmp("SAMPLE\t", buf, slen = 7) == 0) { rc = str2buf(&buf[slen], len - slen, self->sample, sizeof(self->sample)); } else if (strncmp("SLIDE\t", buf, slen = 6) == 0) { rc = str2buf(&buf[slen], len - slen, self->slide, sizeof(self->slide)); } else if (strncmp("SOFTWARE_VERSION\t", buf, slen = 17) == 0) { rc = str2buf(&buf[slen], len - slen, self->software_version, sizeof(self->software_version)); } else { rc = RC(rcRuntime, rcFile, rcConstructing, rcName, rcUnrecognized); } return rc; }
EXPORT_CODE long CONVENTION PhaseSI(const char *Name1, double Prop1, const char *Name2, double Prop2, const char * FluidName, char *phase, int n) { std::string s = CoolProp::PhaseSI(std::string(Name1), Prop1, std::string(Name2), Prop2, std::string(FluidName)); reset_fpu(); return str2buf(s, phase, n) ? 1 : 0; }
int main(int argc, char *argv[]) { int c; /* options character */ int type = 0; /* type of accounting */ int modified = 0; /* have we modified any properties? */ acctconf_t ac; /* current configuration */ char *typestr = NULL; /* type of accounting argument string */ char *enabled = NULL; /* enabled resources string */ char *disabled = NULL; /* disabled resources string */ char *file = NULL; int Eflg = 0; int Dflg = 0; int rflg = 0; int sflg = 0; int xflg = 0; int optcnt = 0; int state; const char *fmri; /* FMRI for this instance */ int err = 0; setup_privs(); (void) setlocale(LC_ALL, ""); (void) textdomain(TEXT_DOMAIN); (void) setpname(argv[0]); for (; optind < argc; optind++) { while ((c = getopt(argc, argv, OPTS)) != (int)EOF) { switch (c) { case 'd': disabled = optarg; break; case 'e': enabled = optarg; break; case 'D': Dflg = 1; optcnt++; break; case 'E': Eflg = 1; optcnt++; break; case 'f': file = optarg; optcnt++; break; case 'r': rflg = 1; optcnt++; break; case 's': sflg = 1; optcnt++; break; case 'x': xflg = 1; optcnt++; break; case '?': default: usage(); } } /* * Permanently give up euid 0, egid 0 and privileges we * don't need for the specified options. */ if (!(file || sflg)) { if (setreuid(getuid(), getuid()) == -1 || setregid(getgid(), getgid()) == -1) die(gettext("setreuid()/setregid() failed")); (void) priv_set(PRIV_OFF, PRIV_PERMITTED, PRIV_FILE_DAC_WRITE, NULL); } if (!(disabled || enabled || Dflg || Eflg || file || sflg || xflg)) (void) priv_set(PRIV_OFF, PRIV_PERMITTED, PRIV_SYS_ACCT, PRIV_SYS_DL_CONFIG, NULL); if (optind < argc) { if (typestr != NULL) { warn(gettext("illegal argument -- %s\n"), argv[optind]); usage(); } else { typestr = argv[optind]; } } } if (typestr != NULL) { if (strcmp(typestr, "process") == 0 || strcmp(typestr, "proc") == 0) type |= AC_PROC; else if (strcmp(typestr, "task") == 0) type |= AC_TASK; else if (strcmp(typestr, "flow") == 0) type |= AC_FLOW; else if (strcmp(typestr, "net") == 0) type |= AC_NET; else { warn(gettext("unknown accounting type -- %s\n"), typestr); usage(); } } else type = AC_PROC | AC_TASK | AC_FLOW | AC_NET; /* * Drop the DL config privilege if we are not working with * net. */ if ((type & AC_NET) == 0) { (void) priv_set(PRIV_OFF, PRIV_PERMITTED, PRIV_SYS_DL_CONFIG, NULL); } /* * check for invalid options */ if (optcnt > 1) usage(); /* * XXX For AC_NET, enabled/disabled should only be "basic" or * "extended" - need to check it here. */ if ((enabled || disabled) && (rflg || Dflg || sflg || xflg || Eflg)) usage(); if ((file || xflg || Dflg || Eflg || enabled || disabled) && !typestr) { warn(gettext("accounting type must be specified\n")); usage(); } if (rflg) { printgroups(type); return (E_SUCCESS); } /* * If no arguments have been passed then just print out the current * state and exit. */ if (!enabled && !disabled && !file && !Eflg && !rflg && !Dflg && !sflg && !xflg) { aconf_print(stdout, type); return (E_SUCCESS); } /* Open the libdladm handle */ if (dladm_open(&dld_handle) != DLADM_STATUS_OK) die(gettext("failed to open dladm handle\n")); /* * smf(5) start method. The FMRI to operate on is retrieved from the * SMF_FMRI environment variable that the restarter provides. */ if (sflg) { if ((fmri = getenv("SMF_FMRI")) != NULL) { int ret = aconf_setup(fmri); dladm_close(dld_handle); return (ret); } die(gettext("-s option should only be invoked by smf(5)\n")); } assert(type == AC_PROC || type == AC_TASK || type == AC_FLOW || type == AC_NET); if ((type == AC_FLOW || type == AC_NET) && getzoneid() != GLOBAL_ZONEID) die(gettext("%s accounting cannot be configured in " "non-global zones\n"), ac_type_name(type)); fmri = aconf_type2fmri(type); if (aconf_scf_init(fmri) == -1) die(gettext("cannot connect to repository for %s\n"), fmri); /* * Since the sys_acct the privilege allows use of acctctl() regardless * of the accounting type, we check the smf(5) authorizations granted * to the user to determine whether the user is allowed to change the * configuration for this particular accounting type. */ if (!aconf_have_smf_auths()) die(gettext("insufficient authorization to change %s extended " "accounting configuration\n"), ac_type_name(type)); if (xflg) { /* * Turn off the specified accounting and close its file */ /* * Stop net logging before turning it off so that the last * set of logs can be written. */ if (type & AC_NET) { (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); err = dladm_stop_usagelog(dld_handle, DLADM_LOGTYPE_FLOW); (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); if (err != DLADM_STATUS_OK) { die(gettext("failed to stop logging network " "information, error %d\n"), errno); } } state = AC_OFF; (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); if (acctctl(type | AC_STATE_SET, &state, sizeof (int)) == -1) die(gettext("cannot disable %s accounting"), ac_type_name(type)); if (acctctl(type | AC_FILE_SET, NULL, 0) == -1) die(gettext("cannot close %s accounting file\n"), ac_type_name(type)); (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); if (aconf_set_bool(AC_PROP_STATE, B_FALSE) == -1) die(gettext("cannot update %s property\n"), AC_PROP_STATE); if (aconf_set_string(AC_PROP_FILE, AC_STR_NONE) == -1) die(gettext("cannot update %s property\n"), AC_PROP_FILE); modified++; } if (enabled || disabled) { char *tracked, *untracked; ac_res_t *buf; /* * Enable/disable resources */ if ((buf = malloc(AC_BUFSIZE)) == NULL) die(gettext("not enough memory\n")); (void) memset(buf, 0, AC_BUFSIZE); if (acctctl(type | AC_RES_GET, buf, AC_BUFSIZE) == -1) { free(buf); die(gettext("cannot obtain list of resources\n")); } if (disabled) { /* * Stop net logging before turning it off so that the * last set of logs can be written. */ if (type & AC_NET) { (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); err = dladm_stop_usagelog(dld_handle, strcmp(disabled, "basic") == 0 ? DLADM_LOGTYPE_LINK : DLADM_LOGTYPE_FLOW); (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); if (err != DLADM_STATUS_OK) { die(gettext("failed to stop logging " "network information, error %d\n"), errno); } } str2buf(buf, disabled, AC_OFF, type); } else if (enabled) { str2buf(buf, enabled, AC_ON, type); } (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); if (acctctl(type | AC_RES_SET, buf, AC_BUFSIZE) == -1) { free(buf); die(gettext("cannot enable/disable %s accounting " "resources\n"), ac_type_name(type)); } (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); tracked = buf2str(buf, AC_BUFSIZE, AC_ON, type); untracked = buf2str(buf, AC_BUFSIZE, AC_OFF, type); if (aconf_set_string(AC_PROP_TRACKED, tracked) == -1) die(gettext("cannot update %s property\n"), AC_PROP_TRACKED); if (aconf_set_string(AC_PROP_UNTRACKED, untracked) == -1) die(gettext("cannot update %s property\n"), AC_PROP_UNTRACKED); free(tracked); free(untracked); free(buf); modified++; } if (file) { /* * Open new accounting file */ (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); if (open_exacct_file(file, type) == -1) { dladm_close(dld_handle); exit(E_ERROR); } if (aconf_set_string(AC_PROP_FILE, file) == -1) die(gettext("cannot update %s property\n"), AC_PROP_FILE); state = AC_ON; if (acctctl(type | AC_STATE_SET, &state, sizeof (int)) == -1) die(gettext("cannot enable %s accounting"), ac_type_name(type)); (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); if (aconf_set_bool(AC_PROP_STATE, B_TRUE) == -1) die(gettext("cannot update %s property\n"), AC_PROP_STATE); modified++; } /* * Let's get network logging started. We do this after turning on * accounting and opening the file so that we can start writing * immediately. */ if (enabled && (type & AC_NET)) { /* * Default logging interval for AC_NET is * ACCTADM_NET_LOG_INTERVAL. */ (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); err = dladm_start_usagelog(dld_handle, strcmp(enabled, "basic") == 0 ? DLADM_LOGTYPE_LINK : DLADM_LOGTYPE_FLOW, ACCTADM_NET_LOG_INTERVAL); (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); if (err != DLADM_STATUS_OK) { die(gettext("failed to start logging " "network information, error %d\n"), errno); } } if (Dflg) { /* * Disable accounting */ /* * Stop net logging before turning it off so that the last * set of logs can be written. */ if (type & AC_NET) { (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); err = dladm_stop_usagelog(dld_handle, DLADM_LOGTYPE_FLOW); (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); if (err != DLADM_STATUS_OK) { die(gettext("failed to stop logging " "network information, error %d\n"), errno); } } state = AC_OFF; (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); if (acctctl(type | AC_STATE_SET, &state, sizeof (int)) == -1) die(gettext("cannot disable %s accounting"), ac_type_name(type)); (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); if (aconf_set_bool(AC_PROP_STATE, B_FALSE) == -1) die(gettext("cannot update %s property\n"), AC_PROP_STATE); modified++; } if (Eflg) { /* * Enable accounting */ /* * Let's get network logging started. */ if (type & AC_NET) { /* * Default logging interval for AC_NET is * ACCTADM_NET_LOG_INTERVAL. */ (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); err = dladm_start_usagelog(dld_handle, DLADM_LOGTYPE_FLOW, ACCTADM_NET_LOG_INTERVAL); (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_DL_CONFIG, NULL); if (err != DLADM_STATUS_OK) { die(gettext("failed to start logging " "network information, error %d\n"), errno); } } state = AC_ON; (void) priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); if (acctctl(type | AC_STATE_SET, &state, sizeof (int)) == -1) die(gettext("cannot enable %s accounting"), ac_type_name(type)); (void) priv_set(PRIV_OFF, PRIV_EFFECTIVE, PRIV_SYS_ACCT, NULL); if (aconf_set_bool(AC_PROP_STATE, B_TRUE) == -1) die(gettext("cannot update %s property\n"), AC_PROP_STATE); modified++; } (void) priv_set(PRIV_OFF, PRIV_PERMITTED, PRIV_SYS_ACCT, NULL); if (modified) { char *smf_state; if (aconf_save() == -1) die(gettext("cannot save %s accounting " "configuration\n"), ac_type_name(type)); /* * Enable or disable the instance depending on the effective * configuration. If the effective configuration results in * extended accounting being 'on', the instance is enabled so * the configuration is applied at the next boot. */ smf_state = smf_get_state(fmri); aconf_init(&ac, type); if (ac.state == AC_ON || strcmp(ac.file, AC_STR_NONE) != 0 || strcmp(ac.tracked, AC_STR_NONE) != 0) { if (strcmp(smf_state, SCF_STATE_STRING_ONLINE) != 0) if (smf_enable_instance(fmri, 0) == -1) die(gettext("cannot enable %s\n"), fmri); } else { if (strcmp(smf_state, SCF_STATE_STRING_ONLINE) == 0) if (smf_disable_instance(fmri, 0) == -1) die(gettext("cannot disable %s\n"), fmri); } free(smf_state); } aconf_scf_fini(); dladm_close(dld_handle); return (E_SUCCESS); }
static rc_t CC CGEvidenceDnbs_Read(const CGEvidenceDnbs15* cself, const char* interval_id, TEvidenceDnbsData* data, int score_allele_num) { rc_t rc = 0; TEvidenceDnbsData_dnb* m = NULL; static TEvidenceDnbsData_dnb next_rec; static char next_interval_id[32] = ""; /* local copy of unused TEvidenceDnbsData_dnb struct elements */ char reference_alignment[CG_EVDNC_ALLELE_CIGAR_LEN]; INSDC_coord_zero mate_offset_in_reference; char mate_reference_alignment[CG_EVDNC_ALLELE_CIGAR_LEN]; uint16_t score_allele[4] = {0, 0, 0, 0}; /* v1.5 has ScoreAllele[012]; v2.0 - [0123] */ char qual[CG_EVDNC_SPOT_LEN]; strcpy(data->interval_id, interval_id); data->qty = 0; /* already read one rec for this interval_id */ if( next_interval_id[0] != '\0' ) { if( strcmp(next_interval_id, interval_id) != 0 ) { /* nothing todo since next interval id is different */ return rc; } m = &data->dnbs[data->qty++]; memcpy(m, &next_rec, sizeof(next_rec)); DEBUG_MSG(10, ("%3u evidenceDnbs: '%s'\t'%s'\t'%s'\t'%s'\t%u\t%lu\t%hu\t%c\t%c\t%i\t'%.*s'" "\t%i\tnot_used\t0\tnot_used\t%c\t0\t0\t0\t'%.*s'\t'--'\n", data->qty, next_interval_id, m->chr, m->slide, m->lane, m->file_num_in_lane, m->dnb_offset_in_lane_file, m->allele_index, m->side, m->strand, m->offset_in_allele, m->allele_alignment_length, m->allele_alignment, m->offset_in_reference, m->mapping_quality, m->read_len, m->read)); } do { int i = 0; char tmp[2]; CG_LINE_START(cself->file, b, len, p); if( b == NULL || len == 0 ) { next_interval_id[0] = '\0'; break; /* EOF */ } if( data->qty >= data->max_qty ) { TEvidenceDnbsData_dnb* x; data->max_qty += 100; x = realloc(data->dnbs, sizeof(*(data->dnbs)) * data->max_qty); if( x == NULL ) { rc = RC(rcRuntime, rcFile, rcReading, rcMemory, rcExhausted); break; } data->dnbs = x; } m = &data->dnbs[data->qty++]; /*DEBUG_MSG(10, ("%2hu evidenceDnbs: '%.*s'\n", data->qty, len, b));*/ CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, next_interval_id, sizeof(next_interval_id)); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, m->chr, sizeof(m->chr)); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, m->slide, sizeof(m->slide)); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, m->lane, sizeof(m->lane)); CG_LINE_NEXT_FIELD(b, len, p); rc = str2u32(b, p - b, &m->file_num_in_lane); CG_LINE_NEXT_FIELD(b, len, p); rc = str2u64(b, p - b, &m->dnb_offset_in_lane_file); CG_LINE_NEXT_FIELD(b, len, p); rc = str2u16(b, p - b, &m->allele_index); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, tmp, sizeof(tmp)); if( tmp[0] != 'L' && tmp[0] != 'R' ) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcOutofrange); } m->side = tmp[0]; CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, tmp, sizeof(tmp)); if( tmp[0] != '+' && tmp[0] != '-' ) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcOutofrange); } m->strand = tmp[0]; CG_LINE_NEXT_FIELD(b, len, p); rc = str2i32(b, p - b, &m->offset_in_allele); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, m->allele_alignment, sizeof(m->allele_alignment)); m->allele_alignment_length = p - b; CG_LINE_NEXT_FIELD(b, len, p); rc = str2i32(b, p - b, &m->offset_in_reference); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, reference_alignment, sizeof(reference_alignment)); CG_LINE_NEXT_FIELD(b, len, p); rc = str2i32(b, p - b, &mate_offset_in_reference); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, mate_reference_alignment, sizeof(mate_reference_alignment)); CG_LINE_NEXT_FIELD(b, len, p); rc = str2buf(b, p - b, tmp, sizeof(tmp)); if( tmp[0] < 33 || tmp[0] > 126 ) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcOutofrange); } m->mapping_quality = tmp[0]; for (i = 0; i < score_allele_num; ++i) { CG_LINE_NEXT_FIELD(b, len, p); rc = str2u16(b, p - b, &score_allele[i]); if(rc){ score_allele[i] =0; rc =0; } } CG_LINE_NEXT_FIELD(b, len, p); m->read_len = p - b; rc = str2buf(b, m->read_len, m->read, sizeof(m->read)); CG_LINE_LAST_FIELD(b, len, p); if( m->read_len != p - b ) { rc = RC(rcRuntime, rcFile, rcReading, rcData, rcInconsistent); } else { rc = str2buf(b, p - b, qual, sizeof(qual)); } ((CGEvidenceDnbs15*)cself)->records++; if( strcmp(next_interval_id, data->interval_id) != 0 ) { if (score_allele_num == 3) { DEBUG_MSG(10, ("%3u evidenceDnbs: '%s'\t'%s'\t'%s'\t'%s'\t%u\t%lu\t%hu\t%c\t%c\t%i\t'%.*s'" "\t%i\t'%s'\t%i\t'%s'\t%c\t%hu\t%hu\t%hu\t'%.*s'\t'%s'\n", data->qty, next_interval_id, m->chr, m->slide, m->lane, m->file_num_in_lane, m->dnb_offset_in_lane_file, m->allele_index, m->side, m->strand, m->offset_in_allele, m->allele_alignment_length, m->allele_alignment, m->offset_in_reference, reference_alignment, mate_offset_in_reference, mate_reference_alignment, m->mapping_quality, score_allele[0], score_allele[1], score_allele[2], m->read_len, m->read, qual)); } else if (score_allele_num == 4) { DEBUG_MSG(10, ("%3u evidenceDnbs: '%s'\t'%s'\t'%s'\t'%s'\t%u\t%lu\t%hu\t%c\t%c\t%i\t'%.*s'" "\t%i\t'%s'\t%i\t'%s'\t%c\t%hu\t%hu\t%hu\t%hu\t'%.*s'\t'%s'\n", data->qty, next_interval_id, m->chr, m->slide, m->lane, m->file_num_in_lane, m->dnb_offset_in_lane_file, m->allele_index, m->side, m->strand, m->offset_in_allele, m->allele_alignment_length, m->allele_alignment, m->offset_in_reference, reference_alignment, mate_offset_in_reference, mate_reference_alignment, m->mapping_quality, score_allele[0], score_allele[1], score_allele[2], score_allele[3], m->read_len, m->read, qual)); } else { assert(0); } } CG_LINE_END(); if( next_interval_id[0] == '\0' ) { break; } if( strcmp(next_interval_id, data->interval_id) != 0 ) { /* next record is from next interval, remeber it and stop */ memcpy(&next_rec, m, sizeof(next_rec)); data->qty--; break; } } while( rc == 0 ); return rc; }
ATerm from_toolbus(int cid, ATerm t) { char *fname; ATerm event, msg; ATermList fargs; int pid1, pid2; ATerm Env, Subs, Notes, AtArgs, Coords; char *AtFun; ATerm pe; char *mon_point; reset_buffer(); if(ATmatch(t, "rec-do(<appl(<list>)>)", &fname, &fargs)) { str2buf(fname); char2buf(' '); if(!ATisEmpty(fargs)) args2buf(fargs); /*TBprintf(stderr, "calling function %s.\n", BUF);*/ if(Tcl_Eval(global_interp, BUF) != TCL_OK) { handle_error(global_interp, global_interp->result); } return NULL; } if(ATmatch(t, "rec-eval(<appl(<list>)>)", &fname, &fargs)) { str2buf(fname); char2buf(' '); if(!ATisEmpty(fargs)) args2buf(fargs); if(Tcl_Eval(global_interp, BUF) != TCL_OK) { handle_error(global_interp, global_interp->result); } if(global_interp->result) return TclString2Term(global_interp->result); return NULL; } if(ATmatch(t, "rec-ack-event(<term>)", &event)) { str2buf("rec-ack-event {"); term2buf(event); str2buf("}"); /*TBprintf(stderr, "calling function %s\n", BUF);*/ if(Tcl_Eval(global_interp, BUF) != TCL_OK) { handle_error(global_interp, global_interp->result); } return NULL; } if(ATmatch(t, "rec-monitor(<appl(<int>,<appl>,<term>,<term>,<term>," "<term>,<term>,<int>,<term>)>)", &mon_point, &pid1, &AtFun, &AtArgs, &Coords, &Env, &Subs, &Notes, &pid2, &pe)) { ATwarning("Monitor commands not implemented yet: %t\n", t); return NULL; } if(ATmatch(t, "rec-terminate(<term>)", &msg)) { str2buf("rec-terminate "); term2buf(msg); if(Tcl_Eval(global_interp, BUF) != TCL_OK) { handle_error(global_interp, global_interp->result); } } ATwarning("Ignored: %t\n", t); return NULL; }
static void term2buf(ATerm t) { ATerm annos = AT_getAnnotations(t); if(annos != NULL) { char2buf('{'); } switch(ATgetType(t)) { case AT_INT: wprintf("%d", ATgetInt((ATermInt)t)); break; case AT_REAL: wprintf("%f", ATgetReal((ATermReal)t)); break; case AT_APPL: { int cur_arg, arity; ATermAppl appl = (ATermAppl)t; AFun sym = ATgetSymbol(appl); if(ATisQuoted(sym)) qstr2buf(ATgetName(sym)); else str2buf(ATgetName(sym)); arity = ATgetArity(sym); if(arity > 0) { char2buf('('); for(cur_arg=0; cur_arg<arity; cur_arg++) { term2buf(ATgetArgument(appl, cur_arg)); if(cur_arg < (arity-1)) char2buf(','); } char2buf(')'); } } break; case AT_LIST: { ATermList l = (ATermList)t; char2buf('{'); while(!ATisEmpty(l)) { ATerm el = ATgetFirst(l); l = ATgetNext(l); term2buf(el); if(!ATisEmpty(l)) char2buf(' '); } char2buf('}'); } break; case AT_PLACEHOLDER: { char2buf('<'); term2buf(ATgetPlaceholder((ATermPlaceholder)t)); char2buf('>'); } break; case AT_BLOB: ATerror("blobs are not supported by tcltk-adapter!\n"); default: ATabort("illegal term type!\n"); } if(annos != NULL) { char2buf(' '); term2buf(annos); char2buf('}'); } }