void processNeighbour(Node *node, Node *parent, int step_weight, Position destination) { // Check if node if valid or is in the closed list if (node && !inList(list_closed, node)) { // Check wether the node has been added to the open list if (!inList(list_open, node)) { // Add to open list addToList(&list_open, node); // Change parent node->parent = parent; // Set H score to Manhattan distance from destination node->H = abs(node->position.x - destination.x) + abs(node->position.y - destination.y); // Set path weight node->G = parent->G + step_weight; // Set step weight node->step_weight = step_weight; } else { // Check if node's score is better if (parent->G + step_weight < node->G) { // Update node details node->G = parent->G + step_weight; node->parent = parent; node->step_weight = step_weight; } } } }
void PropertyManager::createOrderedGrid(wxPropertyGridManager *pg, nau::AttribSet &attribs, std::vector<std::string> &list) { // First add the attributes in the list for (auto name : list) { std::unique_ptr<Attribute> &attr = attribs.get(name); addAttribute(pg, attr); } // Add editable attributes std::map<std::string, std::unique_ptr<Attribute>> & attributes = attribs.getAttributes(); for (auto & attrib : attributes) { if (!inList(attrib.second->getName(), list) && attrib.second->getReadOnlyFlag() == false) addAttribute(pg, attrib.second); } // Add the editable attributes for (auto& attrib : attributes) { if (!inList(attrib.second->getName(), list) && attrib.second->getReadOnlyFlag() == true) addAttribute(pg, attrib.second); } pg->CollapseAll(); pg->Refresh(); }
bool RemoveComment(const QString& path, const QString& text, int from, int to, bool& skip, bool& modify) { bool commentprinted(false); QString comment=text.mid(from, to-from); if(inList(alert_copyrights, comment)) { reportFile(path); log->write("**** COMMENT **********************************\n"); log->write("\n\n ALERT!!!! FORBIDDEN LICENSE DETECTED!!!! \n\n"); log->write(comment.toAscii()); commentprinted=true; } bool flag=inList(gray_copyrights, comment); if(!flag)return false; bool comment_must_be_removed(inList(reject_copyrights, comment)); bool comment_must_be_saved(inList(skip_copyrights, comment)); skip|=comment_must_be_saved; modify|=comment_must_be_removed; if(infomode && log){ if(!commentprinted && !onlyalerts) { reportFile(path); log->write("**** COMMENT **********************************\n"); log->write(comment.toAscii()); log->write("\n**** "); } if(comment_must_be_removed)log->write("[REJECT] "); if(comment_must_be_saved)log->write("[KEEP] "); log->write("\n**********************************************\n"); } if(comment_must_be_removed && !comment_must_be_saved)return true; return false; }
int checkIncreasing() { // Yeay, bubble sort! Fortunately this only gets called if there's a pretty close match. This is the last check. for (int i = 0; i < matchCount; i++) for (int j = 0; j < matchCount; j++) if (matches[j] > matches[i]) { unsigned int temp = matches[j]; matches[j] = matches[i]; matches[i] = temp; } // TODO: check for increasing terms // TODO: if match, migrate them to matches[0]..matches[2] for (int first = 1; first < matchCount; first++) { for (int second = first + 1; second < matchCount; second++) { unsigned int distance = matches[second] - matches[first]; //printf("Distance is %d\n", distance); for (int j = 0; j < matchCount; j++) if (inList(matches[j] + distance) && inList(matches[j] + 2 * distance)) { printf("FOUND!\n"); matches[0] = matches[j]; matches[1] = matches[0] + distance; matches[2] = matches[0] + 2 * distance; return 1; } } } return 0; }
void Job::add(QString itemInfo) { //make sure that the WorkItem info is unique within Job if(inList(&unassigned,itemInfo)||inList(&working,itemInfo)||inList(&finished,itemInfo)) return; //the info is unique, make workItem and add it to the list unassigned.append(new WorkItem(this,itemInfo)); }
/* Checks if the entry exists in the locSym, if so, returns the idx to this entry; otherwise creates a new register identifier node of type TYPE_LONG_(UN)SIGN and returns the index to this new entry. */ int newLongRegId(LOCAL_ID *locSym, hlType t, uint8_t regH, uint8_t regL, int ix) { int idx; // Check for entry in the table for (idx = 0; idx < locSym->csym; idx++) { if ((locSym->id[idx].id.longId.h == regH) && (locSym->id[idx].id.longId.l == regL)) { // Check for occurrence in the list if (inList(&locSym->id[idx].idx, ix)) return idx; else { // Insert icode index in list insertIdx(&locSym->id[idx].idx, ix); return (idx); } } } // Not in the table, create new identifier newIdent(locSym, t, REG_FRAME); insertIdx(&locSym->id[locSym->csym - 1].idx, ix); idx = locSym->csym - 1; locSym->id[idx].id.longId.h = regH; locSym->id[idx].id.longId.l = regL; return idx; }
int ConstantList::checkDup(const char* name, ConstantList& committed, ConstantList& other, ConstantList& otherPend, bool priv, const char* cname) { if (inList(name)) { parse_error("%s constant \"%s\" is already pending in class \"%s\"", privpub(priv), name, cname); return -1; } // see if constant already exists in committed list if (committed.inList(name)) { parse_error("%s constant \"%s\" has already been added to class \"%s\"", privpub(priv), name, cname); return -1; } // see if constant is in the other pending list if (otherPend.inList(name)) { parse_error("%s constant \"%s\" is already pending in class \"%s\" as a %s constant", privpub(priv), name, cname, privpub(!priv)); return -1; } // see if constant is in the other committed list if (other.inList(name)) { parse_error("%s constant \"%s\" has already been added to class \"%s\" as a %s constant", privpub(priv), name, cname, privpub(!priv)); return -1; } return 0; }
/*! * Tries to mount a list of directories, found in /basedir/subdir/<list>. * \param basedir Base directory * \param subdir A subdirectory of basedir * \param appendToPath Whether to append or prepend * \param checkList List of directories to check. NULL means any. */ void addSubdirs( const char * basedir, const char * subdir, const bool appendToPath, char * checkList[], bool addToModList ) { char tmpstr[PATH_MAX]; char buf[256]; char ** subdirlist = PHYSFS_enumerateFiles( subdir ); char ** i = subdirlist; while( *i != NULL ) { #ifdef DEBUG debug( LOG_NEVER, "addSubdirs: Examining subdir: [%s]", *i ); #endif // DEBUG if (*i[0] != '.' && (!checkList || inList(checkList, *i))) { snprintf(tmpstr, sizeof(tmpstr), "%s%s%s%s", basedir, subdir, PHYSFS_getDirSeparator(), *i); #ifdef DEBUG debug( LOG_NEVER, "addSubdirs: Adding [%s] to search path", tmpstr ); #endif // DEBUG if (addToModList) { addLoadedMod(*i); snprintf(buf, sizeof(buf), "mod: %s", *i); addDumpInfo(buf); } PHYSFS_addToSearchPath( tmpstr, appendToPath ); } i++; } PHYSFS_freeList( subdirlist ); }
int ipinstance::determineGroup(std::string &user, int &fg) { struct in_addr sin; inet_aton(user.c_str(), &sin); uint32_t addr = ntohl(sin.s_addr); // check straight IPs, subnets, and ranges fg = inList(addr); if (fg >= 0) { #ifdef DGDEBUG std::cout << "Matched IP " << user << " to straight IP list" << std::endl; #endif return DGAUTH_OK; } fg = inSubnet(addr); if (fg >= 0) { #ifdef DGDEBUG std::cout << "Matched IP " << user << " to subnet" << std::endl; #endif return DGAUTH_OK; } fg = inRange(addr); if (fg >= 0) { #ifdef DGDEBUG std::cout << "Matched IP " << user << " to range" << std::endl; #endif return DGAUTH_OK; } #ifdef DGDEBUG std::cout << "Matched IP " << user << " to nothing" << std::endl; #endif return DGAUTH_NOMATCH; }
void removeSubdirs( const char * basedir, const char * subdir, char * checkList[] ) { char tmpstr[PATH_MAX]; char ** subdirlist = PHYSFS_enumerateFiles( subdir ); char ** i = subdirlist; while( *i != NULL ) { #ifdef DEBUG debug( LOG_NEVER, "removeSubdirs: Examining subdir: [%s]", *i ); #endif // DEBUG if( !checkList || inList( checkList, *i ) ) { snprintf(tmpstr, sizeof(tmpstr), "%s%s%s%s", basedir, subdir, PHYSFS_getDirSeparator(), *i); #ifdef DEBUG debug( LOG_NEVER, "removeSubdirs: Removing [%s] from search path", tmpstr ); #endif // DEBUG if (!PHYSFS_removeFromSearchPath( tmpstr )) { #ifdef DEBUG // spams a ton! debug(LOG_NEVER, "Couldn't remove %s from search path because %s", tmpstr, PHYSFS_getLastError()); #endif // DEBUG } } i++; } PHYSFS_freeList( subdirlist ); }
void ArrayInfo::addIndex(const Node a, const TNode i) { Assert(a.getType().isArray()); Assert(!i.getType().isArray()); // temporary for flat arrays Trace("arrays-ind")<<"Arrays::addIndex "<<a<<"["<<i<<"]\n"; CTNodeList* temp_indices; Info* temp_info; CNodeInfoMap::iterator it = info_map.find(a); if(it == info_map.end()) { temp_indices = new(true) CTNodeList(ct); temp_indices->push_back(i); temp_info = new Info(ct, bck); temp_info->indices = temp_indices; info_map[a] = temp_info; } else { temp_indices = (*it).second->indices; if (! inList(temp_indices, i)) { temp_indices->push_back(i); } } if(Trace.isOn("arrays-ind")) { printList((*(info_map.find(a))).second->indices); } }
static void writeProp(OFile *fp, VObject *o) { int isQuoted=0; if (NAME_OF(o)) { const struct PreDefProp *pi; VObjectIterator t; const char **fields_ = 0; pi = lookupPropInfo(NAME_OF(o)); if (pi && ((pi->flags & PD_BEGIN) != 0)) { writeVObject_(fp,o); return; } if (isAPropertyOf(o,VCGroupingProp)) writeGroup(fp,o); else appendsOFile(fp,NAME_OF(o)); if (pi) fields_ = pi->fields; initPropIterator(&t,o); while (moreIteration(&t)) { const char *s; VObject *eachProp = nextVObject(&t); s = NAME_OF(eachProp); if (strcasecmp(VCGroupingProp,s) && !inList(fields_,s)) writeAttrValue(fp,eachProp); if (strcasecmp(VCQPProp,s)==0 || strcasecmp(VCQuotedPrintableProp,s)==0) isQuoted=1; } if (fields_) { int i = 0, n = 0; const char** fields = fields_; /* output prop as fields */ appendcOFile(fp,':'); while (*fields) { VObject *tl = isAPropertyOf(o,*fields); i++; if (tl) n = i; fields++; } fields = fields_; for (i=0;i<n;i++) { writeValue(fp,isAPropertyOf(o,*fields),0,isQuoted); fields++; if (i<(n-1)) appendcOFile(fp,';'); } } } if (VALUE_TYPE(o)) { unsigned long size = 0; VObject *p = isAPropertyOf(o,VCDataSizeProp); if (p) size = LONG_VALUE_OF(p); appendcOFile(fp,':'); writeValue(fp,o,size,isQuoted); } appendcOFile(fp,'\n'); }
/* returns 1 if n writeable as sum of any two elements in ns, 0 otherwise */ int summableFromList(unsigned int *ns, unsigned int n, unsigned int numElements) { unsigned int c; for (c=0 ; c<numElements ; c++) if (inList(ns,n-ns[c],numElements)) return 1; return 0; }
// no duplicate checking is done here void ConstantList::assimilate(ConstantList& n) { for (cnemap_t::iterator i = n.cnemap.begin(), e = n.cnemap.end(); i != e; ++i) { assert(!inList(i->first)); // "move" data to new list cnemap[i->first] = i->second; i->second = 0; } n.parseDeleteAll(); }
void ConstantList::mergeUserPublic(const ConstantList& src) { for (cnemap_t::const_iterator i = src.cnemap.begin(), e = src.cnemap.end(); i != e; ++i) { if (!i->second->isUserPublic()) continue; assert(!inList(i->first)); ConstantEntry* n = new ConstantEntry(*i->second); cnemap[n->getName()] = n; } }
/* * Inserts element into integer array arr and updates len, if it is not already in. */ int enqueueUnique( int element, int **arr, int *len ) { if( *arr != NULL && inList( element, *arr, *len ) ) return *len; (*len)++; REALLOC( *arr, int*, (*len) * sizeof(int), "arr" ); (*arr)[(*len)-1] = element; return *len; }
bool KisCountVisitor::check(KisNode * node) { if (m_nodeTypes.isEmpty() || inList(node)) { if (m_properties.isEmpty() || node->check(m_properties)) { m_count++; } } visitAll(node); return true; }
void inQueueList (struct qData *entry) { struct qData *qp; for (qp = qDataList->forw; qp != qDataList; qp = qp->forw) if (entry->priority <= qp->priority) break; inList ((struct listEntry *) qp, (struct listEntry *) entry); numofqueues++; }
int ConstantList::importSystemConstants(const ConstantList& src, ExceptionSink* xsink) { for (cnemap_t::const_iterator i = src.cnemap.begin(), e = src.cnemap.end(); i != e; ++i) { if (!i->second->isSystem()) continue; if (inList(i->first)) { xsink->raiseException("IMPORT-SYSTEM-API-ERROR", "cannot import system constant %s due to an existing constant with the same name in the target namespace", i->first); return -1; } ConstantEntry* n = new ConstantEntry(*i->second); cnemap[n->getName()] = n; } return 0; }
// duplicate checking is done here void ConstantList::assimilate(ConstantList& n, ConstantList& otherlist, const char* name) { // assimilate target list for (cnemap_t::iterator i = n.cnemap.begin(), e = n.cnemap.end(); i != e; ++i) { if (inList(i->first)) { parse_error("constant \"%s\" is already pending in namespace \"%s\"", i->first, name); continue; } if (otherlist.inList(i->first)) { parse_error("constant \"%s\" has already been defined in namespace \"%s\"", i->first, name); continue; } cnemap[i->first] = i->second; i->second = 0; } n.parseDeleteAll(); }
UChar* LocDataParser::nextString() { UChar* result = NULL; skipWhitespace(); if (p < e) { const UChar* terminators; UChar c = *p; UBool haveQuote = c == QUOTE || c == TICK; if (haveQuote) { inc(); terminators = c == QUOTE ? DQUOTE_STOPLIST : SQUOTE_STOPLIST; } else { terminators = NOQUOTE_STOPLIST; } UChar* start = p; while (p < e && !inList(*p, terminators)) ++p; if (p == e) { ERROR("Unexpected end of data"); } UChar x = *p; if (p > start) { ch = x; *p = 0x0; // terminate by writing to data result = start; // just point into data } if (haveQuote) { if (x != c) { ERROR("Missing matching quote"); } else if (p == start) { ERROR("Empty string"); } inc(); } else if (x == OPEN_ANGLE || x == TICK || x == QUOTE) { ERROR("Unexpected character in string"); } } // ok for there to be no next string return result; }
void main() { // You MUST print this out, otherwise the // server will not send the response: printf("Content-type: text/plain\n\n"); FILE* list = fopen(dataFile, "a+t"); if(list == 0) { printf("error: could not open database. "); printf("Notify %s", notify); return; } // For a CGI "GET," the server puts the data // in the environment variable QUERY_STRING: CGI_vector query(getenv("QUERY_STRING")); #if defined(DEBUG) // Test: dump all names and values for(int i = 0; i < query.size(); i++) { printf("query[%d].name() = [%s], ", i, query[i].name()); printf("query[%d].value() = [%s]\n", i, query[i].value()); } #endif(DEBUG) Pair name = query[0]; Pair email = query[1]; if(name.empty() || email.empty()) { printf("error: null name or email"); return; } if(inList(list, email.value())) { printf("Already in list: %s", email.value()); return; } // It's not in the list, add it: fseek(list, 0, SEEK_END); fprintf(list, "%s <%s>;\n", name.value(), email.value()); fflush(list); fclose(list); printf("%s <%s> added to list\n", name.value(), email.value()); } ///:~
//=========================================================// pnode* getASTHelper(pnode* root){ if(root == NULL) return root; int i,child; pnode* ret = NULL; if(root->numChild != 0){ child = root->numChild; for(i=0;i<child;i++){ if(root->child[i]!=NULL) root->child[i]=getASTHelper(root->child[i]); } } if(root->val==0 || inList(root->val)){ (root-> par-> numChild)--; free(root); return NULL; } if(root->numChild==0 && root->isTerminal!=1){ (root-> par-> numChild)--; free(root); return NULL; } if(root->numChild==1){ for(i=0;i<200;i++){ if(root->child[i]!=NULL){ ret=root->child[i]; root->child[i]->par=root->par; root->par = NULL; free(root); return ret; } } } return root; }
void ArrayInfo::addStore(const Node a, const TNode st){ Assert(a.getType().isArray()); Assert(st.getKind()== kind::STORE); // temporary for flat arrays CTNodeList* temp_store; Info* temp_info; CNodeInfoMap::iterator it = info_map.find(a); if(it == info_map.end()) { temp_store = new(true) CTNodeList(ct); temp_store->push_back(st); temp_info = new Info(ct, bck); temp_info->stores = temp_store; info_map[a]=temp_info; } else { temp_store = (*it).second->stores; if(! inList(temp_store, st)) { temp_store->push_back(st); } } };
int heuristicPathFinder(int source, int target) { initialiseSearch(); int distance = 0; int *outlist = getLinkedEdges(source); setVisit(source); printNode(source); while(inList(outlist, target) == FALSE && outlist[0] != 0) { distance++; int maxOut = largestOutDegreeSearch(outlist); setVisit(maxOut); printNode(maxOut); outlist = getLinkedEdges(maxOut); }//while distance++; printNode(target); return distance; }//heuristicPathFinder
void ArrayInfo::addInStore(const TNode a, const TNode b){ Trace("arrays-addinstore")<<"Arrays::addInStore "<<a<<" ~ "<<b<<"\n"; Assert(a.getType().isArray()); Assert(b.getType().isArray()); CTNodeList* temp_inst; Info* temp_info; CNodeInfoMap::iterator it = info_map.find(a); if(it == info_map.end()) { temp_inst = new(true) CTNodeList(ct); temp_inst->push_back(b); temp_info = new Info(ct, bck); temp_info->in_stores = temp_inst; info_map[a] = temp_info; } else { temp_inst = (*it).second->in_stores; if(! inList(temp_inst, b)) { temp_inst->push_back(b); } } };
// return true if both functions with indeces of pair are in the intermediate basis and their S polynomial should be computed bool isGoodPair(const Pair &pair, const IntermediateBasis &F, const Pairs &B, int n) { FunctionPair fp = FunctionPair(pair, F, n); if (!fp.good) { return false; } // both polynomials are monomials, so their S polynomial reduces to 0 if ( fp.g->size() == 1 && fp.f->size() == 1 ) { //cout << "m "; return false; } brMonomial g = fp.g->LT(); brMonomial f = fp.f->LT(); if( BRP::isRelativelyPrime(g,f) ) { return false; } int i = pair.i; int j = pair.j; brMonomial lcm = pair.lcm; IntermediateBasis::const_iterator end = F.end(); for(IntermediateBasis::const_iterator it = F.begin(); it != end; ++it) { int k = it->first; const BRP *K = &(it->second); if(( k != i && k != j && BRP::isDivisibleBy(lcm, K->LT() ) && !inList(i,k,B,F) && !inList(j,k,B,F))) { return false; } } //cout << "good pair "; return true; }
void deleteUser(LinkList L, ClientInf user) { if (inList(L, user)) { LinkList s, p; s = L; p = L->next; while (p->next != NULL) { if (!strcmp(user.name, p->data.name)) { printf("user %s delete OR disconnect\n", user.name); s->next = p->next; return; } p = p->next; s = s->next; } if (!strcmp(user.name, p->data.name)) { s->next = NULL; printf("user %s delete OR disconnect\n", user.name); } } }
static void writeProp(OFile *fp, VObject *o) { if (NAME_OF(o)) { struct PreDefProp *pi; VObjectIterator t; const char **fields_ = 0; pi = lookupPropInfo(NAME_OF(o)); if (pi && ((pi->flags & PD_BEGIN) != 0)) { writeVObject_(fp,o); return; } if (isAPropertyOf(o,VCGroupingProp)) writeGroup(fp,o); else appendsOFile(fp,NAME_OF(o)); if (pi) fields_ = pi->fields; initPropIterator(&t,o); while (moreIteration(&t)) { const char *s; VObject *eachProp = nextVObject(&t); s = NAME_OF(eachProp); if (qstricmp(VCGroupingProp,s) && !inList(fields_,s)) writeAttrValue(fp,eachProp); } if (fields_) { int i = 0, n = 0; const char** fields = fields_; /* output prop as fields */ bool printable = TRUE; while (*fields && printable) { VObject *t = isAPropertyOf(o,*fields); if (includesUnprintable(t,TRUE)) printable = FALSE; fields++; } fields = fields_; if (!printable) appendsOFileEncCs(fp); appendcOFile(fp,':'); while (*fields) { VObject *t = isAPropertyOf(o,*fields); i++; if (t) n = i; fields++; } fields = fields_; for (i=0;i<n;i++) { writeValue(fp,isAPropertyOf(o,*fields),0,TRUE); fields++; if (i<(n-1)) appendcOFile(fp,';'); } } } if (VALUE_TYPE(o)) { if ( includesUnprintable(o,FALSE) ) appendsOFileEncCs(fp); unsigned long size = 0; VObject *p = isAPropertyOf(o,VCDataSizeProp); if (p) size = LONG_VALUE_OF(p); appendcOFile(fp,':'); writeValue(fp,o,size,FALSE); } appendcOFile(fp,'\n'); }
Path_element* findShortestPath(int start_x, int start_y, int facing_direction, int destination_x, int destination_y) { // Check wether the destination and start arent the same if (start_x == destination_x && start_y == destination_y) return NULL; // Initiate the node element, the start and destination and the path Node *node = malloc(sizeof (Node)), *start = malloc(sizeof (Node)), *destination = malloc(sizeof (Node)); Path_element *path = NULL; // Find initial 'parent location' int parent_location = reverseDirection(facing_direction); // Clears the grid cache to prevent incorrect results clearGridCache(); // Link start and destination to the grid consequently start = grid[start_x][start_y]; destination = grid[destination_x][destination_y]; // Add start to open list addToList(&list_open, start); do { // Find the node with the best score in the open list node = findLowestFInList(list_open); // Remove the node from the open list removeFromList(&list_open, node); // Add the node to the closed list addToList(&list_closed, node); // Find the parent location if (node->parent) parent_location = getParentLocation(node); // Process the neighbours processNeighbour(node->south, node, determineStepWeight(SOUTH, parent_location), destination->position); processNeighbour(node->north, node, determineStepWeight(NORTH, parent_location), destination->position); processNeighbour(node->east, node, determineStepWeight(EAST, parent_location), destination->position); processNeighbour(node->west, node, determineStepWeight(WEST, parent_location), destination->position); // Do this while the destination is not in the closed list, in which case the path has been found, or the open list is empty } while (!inList(list_closed, destination) && list_open != NULL); // Check if best path is found, in which case the destination is in the closed list if (inList(list_closed, destination)) { // Add destination to path node = destination; addToBeginOfPath(&path, node->position.x, node->position.y, reverseDirection(getParentLocation(node)), node->step_weight, node->id); do { // Get the parent of the node, doing this enough times will eventually get you to the start node = node->parent; // Add node to path addToBeginOfPath( &path, node->position.x, node->position.y, !getParentLocation(node) ? facing_direction : reverseDirection(getParentLocation(node)), node->step_weight, node->id ); } while (node != start); } // Clear the lists clearList(&list_closed); clearList(&list_open); // Return the path return path; }