void AdvancedSearchState::SetSizeFilter(Ui::MainWindow* window, SearchParameter& parameter) { QString option = window->sizeComboBox->currentText(); bool sizeIgnored = option.indexOf("Ignore") != -1; qint64 lowerSize = 0, upperSize = 0; if (sizeIgnored == false) { bool between = option.indexOf("Between") != -1; bool larger = option.indexOf("Larger") != -1; bool smaller = option.indexOf("Smaller") != -1; if (larger) lowerSize = units2bytes(QString("%1 %2").arg(window->sizeLineEdit->text()).arg( chop(window->sizeUnitsComboBox->currentText(), 4))); // chop 'ytes' if (smaller) upperSize = units2bytes(QString("%1 %2").arg(window->sizeLineEdit->text()).arg( chop(window->sizeUnitsComboBox->currentText(), 4))); // chop 'ytes' if (between) { lowerSize = units2bytes(QString("%1 %2").arg(window->sizeLineEdit->text()).arg( chop(window->sizeUnitsComboBox->currentText(), 4))); // chop 'ytes' upperSize = units2bytes(QString("%1 %2").arg(window->sizeLineEdit2->text()).arg( chop(window->sizeUnitsComboBox2->currentText(), 4))); } } parameter.phaseOneParam->SetSizeLowerBound(lowerSize); parameter.phaseOneParam->SetSizeUpperBound(upperSize); }
int chop(int target, int* array, size_t size) { // handle empty array if(size == 0) { return -1; } else if(size == 1) { // single element array - check value if(array[0] == target) { return 0; } else { return -1; } } else { // wider array are split into two parts and we search in the part in that the element should be int split = (size / 2); if(target < array[split]) { return chop(target, array, split); } else { int res; if((res = chop(target, array + split, size - split)) != -1) { return split + res; } else { return res; } } } }
void load_high_scores() { FILE *hiscores_file = fopen(options.full_path("hiscores"), "r"); num_high_scores = 0; if (!hiscores_file) { return; } char line[256]; char *not_empty; while (!feof(hiscores_file)) { // Get name not_empty = fgets(line, 256, hiscores_file); chop(line); if (line[0] == '\0' || !not_empty) break; strcpy(high_scores[num_high_scores].name, line); // Get score not_empty = fgets(line, 256, hiscores_file); chop(line); if (line[0] == '\0' || !not_empty) break; s32 the_score; intval(line, &the_score); high_scores[num_high_scores].score = the_score; num_high_scores++; } fclose(hiscores_file); }
void netchanNeedop(BotNet *source, char *rest) { BotNet *bn; BotInfo *binfo; char *channel; int guid; guid = a2i(chop(&rest)); channel = chop(&rest); if (errno || guid < 1 || !channel) return; botnet_relay(source,"CO%i %s\n",guid,channel); for(bn=botnetlist;bn;bn=bn->next) { if (bn->status != BN_LINKED) continue; for(binfo=bn->botinfo;binfo;binfo=binfo->next) { if (binfo->guid == guid) check_botinfo(binfo,channel); } } }
int read_seenlist_callback(char *rest) { char *nick,*uh,*pa,*pb; time_t when; int t; nick = chop(&rest); uh = chop(&rest); when = a2i(chop(&rest)); /* seen time, a2i handles NULL */ if (errno) return(FALSE); t = a2i(chop(&rest)); /* seen type, a2i handles NULL */ if (errno) return(FALSE); pa = chop(&rest); pb = rest; if ((now - when) < (SEEN_TIME * 86400)) { /* if (pa && !*pa) pa = NULL; chop() doesnt return empty strings */ if (!*pb) pb = NULL; make_seen(nick,uh,pa,pb,when,t); } return(FALSE); }
///Calculate Exp[I*m] LaGenMatComplex snake::math::expm2(LaGenMatDouble &m) { //std::cout<<m<<std::endl; int dim = m.size(0); LaGenMatComplex r(dim,dim); LaGenMatDouble eigvec(dim,dim); LaGenMatComplex eigvecC(dim,dim); LaVectorDouble eigval(dim); LaVectorComplex eigvalim(dim); eigvec = m; snake::math::SSMED(eigvec.addr(),dim,eigval.addr()); for(int i = 0;i<dim;i++) eigvalim(i) = LaComplex(cos(eigval(i)),sin(eigval(i))); LaGenMatComplex temp(dim,dim); temp = LaComplex(0,0); for(int i = 0;i<dim;i++) temp(i,i) = eigvalim(i); chop(temp,1e-15); //std::cout<<temp<<std::endl; eigvecC = eigvec.to_LaGenMatComplex(); LaGenMatComplex tempx(dim,dim); Blas_Mat_Mat_Trans_Mult(temp,eigvecC,tempx); Blas_Mat_Mat_Mult(eigvecC,tempx,r); chop(r,1e-15); return r; }
TEMP_PAR typename NUM_SYS::DigitSet NUM_SYS::getDigits(const Vector<INT_TYPE>& z) const { bool finished = false; IVector v = vector_traits_int::copy(z); DigitSet digits; digits.reserve(20); digits.push_back(v); v = chop(v); while(!finished) { if( find_if(digits.begin(), digits.end(), DigitFinder(v)) != digits.end()) { finished = true; } else { digits.push_back(v); v = chop(v); } } return digits; }
static void dirtodots(char *path, unsigned maxlen) { char *first_slash, *end_slash; first_slash = strchr(path, '/'); if(!first_slash) { chop(path, maxlen); return; } if(strncmp(first_slash+1, "...", 3) == 0) { end_slash = strchr(first_slash+5, '/'); } else end_slash = strchr(first_slash+1, '/'); if(!end_slash) { chop(path, maxlen); return; } if(end_slash - first_slash < 4) /* /fu/ */ strpush(first_slash+1, 4 - (end_slash - first_slash)); else /* /foobar/ */ strcpy(first_slash + 4, end_slash); strncpy(first_slash+1, "...", 3); }
void main() { allegrosetup(scrwid,scrhei); makesplitpalette(&redtowhitepalette,&greentowhitepalette); PPsetup(scrwid,scrhei,4); JBmp j=JBmp(scrwid,scrhei); j.clear(); List<Part> ps=List<Part>(); for (int i=1;i<=10;i++) { Part p; newpart(&p); ps+p; } int frame=0; do { for (int i=1;i<=ps.len;i++) { Part *p=ps.p2num(i); int sx,sy; PPgetscrpos(p->pos,&sx,&sy); int sxb,syb; PPgetscrpos(p->pos+V3d(p->rad,0,0),&sxb,&syb); float rad=sqrt(mysquare(sx-sxb)+mysquare(sy-syb)); j.filledcircle(sx,sy,rad,p->inc); // j.filledcirclenodarker(sx,sy,rad/3,p->inc); } for (int x=0;x<scrwid;x++) for (int y=0;y<scrhei;y++) { int k=j.bmp[y][x]; if (k==128) j.bmp[y][x]=0; if (k<128) j.bmp[y][x]=chop(k-4,0,128); else j.bmp[y][x]=128+chop(k-4-128,0,128); } j.writetoscreen(); Matrix m,n; V3d rotaxis=V3d::rotate(V3d(0,1,0),V3d(0,0,1),pi/4.0*sin(2*pi*frame/4000)); m.makerotation(rotaxis,pi/1000.0); n.makerotation(rotaxis,-pi/1000.0); for (int i=1;i<=ps.len;i++) { Part *p=ps.p2num(i); if (p->sgn>0) p->pos=m*p->pos; else p->pos=n*p->pos; p->pos=p->pos+V3d(0,0,-0.03); if (p->pos.z<-4 || max(myabs(p->pos.x),myabs(p->pos.y))>2) newpart(p); } frame++; } while (!key[KEY_ESC]); }
static void load_dsc() { s_objtab.clear(); Slice dsc = read_file("grafix/corri01.dsc"); chop_until(dsc, 0); // skip until first 0 byte while (dsc.len()) { // header: // void *img[3]; // U8 x, y; // U8 unk; // U8 cursorType, imgType; Slice header = chop(dsc, 17); Str name = to_string(chop_until(dsc, '\r')); Slice script = chop_until(dsc, 0); // fix up script for (U32 i=0; i < script.len(); i++) if (script[i] == '^') script[i] = '\n'; //print_hex(Str::fmt("%2d %8s: ", s_objtab.size(), name), header, 17); ObjectDesc d; d.script = script; d.gfx_name = name; d.x = header[12]; d.y = header[13]; d.flipX = header[14]; d.cursor = header[15]; // imgtype = header[16] s_objtab.push_back(d); } }
void usernameHandler(char *buffer, int sock) //handles username requests { grabContents(buffer); //get the actual message minus command chop(buffer); //chop off anything extraneous int x = 0; for (x = 0; x < MAX_USERS; x++) //check username with all users and return bad if not found { if (strcmp(users[x].username, buffer) == 0) { char tempBuffer[MAX_MESSAGE_SIZE]; sprintf(tempBuffer, " %dError: username '%s' all ready taken\n", NAME_TAKEN, buffer); writeMessageDefined(sock, tempBuffer); return; } } //if good return a good call and establish the username sprintf(users[sock].username, "%s", buffer); printf("\nUsername established: %s\n", users[sock].username); zeroBuffer(buffer); sprintf(buffer, "Server: Username established '%s'\n", users[sock].username); writeMessageDefined(sock, buffer); }
void do_rkicksay(COMMAND_ARGS) { /* * on_msg checks: CARGS */ KickSay *kick; char *channel; channel = chop(&rest); /* cant be NULL (CARGS) */ if (!ischannel(channel) && *channel != '*') goto usage; if (!*rest) goto usage; if (!(kick = find_kicksay(rest,channel))) { to_user(from,"I'm not kicking on that"); return; } to_user(from,"No longer kicking on %s",kick->mask); remove_kicksay(kick); current->ul_save++; return; usage: usage(from); /* usage for CurrentCmd->name */ }
int main(int argc,char**argv) { FILE *fi,*fo; char buf[256]; char *st; if(argc==2) { fi=fopen(argv[1],"r"); strcpy(buf,argv[1]); //strcpy(buf+strlen(buf)-4,".log"); // ".xxx"->".log" strcpy(buf+strlen(buf)-4,"_smile"); // ".xxx" -> "_smile.xxx" strcpy(buf+strlen(buf) ,argv[1]+strlen(argv[1])-4); fo=fopen(buf,"w"); while(st=fgets(buf,sizeof(buf),fi)){ chop(st); fprintf(fo,"%s(^^)/~\n",st); } fclose(fi); fclose(fo); return 0; } else { printf("USAGE: %s filename",argv[0]); return 0; } }
void CIMainWindow::startBuilding() { QString cmd(mCompilerPath); mProcBuild = new QProcess(this); if (mCompilerParamList.size() > 0) { QString str = mCompilerParamList[mBuildingCount++]; // TEST ONLY!!! str.remove(0, 1); str = "\"D:/!GEMS8/" + str; QString arg_sln = str.section(' ', 0, 0); auto arg_build = str.section(' ', 1, 1); auto arg_build_type = str.section(' ', 2); arg_sln.remove(0, 1); arg_sln.chop(1); arg_build_type.remove(0, 1); arg_build_type.chop(1); QStringList args; args << arg_sln << arg_build << arg_build_type; mProcBuild->setProgram(cmd); mProcBuild->setArguments(args); mProcBuild->start(); } QObject::connect(mProcBuild, SIGNAL(readyReadStandardOutput()), this, SLOT(on_readyReadBuildingStandardOutput())); QObject::connect(mProcBuild, SIGNAL(finished(int)), this, SLOT(buildAnotherSolutionOrDone())); }
int new_item( char *item, char *menu, char **tcl_lines, int line_no ) { int eax; char *token; int num_tokens; char entry[2048]; char command[2048]; char tmp[2048]; chop( item ); token = strtok( item, ";" ); if ( token == 0 ) { print_warning( "invalid token in 'entries-gisman'.\n" ); } else { strcpy( entry, token ); num_tokens = 0; for ( ; token == 0; num_tokens++ ) { token = strtok( 0, ";" ); if ( token ) strcpy( command, token ); // num_tokens++; } } return line_no; }
char * convert_flags_to_str(unsigned long flags) { unsigned int i; unsigned long p; static char buffer[290]; *buffer = 0; for (i = 0, p = 1; strflags[i]; i++, p <<= 1) { if (flags & p) { strmcat(buffer, strflags[i], 280); strmcat(buffer, ",", 280); } } for (i = 0, p = PROT_REOP; protflags[i]; i++, p <<= 1) { if (flags & p) { strmcat(buffer, protflags[i], 280); strmcat(buffer, ",", 280); } } if (*buffer) chop(buffer, 1); return buffer; }
static uclptr_t STRING_create (const void* sample_data) { if (sizeof(char*) <= sizeof(cell_t)) { uclptr_t storage_index = cell_alloc(); if (storage_index != NIL) { int length = strlen(sample_data) + 1; //char **storage_cell_ptr = (char**)&uclmem[storage_index]; char **storage_cell_ptr = (char**)&CONTAINER(storage_index); MANAGED(storage_index) = 1; *storage_cell_ptr = (char*)malloc(length); memset (*storage_cell_ptr, 0, length); strcpy (*storage_cell_ptr, sample_data); return storage_index; } } else /* физический указатель очень велик и не помещается даже на место целой ячейки */ { int length = strlen(sample_data) + 1; char *src = (char*)malloc(length); strcpy (src, sample_data); return chop (&src, sizeof(void*)); } return NIL; }
main() { int msqid; key_t msgkey; struct msgbuf{ long mtype; char mdata[256]; }; struct msgbuf msgdata,*p; p = &msgdata; printf("Enter message: "); fflush(stdin); fgets(p->mdata,BUFSIZ,stdin); p->mtype = 2; chop(p->mdata); // p->mtype = getpid(); msgkey = ftok("mrecv",'a'); msqid = msgget(msgkey,IPC_CREAT|0666); msgsnd(msqid,p,sizeof(p->mdata),0); }
QList<ImageSourceItem> QuaZipImageSource::getImageInfoFromArchive(QuaZip *archive, const QString &extractPath) { archive->open(QuaZip::mdUnzip); auto i = 0; auto images = QList<ImageSourceItem>(); auto fileNames = archive->getFileNameList(); fileNames.sort(Qt::CaseInsensitive); for (const auto &fileName : fileNames) { // Get the file information. auto fileInfo = QFileInfo(extractPath + "/" + fileName); auto suffix = fileInfo.suffix(); auto relativePath = fileName; relativePath.chop(fileInfo.fileName().length()); // Insert the file into the list if it is an image file. if (Utility::imageFileTypes().contains(suffix, Qt::CaseInsensitive)) { auto extractPath = fileInfo.absoluteFilePath(); auto image = std::make_shared<ImageInfo>(extractPath, relativePath); images.append({++i, image}); } } archive->close(); return images; }
int main(int argc, char * argv[]) { int nbytes = 1; char *str = (char *) malloc (nbytes + 1); char ** operand = (char **)malloc(2 * sizeof(char *)); int op; double rez; int flag = 0; while (getline(&str, (size_t *)&nbytes, stdin) > 0 ) { op = chop(str, operand); switch (op) { case 1: rez = atof(operand[0]) + atof(operand[1]); break; case 2: rez = atof(operand[0]) - atof(operand[1]); break; case 3: rez = atof(operand[0]) * atof(operand[1]); break; case 4: rez = atof(operand[0]) / atof(operand[1]); break; case 5: rez = pow(atof(operand[0]), atof(operand[1])); break; default: flag = 1; break; } if (flag) { printf("GRESKA!\n"); } else { printf("%.2lf\n", rez); } } return 0; }
int parse_proc_status(char *line) { const char *key; char *dest,*limit; int i; key = chop(&line); #ifdef DEBUG debug("pps key = %s (%s)\n",key,line); #endif if (key == NULL) return(FALSE); for(i=0;sv[i].key;i++) { if (strncmp(key,sv[i].key,sv[i].klen) == 0) { #ifdef DEBUG debug("(parse_proc_status) key %s -> %s\n",key,line); #endif /* DEBUG */ dest = sv[i].valbuf; limit = sv[i].valbuf + 31; while(*line == ' ') line++; while(*line && dest <= limit) *(dest++) = *(line++); *dest = 0; } } return(FALSE); }
int main( int argc, char *argv[] ) { FILE *f; char buf[256]; line *head, *curr; int linenum = 0; if( argc < 2 ) { puts( "line: Usage line filename" ); return 0; } f = fopen( argv[1], "r" ); head = new_line("", ' ', 0 ); curr = head; do { strset( buf, 0 ); fgets( buf, 255, f ); chop( buf ); trim( buf ); puts( buf ); if( strcmp(buf, "") ) { curr->next = (struct line *)new_line( buf, 'Q', ++linenum ); curr = (line *)curr->next; } } while( !feof(f) ); print_line_list( head ); return 0; }
/* * help_topic: Given a topic, we search the help directory, and try to * find the right file, if all is cool, and we can open it, or zcat it, * then we call help_prompt to get the actually displaying of the file * on the road. */ static void help_topic (char *path, char *name) { char *filename = (char *) 0; if (!name) return; /* what is the base name? */ malloc_sprintf(&filename, "%s/%s", path, name); if (filename[strlen(filename)-1] == '/') chop(filename, 1); /* let uzfopen have all the fun */ if ((help_fp = uzfopen(&filename, path, 1))) { /* Isnt this a heck of a lot better then the kludge you were using? */ help_put_it(name, "*** Help on %s", name); help_prompt(name, NULL); } else help_put_it (name, "*** No help available on %s: Use ? for list of topics", name); new_free(&filename); return; }
static void send_client_banner(int connection_out, int minor1) { /* Send our own protocol version identification. */ if (compat20) { #ifndef WIN32_FIXME xasprintf(&client_version_string, "SSH-%d.%d-%.100s\r\n", PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION); #else #ifdef WIN32_VS xasprintf(&client_version_string, "SSH-%d.%d-%.100sp1 Microsoft Win32 port with VS %s\r\n", PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION, __DATE__ ); #else xasprintf(&client_version_string, "SSH-%d.%d-%.100sp1 Microsoft Win32 port %s\r\n", PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION, __DATE__ ); #endif #endif } else { xasprintf(&client_version_string, "SSH-%d.%d-%.100s\n", PROTOCOL_MAJOR_1, minor1, SSH_VERSION); } if (roaming_atomicio(vwrite, connection_out, client_version_string, strlen(client_version_string)) != strlen(client_version_string)) fatal("write: %.100s", strerror(errno)); chop(client_version_string); debug("Local version string %.100s", client_version_string); }
QString LogData::doGetExpandedLineString( LineNumber line ) const { if ( line >= indexing_data_.getNbLines() ) { return ""; /* exception? */ } if ( keepFileClosed_ ) { reOpenFile(); } QByteArray rawString; { QMutexLocker locker( &fileMutex_ ); attached_file_->seek( ( line.get() == 0 ) ? 0 : indexing_data_.getPosForLine( line - 1_lcount).get() ); rawString = attached_file_->readLine(); if ( keepFileClosed_ ) { attached_file_->close(); } } auto string = untabify( codec_->toUnicode( rawString ) ); string.chop( 1 ); return string; }
QString DoubleSpinBox::textFromValue(double val) const { if (multiple) return ""; auto ans = locale().toString(val, 'f', decimals()); for (int i = 0; i < decimals() - 1; i++) if (ans.endsWith("0")) ans.chop(1); if (ans.endsWith("0")) ans.chop(2); return ans; }
int writeVector(vector_line_t * v, int dbg_mode) { FILE *out = stil_out; if (out == 0) { return 1; } //Write the header only where the first vector is to be written write_header(); int tabs = 1; if (v->loopcnt > 1) { if (fprintf (out, "\tLoop %d {\n", v->loopcnt) < 0 ) { close_delete_file(); return 1; } tabs++; } int tab; for (tab=0; tab<tabs; tab++) { if ( fprintf(out, "\t") < 0 ) { close_delete_file(); return 1; } } if (jtag_pin_count == 4) { chop((v->data)); } if ( fprintf (out, "V { %s = %s;}", jtag_grp_name, v->data ) < 0 ) { close_delete_file(); return 1; } if (dbg_mode) { if ( fprintf (out, "/* %s */\n", get_jtag_state_string(v->curr_state) ) < 0 ) { close_delete_file(); return 1; } } else { if ( fprintf (out, "\n", jtag_grp_name, v->data ) < 0 ) { close_delete_file(); return 1; } } if (v->loopcnt > 1) { if (fprintf (out, "\t}\n") < 0 ) { close_delete_file(); return 1; } tabs++; } return 0; }
Object* OgrFileImport::importPointGeometry(MapPart* map_part, OGRFeatureH feature, OGRGeometryH geometry) { auto style = OGR_F_GetStyleString(feature); auto symbol = getSymbol(Symbol::Point, style); if (symbol->getType() == Symbol::Point) { auto object = new PointObject(symbol); object->setPosition(toMapCoord(OGR_G_GetX(geometry, 0), OGR_G_GetY(geometry, 0))); map_part->addObject(object); return object; } else if (symbol->getType() == Symbol::Text) { const auto& description = symbol->getDescription(); auto length = description.length(); auto split = description.indexOf(QLatin1Char(' ')); Q_ASSERT(split > 0); Q_ASSERT(split < length); auto label = description.right(length - split - 1); if (label.startsWith('{') && label.endsWith('}')) { label.remove(0,1); label.chop(1); int index = OGR_F_GetFieldIndex(feature, label.toLatin1()); if (index >= 0) { label = QString(OGR_F_GetFieldAsString(feature, index)); } } if (!label.isEmpty()) { auto object = new TextObject(symbol); object->setAnchorPosition(toMapCoord(OGR_G_GetX(geometry, 0), OGR_G_GetY(geometry, 0))); // DXF observation label.replace(QRegularExpression("(\\\\[^;]*;)*", QRegularExpression::MultilineOption), QString::null); label.replace(QLatin1String("^I"), "\t"); object->setText(label); bool ok; auto anchor = QStringRef(&description, 1, 2).toInt(&ok); if (ok) { applyLabelAnchor(anchor, object); } auto angle = QStringRef(&description, 3, split-3).toFloat(&ok); if (ok) { object->setRotation(qDegreesToRadians(angle)); } map_part->addObject(object); return object; } } return nullptr; }
QStringList StaticPlaylistManager::EnumerateCustomPlaylists () const { QStringList result = PlaylistsDir_.entryList (QStringList ("*.m3u8")); for (auto i = result.begin (), end = result.end (); i != end; ++i) i->chop (5); result.sort (); return result; }
int main(int argc, char ** argv) { char str[100]; char pat[100]; printf("Enter string: "); fgets(str, sizeof(str), stdin); chop(str); while (1) { printf("Enter pattern: "); fgets(pat, sizeof(pat), stdin); chop(pat); printf(match_pattern(pat, str) ? "MATCHED!\n" : "no match\n"); } return 1; }