int main(void) { Menu menu; List list; InitList(&list); do { Data x; switch (menu = SelectMenu()) { case InsFront: x = Read("先頭に挿入", NO | NAME); InsertFront(&list, x); break; case InsRear: x = Read("末尾に挿入", NO | NAME); InsertRear(&list, x); break; case RmvFront: RemoveFront(&list); break; case RmvRear: RemoveRear(&list); break; case PrintCrnt: PrintCrntNode(&list); break; case RmvCrnt: RemoveCrnt(&list); break; case SrchNo: x = Read("探索", NO); if (SearchNode(&list, x, NoEqual) != NULL){ PrintCrntNode(&list); } break; case SrchName: x = Read("探索", NAME); if(SearchNode(&list, x, NameEqual) != NULL){ PrintCrntNode(&list); } break; case PrintAll: PrintList(&list); break; case Clear: ClearList(&list); break; } } while (menu != Term); TermList(&list); return (0); }
void SearchNode(BinNode *p, const BinNode *w){ int cond; if (p== NULL){ printf("【エラー】%sは登録されていません。\n", w->name); }else if(( cond = strcmp(w->name,p->name)) == 0){ printf("【エラー】%sは登録されています。\n", w->name); } else if ( cond < 0){ SearchNode(p->left,w); } else { SearchNode(p->right,w); } }
BinaryTree *SearchNode(BinaryTree *root, BinaryTree **parent, int key){ if(root == NULL) return NULL; if(root->value == key){ return root; } else if(root->value > key){ *parent = root; return SearchNode(root->lNode,parent,key); } else if(root->value < key){ *parent = root; return SearchNode(root->rNode,parent,key); } return NULL; }
const CSuffixTrie::Node* CSuffixTrie::SearchNode(const SearchString& rString, const Node* pNode)const { //Sanity check if (!pNode || rString.empty()) return NULL; //The char we are looking for SearchChar aChar; aChar=rString[0]; //Look for the next node SearchMap::const_iterator aIterator; aIterator=pNode->aMap.find(aChar); //Do we have it? if (aIterator!=pNode->aMap.end()) { //Is it the last char? if (rString.length()==1) //We found our string return aIterator->second; else //Search again return SearchNode(rString.substr(1,rString.length()-1), aIterator->second); } else //Not found return NULL; }
void Graph<T1>::SearchNode(Node<T1> *ptr) { vector<string> V; V = ptr->getNeighbours(); int sz = V.size(); int rootIdx = M[ptr->getName()]-1; for(int i = 0;i < sz;i++) { string str = V[i]; int childIdx = M[str]-1; if(Active[childIdx]) { if(!Mark[rootIdx][childIdx]) { End = 0; Mark[rootIdx][childIdx] = 1; cout<<NodeList[rootIdx]->getName()<<"("<<NodeList[rootIdx]->getData()<<")"<<".."; SearchNode(NodeList[childIdx]); } } } if(End == 0) { cout<<NodeList[rootIdx]->getName()<<"("<<NodeList[rootIdx]->getData()<<")"<<endl; End = 1; } }
void Graph<T1>::Print() { int sz; sz = NodeList.size(); if(Mark != 0) { for(int i = 0;i < prevsz;i++) { delete[] Mark[i]; } Mark = 0; } Mark = new int*[sz]; for(int i = 0;i < sz;i++) Mark[i] = new int[sz](); prevsz = sz; for(int i = 0;i < sz;i++) { if(Active[i]) { End = -1; SearchNode(NodeList[i]); } } }
int RecDelete(KeyType k,BTNode *p) /*查找并删除关键字k*/ { int i; int found; if (p==NULL) return 0; else { if ((found=SearchNode(k,p,i))==1) /*查找关键字k*/ { if (p->ptr[i-1]!=NULL) /*若为非叶子结点*/ { Successor(p,i); /*由其后继代替它*/ RecDelete(p->key[i],p->ptr[i]); /*p->key[i]在叶子结点中*/ } else Remove(p,i); /*从*p结点中位置i处删除关键字*/ } else found=RecDelete(k,p->ptr[i]); /*沿孩子结点递归查找并删除关键字k*/ if (p->ptr[i]!=NULL) if (p->ptr[i]->keynum<Min) /*删除后关键字个数小于MIN*/ Restore(p,i); return found; } }
Tree SearchNode(Tree root, KEY_TYPE value) { if (root == NULL) { printf("Not found, key: %d\n", value); return NULL; } if (root->key == value) { printf("Found the node, key: %d\n", root->key); return root; } else if (value > root->key) { return SearchNode(root->rchild, value); } else { return SearchNode(root->lchild, value); } }
int RecDelete(KeyType k,BTNode *p) //查找并删除关键字k { int i; int found; if (p==NULL) return 0; else { if ((found=SearchNode(k,p,i))==1) //查找关键字k { if (p->ptr[i-1]!=NULL) //若为非叶子结点 { Successor(p,i); //由其后继代替它 RecDelete(p->key[i],p->ptr[i]); //p->key[i]在叶子结点中 } else Remove(p,i); //从*p结点中位置i处删除关键字 } else found=RecDelete(k,p->ptr[i]); //沿孩子结点递归查找并删除关键字k if (p->ptr[i]!=NULL) if (p->ptr[i]->keynum<Min) //删除后关键字个数小于MIN Restore(p,i); return found; } }
void Search::SetSearchInput(const wchar_t* input) { _criteria.clear(); wchar_t _input [MAX_PATH]; wcscpy_s(_input,MAX_PATH,input); if (_letterCombination) ConvertMacros(_input); unsigned int i=0; unsigned int i2=0; int id=0; wchar_t tempString[MAX_PATH]=L""; while(_input[i]) { if (_input[i]=='|') { if (_criteria.size()<1 ||_criteria[_criteria.size()-1]._oprt!=OPRT_RIGHT/* && tempString)*/) { _criteria.push_back(SearchNode(tempString,OPERAND)); i2=0; ZeroMemory(tempString,sizeof(tempString)); } _criteria.push_back(SearchNode(L"",OPRT_OR)); } else if (_input[i]=='&') { if (_criteria.size()<1 || _criteria[_criteria.size()-1]._oprt!=OPRT_RIGHT/* && CheckCritInput(tempString)*/) { _criteria.push_back(SearchNode(tempString,OPERAND)); i2=0; ZeroMemory(tempString,sizeof(tempString)); } _criteria.push_back(SearchNode(L"",OPRT_AND)); } else if (_input[i]=='<') { _criteria.push_back(SearchNode(ItoW(id).c_str(),OPRT_LEFT));id++; } else if (_input[i]=='>') { if (_criteria.size()<1 ||_criteria[_criteria.size()-1]._oprt!=OPRT_RIGHT/* && CheckCritInput(tempString)*/) { _criteria.push_back(SearchNode(tempString,OPERAND)); i2=0; ZeroMemory(tempString,sizeof(tempString)); } id--;_criteria.push_back(SearchNode(ItoW(id).c_str(),OPRT_RIGHT)); }else { tempString[i2]=_input[i]; i2++; } i++; } if (_criteria.size()<1 ||_criteria[_criteria.size()-1]._oprt!=OPRT_RIGHT/* && CheckCritInput(tempString)*/) { _criteria.push_back(SearchNode(tempString,OPERAND)); } int end=0; while(OptimizeCriteria(0,&end)); }
bool Dictionary::DisableNode(std::string& key_word) { LzwNode<char>* tempNode = SearchNode(key_word); if (tempNode != NULL) { tempNode->abilable = false; this->size--; } else { return false; } return true; }
void CSuffixTrie::DeleteString(const SearchString& rString) { //Our prev node Node* pPrevNode; pPrevNode=NULL; //Start to find the nodes for (int iCount=0; iCount<rString.length(); ++iCount) { //Find the node Node* pNode; pNode=SearchNode(rString.substr(iCount,rString.length()-iCount), &m_aRoot); //Do we have a previous node? if (pPrevNode && pNode) { //We need to delete it pNode->aMap.erase(pPrevNode->aChar); //And delete the node delete pPrevNode; pPrevNode=NULL; } //Did we get it? if (pNode) //What stage are we? if (!iCount) //Does it have children? if (pNode->aMap.empty()) //We can delete it pPrevNode=pNode; else { //Can't be final pNode->bFinal=false; //Exit return; } //Do we have children else if (pNode->aMap.empty()) //We can delete it pPrevNode=pNode; else //Exit return; } }
/** * 习题6.50,以三元组(F, C, L/R)的形式创建一棵二叉树,如^AL ABL ^^L创建以A为根的树 */ Status MyCreateTree(BiTree &T) { char c; BiTree p, q; BiTree R[20]; //保存已经创建了的结点 int len = 0; //结点数组的指针 c = getchar(); while (' ' == c || '\t' == c || '\n' == c) //过滤空字符 c = getchar(); if ('^' == c) { //创建根 c = getchar(); if ('^' != c) { T = (BiTree)malloc(sizeof(BiTNode)); if (!T) return ERROR; //分配失败 R[len++] = T; //将结点存入结点数组 T->data = c; T->lchild = NULL; T->rchild = NULL; c = getchar(); } else { T = NULL; return OK; //创建空树 } } else //输入错误 return ERROR; while (1) { //创建子树 c = getchar(); while (' ' == c || '\t' == c || '\n' == c) //过滤空字符 c = getchar(); if ('^' == c) //输入结束 return OK; if (ERROR == SearchNode(R, len, c, p)) //搜索结点数组得到指定的父结点 return ERROR; c = getchar(); //得到三元组第二个字符 q = (BiTree)malloc(sizeof(BiTNode)); //为子结点分配空间 if (!q) return ERROR; //分配失败 R[len++] = q; //将结点加入结点数组中 q->data = c; q->lchild = NULL; q->rchild = NULL; c = getchar(); //得到三元组第三个字符 if ('L' == c || 'l' == c) p->lchild = q; else if ('R' == c || 'r' == c) p->rchild = q; else //输入错误 return ERROR; } }
std::vector<Entity *> Virus::getNearbyEntities(int distance) { std::vector<Entity *> entities; std::map<std::pair<int, int>, bool> visited; std::queue<SearchNode> search; Tile *source = map->getTile(position); search.push(SearchNode(source->hx, source->hy, 0)); visited[std::make_pair(source->hx, source->hy)] = true; while (!search.empty()) { SearchNode cur = search.front(); search.pop(); Tile *tile = map->getTile(cur.x, cur.y); if (tile->hasEntities()) { std::list<Entity *> toAdd = tile->getEntities(); entities.insert(entities.begin(), toAdd.begin(), toAdd.end()); } if (cur.distance + 1 <= distance) { for (int i = 0; i < 6; i++) { int nx = cur.x + dirX[i]; int ny = cur.y + dirY[i]; if (!visited[std::make_pair(nx, ny)] && map->getTile(nx, ny)->getType() == TILE_EMPTY) { search.push(SearchNode(nx, ny, cur.distance + 1)); visited[std::make_pair(nx, ny)] = true; } } } } entities.erase(find(entities.begin(), entities.end(), this)); return entities; }
int SearchRouteNode(uint32_t dwKey) { BSNode *bsTmp = SearchNode(bsTree, 90); if(bsTmp) { printf("bsTmp->dwMinKey = %d\n", bsTmp->bsData.dwMinKey); printf("bsTmp->dwMaxKey = %d\n", bsTmp->bsData.dwMaxKey); struct sockaddr_in *tmp = (struct sockaddr_in *)bsTmp->bsData.data; printf("sockaddr fmainly = %d\n", tmp->sin_family); printf("sockaddr port = %d\n", tmp->sin_port); printf("sockaddr address = %s\n", inet_ntoa(tmp->sin_addr)); } return 0; }
void CSuffixTrie::BuildIndex(const SearchString& rString, Node* pNode) { //Sanity if (!pNode) return; //Do we need to process this node? if (pNode->usDepth>1) { //Clear the node first pNode->pFailureNode=NULL; //We need to start and look for suffix/prefix for (int iCount=1; iCount<rString.length(); ++iCount) { //Build the sub string SearchString sString; sString=rString.substr(iCount,rString.length()-iCount); //And search Node* pFoundNode; pFoundNode=SearchNode(sString, &m_aRoot); //Did we get it? if (pFoundNode) { //Save it pNode->pFailureNode=pFoundNode; //Exit from this loop break; } } } //Build the next string SearchString sString(rString); //Iterate all its children for (SearchMap::iterator aIterator=pNode->aMap.begin(); aIterator!=pNode->aMap.end(); ++aIterator) //Build the index BuildIndex(rString+aIterator->first, aIterator->second); }
void DeleteNode(int element) { node *nodeToBeDeleted; nodeToBeDeleted = SearchNode(element); if (nodeToBeDeleted != null) { // Element Found node *nodeParent, *nodeRightChild; nodeParent = nodeToBeDeleted->parent; nodeRightChild = nodeParent->right; } else { // Element not found printf("\nElement Not Found"); return; } }
void DeleteTree(BinaryTree *root, int key){ BinaryTree *parent = NULL; BinaryTree *deletenode = SearchNode(root,&parent,key); if(deletenode == NULL){ printf("\nIt's not here!\n"); return ; } if((deletenode->lNode == NULL) && (deletenode->rNode == NULL)){ if(parent == NULL){ root = NULL; } else if(parent->lNode == deletenode) { parent->lNode = NULL; } else if(parent->rNode == deletenode) { parent->rNode = NULL; } free(deletenode); }else if((deletenode->rNode == NULL) && (deletenode->lNode != NULL)){ BinaryTree *tmp = deletenode->lNode; deletenode->value = tmp->value; deletenode->rNode = tmp->rNode; deletenode->lNode = tmp->lNode; free(tmp); }else if(deletenode->lNode == NULL && deletenode->rNode != NULL){ BinaryTree *tmp = deletenode->rNode; deletenode->value = tmp->value; deletenode->rNode = tmp->rNode; deletenode->lNode = tmp->lNode; free(tmp); }else{ BinaryTree *tmp = deletenode; BinaryTree *child = deletenode->lNode; while(child->rNode){ tmp = child; child = child->rNode; } deletenode->value = child->value; if(tmp!=deletenode) tmp->rNode=child->lNode; else tmp->lNode=child->lNode; free(child); } }
/*將資料插入串列中*/ int InsertAfter(ListNode table[], char OldData[], char NewData[]) { /*在資料為OldData的節點之後,加入新節點,資料為NewData[]*/ int EmptyNode, i; EmptyNode = GetFreeNode(table); /*找空節點*/ if (EmptyNode == 0) { /*已經沒有空節點*/ return FALSE; /*告訴呼叫者此動作失敗*/ } strcpy(table[EmptyNode].data, NewData); /*複製資料到新節點*/ i = SearchNode(table, OldData); /*找出舊節點的位置*/ if (i == FALSE) { return FALSE; } table[EmptyNode].next = table[i].next; /*舊節點的次一元素變成新節點的次一元素*/ table[i].next = EmptyNode; /*改變舊節點的次一元素位置*/ return TRUE; /*成功*/ }
int PrepARC(char *Queue, fidoaddr Dest) { char *pktfile; FILE *fp; Syslog('p', "Prepare ARCmail for %s", aka2str(Dest)); if (!SearchNode(Dest)) { WriteError("Downlink %s not found", aka2str(Dest)); return FALSE; } pktfile = calloc(PATH_MAX, sizeof(char)); snprintf(pktfile, PATH_MAX, "%s/%d.%d.%d.%d/%08x.pkt", CFG.out_queue, Dest.zone, Dest.net, Dest.node, Dest.point, sequencer()); Syslog('p', "Rename .pkt to %s", pktfile); if (rename(Queue, pktfile)) { WriteError("$Can't rename %s to %s", Queue, pktfile); free(pktfile); return FALSE; } /* * Add zero word to end of .pkt file */ if ((fp = fopen(pktfile, "a+")) == NULL) { WriteError("$Can't open %s", pktfile); free(pktfile); return FALSE; } putc('\0', fp); putc('\0', fp); fsync(fileno(fp)); fclose(fp); free(pktfile); return TRUE; }
int main(){ Menu menu; BinNode *root; root = NULL; do { BinNode x; switch ( menu = SelectMenu()){ case Insert : x = Read("挿入"); root = InsertNode(root,&x); break; case Search : x = Read("探索"); SearchNode(root,&x); break; case Print : puts("--- 一覧表 ---"); PrintTree(root); break; } } while ( menu != Term); FreeTree(root); return 0; }
bool CSuffixTrie::FindString(const SearchString& rString)const { return SearchNode(rString, &m_aRoot)!=NULL; }
void ForwardFile(fidoaddr Node, fa_list *sbl) { char *subject = NULL, *fwdfile = NULL, *queuedir, *listfile, *ticfile = NULL, *ticname, flavor; FILE *fp, *fi, *fl, *net; faddr *dest, *routeto, *Fa, *Temp, *ba; int i, z, n; time_t now, ftime; fa_list *tmp; if (!SearchNode(Node)) { WriteError("TIC forward in %s, node %s not in setup but defined in area setup", TIC.TicIn.Area, aka2str(Node)); return; } Syslog('+', "Forward file to %s %s netmail", aka2str(Node), nodes.Message?"with":"without"); fwdfile = calloc(PATH_MAX, sizeof(char)); queuedir = calloc(PATH_MAX, sizeof(char)); listfile = calloc(PATH_MAX, sizeof(char)); snprintf(queuedir, PATH_MAX, "%s/%d.%d.%d.%d", CFG.out_queue, Node.zone, Node.net, Node.node, Node.point); snprintf(listfile, PATH_MAX, "%s/.filelist", queuedir); mkdirs(listfile, 0750); if ((fl = fopen(listfile, "a+")) == NULL) { WriteError("$Can't open %s", listfile); free(fwdfile); free(listfile); free(queuedir); return; } /* * Create the full filename */ if (TIC.PassThru || TIC.SendOrg) { snprintf(fwdfile, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); subject = xstrcpy(TIC.TicIn.File); } else { /* * Make sure the file attach is the 8.3 filename */ snprintf(fwdfile, PATH_MAX, "%s/%s", TIC.BBSpath, TIC.NewFile); subject = xstrcpy(TIC.NewFile); } flavor = 'f'; if (nodes.Crash) flavor = 'c'; if (nodes.Hold) flavor = 'h'; fprintf(fl, "%c LEAVE FDN %s\n", flavor, fwdfile); if (nodes.RouteVia.zone) routeto = fido2faddr(nodes.RouteVia); else routeto = fido2faddr(Node); dest = fido2faddr(Node); ticfile = calloc(PATH_MAX, sizeof(char)); ticname = calloc(15, sizeof(char)); if (nodes.Tic) { snprintf(ticname, 15, "%08x.tic", sequencer()); subject = xstrcat(subject, (char *)" "); subject = xstrcat(subject, ticname); snprintf(ticfile, PATH_MAX, "%s/%s", CFG.ticout, ticname); } free(ticname); /* * Send netmail message if the node has it turned on. */ if (nodes.Message) { Temp = fido2faddr(Node); if ((net = SendMgrMail(Temp, CFG.ct_KeepMgr, TRUE, (char *)"Filemgr", subject, NULL)) != NULL) { if ((fi = OpenMacro("forward.tic", nodes.Language, FALSE)) != NULL) { ftime = TIC.FileDate; MacroVars("a", "s", TIC.TicIn.Area); MacroVars("b", "s", tic.Comment); MacroVars("c", "d", TIC.FileCost); MacroVars("d", "s", fgroup.Comment); if (TIC.PassThru || TIC.SendOrg) MacroVars("f", "s", TIC.TicIn.FullName); else MacroVars("f", "s", TIC.NewFullName); MacroVars("g", "d", TIC.FileSize); MacroVars("h", "d", (TIC.FileSize / 1024)); MacroVars("i", "s", TIC.TicIn.Crc); MacroVars("j", "s", TIC.TicIn.Origin); MacroVars("m", "s", rfcdate(ftime)); MacroVars("n", "s", TIC.TicIn.Desc); MacroVars("s", "s", nodes.Sysop); if (TIC.PassThru || TIC.SendOrg) MacroVars("e", "s", TIC.TicIn.File); else MacroVars("e", "s", TIC.NewFile); if (strlen(TIC.TicIn.Magic)) MacroVars("k", "s", TIC.TicIn.Magic); if (strlen(TIC.TicIn.Replace)) MacroVars("l", "s", TIC.TicIn.Replace); MacroRead(fi, net); fprintf(net, "%s\r", TearLine()); CloseMail(net, Temp); } } else { WriteError("Can't create netmail"); } tidy_faddr(Temp); } free(subject); /* * If we need a .TIC file, start creating it. */ if (nodes.Tic) { mkdirs(ticfile, 0770); if ((fp = fopen(ticfile, "a+")) != NULL) { fprintf(fp, "Area %s\r\n", TIC.TicIn.Area); fprintf(fp, "Origin %s\r\n", TIC.TicIn.Origin); Fa = fido2faddr(tic.Aka); fprintf(fp, "From %s\r\n", ascfnode(Fa, 0x0f)); free(Fa); if (strlen(TIC.TicIn.Replace)) fprintf(fp, "Replaces %s\r\n", TIC.TicIn.Replace); if (strlen(TIC.TicIn.Magic)) fprintf(fp, "Magic %s\r\n", TIC.TicIn.Magic); if ((TIC.PassThru) || (TIC.SendOrg)) { fprintf(fp, "File %s\r\n", TIC.TicIn.File); if (strlen(TIC.TicIn.FullName)) fprintf(fp, "Lfile %s\r\n", TIC.TicIn.FullName); } else { fprintf(fp, "File %s\r\n", TIC.NewFile); if (strlen(TIC.NewFullName)) fprintf(fp, "Lfile %s\r\n", TIC.NewFullName); } fprintf(fp, "Size %d\r\n", (int)(TIC.FileSize)); fprintf(fp, "Desc %s\r\n", TIC.TicIn.Desc); fprintf(fp, "Crc %s\r\n", TIC.TicIn.Crc); if (nodes.TIC_To) { fprintf(fp, "To %s, %s\r\n", nodes.Sysop, ascfnode(dest, 0x1f)); } if (nodes.AdvTic) { fprintf(fp, "Areadesc %s\r\n", tic.Comment); fprintf(fp, "Fdn %s\r\n", fgroup.Comment); if (TIC.TicIn.TotLDesc) for (i = 0; i < TIC.TicIn.TotLDesc; i++) fprintf(fp, "LDesc %s\r\n", TIC.TicIn.LDesc[i]); } fprintf(fp, "Created by MBSE BBS %s %s\r\n", VERSION, SHORTRIGHT); if (TIC.TicIn.TotPath) for (i = 0; i < TIC.TicIn.TotPath; i++) fprintf(fp, "Path %s\r\n", TIC.TicIn.Path[i]); /* * Add our system to the path */ now = time(NULL); subject = ctime(&now); Striplf(subject); ba = bestaka_s(dest); fprintf(fp, "Path %s %u %s %s\r\n", ascfnode(ba, 0x1f), (int)mktime(localtime(&now)), subject, tzname[0]); tidy_faddr(ba); if (nodes.TIC_AdvSB) { /* * In advanced TIC mode we send multiple seenby * addresses on one line in stead of one line * per system. */ z = 0; n = 0; subject = xstrcpy((char *)"Seenby"); for (tmp = sbl; tmp; tmp = tmp->next) { if (strlen(subject) > 70) { fprintf(fp, "%s\r\n", subject); z = 0; n = 0; free(subject); subject = xstrcpy((char *)"Seenby "); } else { subject = xstrcat(subject, (char *)" "); } if (z != tmp->addr->zone) { if (nodes.Tic4d) subject = xstrcat(subject, ascfnode(tmp->addr, 0x0f)); else subject = xstrcat(subject, ascfnode(tmp->addr, 0x0e)); z = tmp->addr->zone; } else { if (n != tmp->addr->net) { if (nodes.Tic4d) subject = xstrcat(subject, ascfnode(tmp->addr, 0x07)); else subject = xstrcat(subject, ascfnode(tmp->addr, 0x06)); n = tmp->addr->net; } else { if (nodes.Tic4d) subject = xstrcat(subject, ascfnode(tmp->addr, 0x03)); else subject = xstrcat(subject, ascfnode(tmp->addr, 0x02)); } } } if (strlen(subject) > 7) { fprintf(fp, "%s\r\n", subject); free(subject); } } else { /* * Old style seenby lines */ for (tmp = sbl; tmp; tmp = tmp->next) { fprintf(fp, "Seenby %s\r\n", ascfnode(tmp->addr, 0x0f)); } } /* * Now append all passthru ticlines */ if (TIC.TicIn.Unknowns) for (i = 0; i < TIC.TicIn.Unknowns; i++) fprintf(fp, "%s\r\n", TIC.TicIn.Unknown[i]); fprintf(fp, "Pw %s\r\n", nodes.Fpasswd); fclose(fp); fprintf(fl, "%c KFS NOR %s\n", flavor, ticfile); } else { WriteError("$Can't create %s", ticfile); } } fsync(fileno(fl)); fclose(fl); /* * Update the nodes statistic counters */ StatAdd(&nodes.FilesSent, 1L); StatAdd(&nodes.F_KbSent, T_File.SizeKb); UpdateNode(); SearchNode(Node); free(ticfile); free(fwdfile); free(queuedir); free(listfile); tidy_faddr(routeto); }
/* * Check TIC group AREAS file if requested area exists. * If so, create tic area and if SendUplink is TRUE, * send the uplink a FileMgr request to connect this area. * The tic group record (fgroup) must be in memory. * Return codes: * 0 - All Seems Well * 1 - Some error * * The current nodes record may be destroyed after this, * make sure it is saved. */ int CheckTicGroup(char *Area, int SendUplink, faddr *f) { char *temp, *buf, *tag = NULL, *desc = NULL, *p, *raid = NULL, *flow = NULL; FILE *ap, *mp, *fp; int offset, AreaNr; int i, rc = 0, Found = FALSE; sysconnect System; faddr *From, *To; struct _fdbarea *fdb_area = NULL; temp = calloc(PATH_MAX, sizeof(char)); Syslog('f', "Checking file group \"%s\" \"%s\"", fgroup.Name, fgroup.Comment); snprintf(temp, PATH_MAX, "%s/%s", CFG.alists_path , fgroup.AreaFile); if ((ap = fopen(temp, "r")) == NULL) { WriteError("Filegroup %s: area taglist %s not found", fgroup.Name, temp); free(temp); return 1; } buf = calloc(4097, sizeof(char)); if (fgroup.FileGate) { /* * filegate.zxx format */ while (fgets(buf, 4096, ap)) { /* * Each filegroup starts with "% FDN: Filegroup Description" */ if (strlen(buf) && !strncmp(buf, "% FDN:", 6)) { tag = strtok(buf, "\t \r\n\0"); p = strtok(NULL, "\t \r\n\0"); p = strtok(NULL, "\r\n\0"); desc = p; while ((*desc == ' ') || (*desc == '\t')) desc++; if (!strcmp(desc, fgroup.Comment)) { while (fgets(buf, 4096, ap)) { if (!strncasecmp(buf, "Area ", 5)) { tag = strtok(buf, "\t \r\n\0"); tag = strtok(NULL, "\t \r\n\0"); if (!strcasecmp(tag, Area)) { raid = strtok(NULL, "\t \r\n\0"); flow = strtok(NULL, "\t \r\n\0"); p = strtok(NULL, "\r\n\0"); desc = p; while ((*desc == ' ') || (*desc == '\t')) desc++; Syslog('f', "Found area \"%s\" \"%s\" \"%s\" \"%s\"", tag, raid, flow, desc); Found = TRUE; break; } } if (strlen(buf) && !strncmp(buf, "% FDN:", 6)) { /* * All entries in group are seen, the area wasn't there. */ break; } } } if (Found) break; } } } else { /* * Normal taglist format */ while (fgets(buf, 4096, ap)) { if (strlen(buf) && isalnum(buf[0])) { tag = strtok(buf, "\t \r\n\0"); p = strtok(NULL, "\r\n\0"); if (p == NULL) p = tag; /* If no description after the TAG, use TAG as description */ desc = p; while ((*desc == ' ') || (*desc == '\t')) desc++; if (strcasecmp(tag, Area) == 0) { Syslog('f', "Found tag \"%s\" desc \"%s\"", tag, desc); Found = TRUE; break; } } } } if (!Found) { Syslog('f', "Area %s not found in taglist", Area); free(buf); fclose(ap); free(temp); return 1; } /* * Some people write taglists with lowercase tagnames... */ for (i = 0; i < strlen(tag); i++) tag[i] = toupper(tag[i]); Syslog('m', "Found tag \"%s\" desc \"%s\"", tag, desc); /* * Area is in AREAS file, now create area. * If needed, connect at uplink. */ if (SendUplink && SearchNode(fgroup.UpLink)) { if (nodes.UplFmgrBbbs) snprintf(temp, PATH_MAX, "file +%s", tag); else snprintf(temp, PATH_MAX, "+%s", tag); From = fido2faddr(fgroup.UseAka); To = fido2faddr(fgroup.UpLink); if (UplinkRequest(To, From, TRUE, temp)) { WriteError("Can't send netmail to uplink"); fclose(ap); free(buf); free(temp); tidy_faddr(From); tidy_faddr(To); return 1; } tidy_faddr(From); tidy_faddr(To); } /* * Open tic area and set filepointer to the end to append * a new record. */ snprintf(temp, PATH_MAX, "%s/etc/tic.data", getenv("MBSE_ROOT")); if ((mp = fopen(temp, "r+")) == NULL) { WriteError("$Can't open %s", temp); fclose(ap); free(buf); free(temp); return 1; } fread(&tichdr, sizeof(tichdr), 1, mp); fseek(mp, 0, SEEK_END); memset(&tic, 0, sizeof(tic)); Syslog('f', "TIC area open, filepos %ld", ftell(mp)); /* * Open files area, and find a free slot */ snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r+")) == NULL) { WriteError("$Can't open %s", temp); fclose(ap); fclose(mp); free(buf); free(temp); return 1; } fread(&areahdr, sizeof(areahdr), 1, fp); Syslog('f', "File area is open"); /* * Verify the file is large enough */ fseek(fp, 0, SEEK_END); offset = areahdr.hdrsize + ((fgroup.StartArea -1) * (areahdr.recsize)); Syslog('+', "file end at %ld, offset needed %ld", ftell(fp), offset); if (ftell(fp) < offset) { Syslog('f', "Database too small, expanding..."); memset(&area, 0, sizeof(area)); while (TRUE) { fwrite(&area, sizeof(area), 1, fp); if (ftell(fp) >= areahdr.hdrsize + ((fgroup.StartArea -1) * (areahdr.recsize))) break; } } if (fseek(fp, offset, SEEK_SET)) { WriteError("$Can't seek in %s to position %ld", temp, offset); fclose(ap); fclose(mp); fclose(fp); free(buf); free(temp); return 1; } /* * Search a free record */ Syslog('f', "Start search record"); while (fread(&area, sizeof(area), 1, fp) == 1) { if (!area.Available) { fseek(fp, - areahdr.recsize, SEEK_CUR); rc = 1; break; } } if (!rc) { Syslog('f', "No free slot, append after last record"); fseek(fp, 0, SEEK_END); if (ftell(fp) < areahdr.hdrsize + ((fgroup.StartArea -1) * (areahdr.recsize))) { Syslog('f', "Database too small, expanding..."); memset(&area, 0, sizeof(area)); while (TRUE) { fwrite(&area, sizeof(area), 1, fp); if (ftell(fp) >= areahdr.hdrsize + ((fgroup.StartArea -1) * (areahdr.recsize))) break; } } rc = 1; } AreaNr = ((ftell(fp) - areahdr.hdrsize) / (areahdr.recsize)) + 1; Syslog('f', "Found free slot at %ld", AreaNr); /* * Create the records */ memset(&area, 0, sizeof(area)); strncpy(area.Name, desc, 44); strcpy(temp, tag); temp = tl(temp); for (i = 0; i < strlen(temp); i++) if (temp[i] == '.') temp[i] = '/'; snprintf(area.Path, 81, "%s/%s", fgroup.BasePath, temp); area.DLSec = fgroup.DLSec; area.UPSec = fgroup.UPSec; area.LTSec = fgroup.LTSec; area.New = area.Dupes = area.Free = area.AddAlpha = area.FileFind = area.Available = area.FileReq = TRUE; strncpy(area.BbsGroup, fgroup.BbsGroup, 12); strncpy(area.NewGroup, fgroup.AnnGroup, 12); strncpy(area.Archiver, fgroup.Convert, 5); area.Upload = fgroup.Upload; fwrite(&area, sizeof(area), 1, fp); fclose(fp); /* * Create download path */ snprintf(temp, PATH_MAX, "%s/foobar", area.Path); if (!mkdirs(temp, 0775)) WriteError("Can't create %s", temp); /* * Create download database */ if ((fdb_area = mbsedb_OpenFDB(AreaNr, 30))) mbsedb_CloseFDB(fdb_area); /* * Setup new TIC area. */ strncpy(tic.Name, tag, 20); strncpy(tic.Comment, desc, 55); tic.FileArea = AreaNr; strncpy(tic.Group, fgroup.Name, 12); tic.AreaStart = time(NULL); tic.Aka = fgroup.UseAka; strncpy(tic.Convert, fgroup.Convert, 5); strncpy(tic.Banner, fgroup.Banner, 14); tic.Replace = fgroup.Replace; tic.DupCheck = fgroup.DupCheck; tic.Secure = fgroup.Secure; tic.Touch = fgroup.Touch; tic.VirScan = fgroup.VirScan; tic.Announce = fgroup.Announce; tic.UpdMagic = fgroup.UpdMagic; tic.FileId = fgroup.FileId; tic.ConvertAll = fgroup.ConvertAll; tic.SendOrg = fgroup.SendOrg; tic.Active = TRUE; tic.LinkSec.level = fgroup.LinkSec.level; tic.LinkSec.flags = fgroup.LinkSec.flags; tic.LinkSec.notflags = fgroup.LinkSec.notflags; fwrite(&tic, sizeof(tic), 1, mp); memset(&System, 0, sizeof(System)); System.aka = fgroup.UpLink; if (flow && !strcmp(flow, "*&")) /* * Areas direction HQ's go the other way */ System.sendto = TRUE; else /* * Normal distribution areas. */ System.receivefrom = TRUE; fwrite(&System, sizeof(System), 1, mp); memset(&System, 0, sizeof(System)); for (i = 1; i < (tichdr.syssize / sizeof(System)); i++) fwrite(&System, sizeof(System), 1, mp); fclose(mp); fclose(ap); free(buf); free(temp); if (f == NULL) Mgrlog("Auto created TIC area %s, group %s, bbs area %ld", tic.Name, tic.Group, AreaNr); else Mgrlog("Auto created TIC area %s, group %s, bbs area %ld, for node %s", tic.Name, tic.Group, AreaNr, ascfnode(f, 0x1f)); return 0; }
/* * Return values: * 0 - Success * 1 - Some error * 2 - Orphaned tic */ int ProcessTic(fa_list **sbl, orphans **opl) { int First, Listed = FALSE, DownLinks = 0, MustRearc = FALSE; int UnPacked = FALSE, IsArchive = FALSE, rc, i, j, k; char *Temp, *unarc = NULL, *cmd = NULL; char temp1[PATH_MAX], temp2[PATH_MAX], sbe[24], TDesc[1024]; unsigned int crc, crc2, Kb; sysconnect Link; FILE *fp; struct utimbuf ut; int BBS_Imp = FALSE, DidBanner = FALSE; faddr *p_from; qualify *qal = NULL, *tmpq; orphans *topl; if (TIC.TicIn.PathError) { WriteError("Our Aka is in the path"); tic_bad++; return 1; } Temp = calloc(PATH_MAX, sizeof(char)); if (!do_quiet) { mbse_colour(LIGHTGREEN, BLACK); printf("Checking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } if (TIC.Orphaned) { fill_orphans(opl, TIC.TicName, TIC.TicIn.Area, TIC.TicIn.File, TRUE, FALSE); Syslog('+', "File not in inbound: %s", TIC.TicIn.File); free(Temp); return 2; } snprintf(Temp, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); crc = file_crc(Temp, CFG.slow_util && do_quiet); TIC.FileSize = file_size(Temp); TIC.FileDate = file_time(Temp); if (TIC.TicIn.Size) { if (TIC.TicIn.Size != TIC.FileSize) WriteError("Size is %ld, expected %ld", TIC.FileSize, TIC.TicIn.Size); } else { /* * No filesize in TIC file, add filesize. */ TIC.TicIn.Size = TIC.FileSize; } if (TIC.Crc_Int) { if (crc != TIC.Crc_Int) { Syslog('!', "CRC: expected %08lX, the file is %08lX", TIC.Crc_Int, crc); fill_orphans(opl, TIC.TicName, TIC.TicIn.Area, TIC.TicIn.File, FALSE, TRUE); if (check_crc) { Syslog('+', "Bad CRC, will check this ticfile later"); free(Temp); return 1; } else { Syslog('!', "CRC: error, recalculating crc"); ReCalcCrc(Temp); } } } else { Syslog('+', "CRC: missing, calculating CRC"); ReCalcCrc(Temp); } /* * Load and check the .TIC area. */ if (!SearchTic(TIC.TicIn.Area)) { UpdateNode(); Syslog('f', "Unknown file area %s", TIC.TicIn.Area); p_from = fido2faddr(TIC.Aka); if (!create_ticarea(TIC.TicIn.Area, p_from)) { Bad((char *)"Unknown file area %s", TIC.TicIn.Area); free(Temp); tidy_faddr(p_from); return 1; } tidy_faddr(p_from); /* * Try to load the .TIC area again. */ if (!SearchTic(TIC.TicIn.Area)) { Bad((char *)"Reload of new created file area %s failed", TIC.TicIn.Area); free(Temp); return 1; } } if ((tic.Secure) && (!TIC.TicIn.Hatch)) { First = TRUE; while (GetTicSystem(&Link, First)) { First = FALSE; if (Link.aka.zone) { if ((Link.aka.zone == TIC.Aka.zone) && (Link.aka.net == TIC.Aka.net) && (Link.aka.node == TIC.Aka.node) && (Link.aka.point== TIC.Aka.point) && (Link.receivefrom)) Listed = TRUE; } } if (!Listed) { Bad((char *)"%s NOT connected to %s", aka2str(TIC.Aka), TIC.TicIn.Area); free(Temp); return 1; } } if ((!SearchNode(TIC.Aka)) && (!TIC.TicIn.Hatch)) { Bad((char *)"%s NOT known", aka2str(TIC.Aka)); free(Temp); return 1; } if (!TIC.TicIn.Hatch) { if (strcasecmp(TIC.TicIn.Pw, nodes.Fpasswd)) { Bad((char *)"Pwd error, got %s, expected %s", TIC.TicIn.Pw, nodes.Fpasswd); free(Temp); return 1; } } else { if (strcasecmp(TIC.TicIn.Pw, CFG.hatchpasswd)) { Bad((char *)"Password error in local Hatch"); WriteError("WARNING: it might be a Trojan in your inbound"); free(Temp); return 1; } } if (Magic_DeleteFile()) { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicName); file_rm(temp1); Syslog('+', "Deleted file %s", temp1); file_rm(Temp); free(Temp); return 0; } if (Magic_MoveFile()) { if (!SearchTic(TIC.TicIn.Area)) { Bad((char *)"Unknown Area: %s", TIC.TicIn.Area); free(Temp); return 1; } } strncpy(T_File.Echo, tic.Name, 20); strncpy(T_File.Group, tic.Group, 12); TIC.KeepNum = tic.KeepLatest; Magic_Keepnum(); if (!tic.FileArea) { Syslog('+', "Passthru TIC area!"); strcpy(TIC.BBSpath, CFG.ticout); strcpy(TIC.BBSdesc, tic.Comment); } else { snprintf(Temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((fp = fopen(Temp, "r")) == NULL) { WriteError("Can't access fareas.data area: %ld", tic.FileArea); free(Temp); return 1; } fread(&areahdr, sizeof(areahdr), 1, fp); if (fseek(fp, ((tic.FileArea -1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET)) { fclose(fp); WriteError("Can't seek area %ld in fareas.data", tic.FileArea); free(Temp); return 1; } if (fread(&area, areahdr.recsize, 1, fp) != 1) { fclose(fp); WriteError("Can't read area %ld in fareas.data", tic.FileArea); free(Temp); return 1; } fclose(fp); strcpy(TIC.BBSpath, area.Path); strcpy(TIC.BBSdesc, area.Name); /* * If the File area has a special announce group, change * the group to that name. */ if (strlen(area.NewGroup)) strncpy(T_File.Group, area.NewGroup, 12); } strncpy(T_File.Comment, tic.Comment, 55); /* * Check if the destination area really exists, it may be that * the area is not linked to an existing BBS area. */ if (tic.FileArea && access(TIC.BBSpath, W_OK)) { WriteError("No write access to \"%s\"", TIC.BBSpath); Bad((char *)"Dest directory not available"); free(Temp); return 1; } if ((tic.DupCheck) && (check_dupe)) { snprintf(Temp, PATH_MAX, "%s%s", TIC.TicIn.Area, TIC.TicIn.Crc); crc2 = 0xffffffff; crc2 = upd_crc32(Temp, crc2, strlen(Temp)); if (CheckDupe(crc2, D_FILEECHO, CFG.tic_dupes)) { Bad((char *)"Duplicate file"); tic_dup++; free(Temp); return 1; } } /* * Count the actual downlinks for this area and build the list of * systems qualified to receive this file. */ First = TRUE; while (GetTicSystem(&Link, First)) { First = FALSE; if ((Link.aka.zone) && (Link.sendto) && (!Link.pause)) { DownLinks++; p_from = fido2faddr(Link.aka); if (TIC.TicIn.Hatch) { fill_qualify(&qal, Link.aka, FALSE, in_list(p_from, sbl, TRUE)); } else { fill_qualify(&qal, Link.aka, ((TIC.Aka.zone == Link.aka.zone) && (TIC.Aka.net == Link.aka.net) && (TIC.Aka.node == Link.aka.node) && (TIC.Aka.point == Link.aka.point)), in_list(p_from, sbl, TRUE)); } tidy_faddr(p_from); } } T_File.Size = TIC.FileSize; T_File.SizeKb = TIC.FileSize / 1024; /* * Update the uplink's counters. */ Kb = TIC.FileSize / 1024; if (SearchNode(TIC.Aka)) { StatAdd(&nodes.FilesRcvd, 1L); StatAdd(&nodes.F_KbRcvd, Kb); UpdateNode(); SearchNode(TIC.Aka); } /* * Update the fileecho and group counters. */ StatAdd(&fgroup.Files, 1L); StatAdd(&fgroup.KBytes, Kb); fgroup.LastDate = time(NULL); StatAdd(&tic.Files, 1L); StatAdd(&tic.KBytes, Kb); tic.LastAction = time(NULL); UpdateTic(); if (!do_quiet) { printf("Unpacking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } /* * Check if this is an archive, and if so, which compression method * is used for this file. */ if (strlen(tic.Convert) || tic.FileId || tic.ConvertAll || strlen(tic.Banner)) { /* * Create tmp workdir */ if (create_tmpwork()) { free(Temp); tidy_qualify(&qal); return 1; } if ((unarc = unpacker(TIC.TicIn.File)) == NULL) Syslog('+', "Unknown archive format %s", TIC.TicIn.File); else { IsArchive = TRUE; if ((strlen(tic.Convert) && (strcmp(unarc, tic.Convert) == 0)) || (tic.ConvertAll)) MustRearc = TRUE; } } /* * Copy the file if there are downlinks and we send the * original file, but want to rearc it for ourself, or if * it's a passthru area. */ if (((tic.SendOrg) && (MustRearc || strlen(tic.Banner))) || (!tic.FileArea)) { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); snprintf(temp2, PATH_MAX, "%s/%s", CFG.ticout, TIC.TicIn.File); if ((rc = file_cp(temp1, temp2) == 0)) { TIC.SendOrg = TRUE; } else { WriteError("Copy %s to %s failed: %s", temp1, temp2, strerror(rc)); } } if (MustRearc && IsArchive) { snprintf(temp2, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); if (!checkspace(temp2, TIC.TicIn.File, UNPACK_FACTOR)) { Bad((char *)"Not enough free diskspace left"); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (chdir(temp2) != 0) { WriteError("$Can't change to %s", temp2); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (!getarchiver(unarc)) { WriteError("Can't get archiver for %s", unarc); chdir(TIC.Inbound); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (strlen(archiver.funarc) == 0) { Syslog('!', "No unarc command available"); } else { cmd = xstrcpy(archiver.funarc); snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { UnPacked = TRUE; } else { chdir(TIC.Inbound); Bad((char *)"Archive maybe corrupt"); free(Temp); clean_tmpwork(); return 1; } free(cmd); } } /* * Scan file for viri. */ if (tic.VirScan) { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (!do_quiet) { printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } if (VirScanFile(temp1)) { chdir(TIC.Inbound); Bad((char *)"Possible virus found!"); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (!do_quiet) { printf("Checking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } } if (tic.FileId && tic.FileArea && IsArchive) { if (UnPacked) { snprintf(temp1, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); snprintf(Temp, PATH_MAX, "FILE_ID.DIZ"); if (getfilecase(temp1, Temp)) { Syslog('f', "Found %s", Temp); snprintf(temp1, PATH_MAX, "%s/tmp/arc%d/%s", getenv("MBSE_ROOT"), (int)getpid(), Temp); snprintf(temp2, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); } else { Syslog('f', "Didn't find a FILE_ID.DIZ"); } } else { if (!getarchiver(unarc)) { chdir(TIC.Inbound); } else { cmd = xstrcpy(archiver.iunarc); if (cmd == NULL) { WriteError("No unarc command available"); } else { snprintf(temp1, PATH_MAX, "%s/tmp", getenv("MBSE_ROOT")); chdir(temp1); snprintf(temp1, PATH_MAX, "%s/%s FILE_ID.DIZ", TIC.Inbound, TIC.TicIn.File); if (execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) { snprintf(temp1, PATH_MAX, "%s/%s file_id.diz", TIC.Inbound, TIC.TicIn.File); execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); } free(cmd); } } /* if getarchiver */ } /* if not unpacked */ } /* if need FILE_ID.DIZ and not passthru */ /* * Create internal file description, priority is FILE_ID.DIZ, * 2nd LDesc, and finally the standard description. */ if (!Get_File_Id()) { if (TIC.TicIn.TotLDesc > 2) { for (i = 0; i < TIC.TicIn.TotLDesc; i++) { strncpy(TIC.File_Id[i], TIC.TicIn.LDesc[i], 48); } TIC.File_Id_Ct = TIC.TicIn.TotLDesc; } else { /* * Format the description line (max 255 chars) in parts of 48 characters. */ if (strlen(TIC.TicIn.Desc) <= 48) { strcpy(TIC.File_Id[0], TIC.TicIn.Desc); TIC.File_Id_Ct++; } else { memset(&TDesc, 0, sizeof(TDesc)); strcpy(TDesc, TIC.TicIn.Desc); while (strlen(TDesc) > 48) { j = 48; while ((TDesc[j] != ' ') && (j > 0)) j--; if (j == 0) { Syslog('f', "Panic, no spaces"); j = 47; } strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, j); Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, j, TIC.File_Id[TIC.File_Id_Ct]); TIC.File_Id_Ct++; k = strlen(TDesc); j++; /* Correct space */ for (i = 0; i <= k; i++, j++) TDesc[i] = TDesc[j]; if (TIC.File_Id_Ct == 23) break; } strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, 48); Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, strlen(TIC.File_Id[TIC.File_Id_Ct]), TIC.File_Id[TIC.File_Id_Ct]); TIC.File_Id_Ct++; } } } /* not get FILE_ID.DIZ */ /* * Now check if other (older) ticfiles point to this file, * if found mark it to purge later. */ for (topl = *opl; topl; topl = topl->next) { if ((strcmp(topl->Area, TIC.TicIn.Area) == 0) && (strcmp(topl->FileName, TIC.TicIn.File) == 0)) { topl->Purged = TRUE; } } /* * Rearc file if it is an unpacked archive. */ if ((MustRearc) && (UnPacked) && (tic.FileArea)) { if (Rearc(tic.Convert)) { /* * Get new filesize for import and announce */ snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.NewFile); TIC.FileSize = file_size(temp1); T_File.Size = TIC.FileSize; T_File.SizeKb = TIC.FileSize / 1024; /* * Calculate the CRC if we must send the new archived file. */ if (!TIC.SendOrg) { ReCalcCrc(temp1); } } else { WriteError("Rearc failed"); } /* if Rearc() */ } /* * Change banner if needed. */ if ((strlen(tic.Banner)) && IsArchive) { cmd = xstrcpy(archiver.barc); if ((cmd == NULL) || (!strlen(cmd))) { Syslog('+', "No banner command for %s", archiver.name); } else { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.NewFile); snprintf(Temp, PATH_MAX, "%s/etc/%s", getenv("MBSE_ROOT"), tic.Banner); if (execute_str(cmd, temp1, (char *)NULL, Temp, (char *)"/dev/null", (char *)"/dev/null")) { WriteError("Changing the banner failed"); } else { Syslog('+', "New banner %s", tic.Banner); TIC.FileSize = file_size(temp1); T_File.Size = TIC.FileSize; T_File.SizeKb = TIC.FileSize / 1024; ReCalcCrc(temp1); DidBanner = TRUE; } } } clean_tmpwork(); chdir(TIC.Inbound); /* * If the file is converted, we set the date of the original * received file as the file creation date. */ snprintf(Temp, PATH_MAX, "%s/%s", TIC.Inbound, TIC.NewFile); if ((MustRearc || DidBanner) && CFG.ct_KeepDate) { if ((tic.Touch) && (tic.FileArea)) { ut.actime = mktime(localtime(&TIC.FileDate)); ut.modtime = mktime(localtime(&TIC.FileDate)); utime(Temp, &ut); Syslog('-', "Restamp filedate %s to %s", Temp, rfcdate(ut.modtime)); } } /* * Now make sure the file timestamp is updated. The file may be restamped, * altered by banners etc. */ TIC.FileDate = file_time(Temp); /* * If not passthru, import in the BBS. */ if (tic.FileArea) { Syslog('+', "Import: %s (%s) Area: %s", TIC.NewFile, TIC.NewFullName, TIC.TicIn.Area); BBS_Imp = Add_BBS(&qal); if (!BBS_Imp) { Bad((char *)"File Import Error"); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } } chdir(TIC.Inbound); /* * Create file announce record */ if (tic.FileArea) { if (strlen(TIC.TicIn.Magic)) magic_update(TIC.TicIn.Magic, TIC.NewFile); else Magic_UpDateAlias(); for (i = 0; i < TIC.File_Id_Ct; i++) strncpy(T_File.LDesc[i], TIC.File_Id[i], 48); T_File.TotLdesc = TIC.File_Id_Ct; T_File.Announce = tic.Announce; strncpy(T_File.Name, TIC.NewFile, 12); strncpy(T_File.LName, TIC.NewFullName, 80); T_File.Fdate = TIC.FileDate; Add_ToBeRep(T_File); } if (TIC.SendOrg && !tic.FileArea) { /* * If it's a passthru area we don't need the * file in the inbound anymore so it can be * deleted. */ snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (file_rm(temp1) == 0) Syslog('f', "Deleted %s", temp1); } if (DownLinks) { First = TRUE; /* * Add all our system aka's to the seenby lines in the same zone, * omit aka's already in the seenby list. */ for (i = 0; i < 39; i++) { if (CFG.akavalid[i] && (tic.Aka.zone == CFG.aka[i].zone)) { p_from = fido2faddr(CFG.aka[i]); if (! in_list(p_from, sbl, TRUE)) { if (CFG.aka[i].point) snprintf(sbe, 24, "%u:%u/%u.%u", CFG.aka[i].zone, CFG.aka[i].net, CFG.aka[i].node, CFG.aka[i].point); else snprintf(sbe, 24, "%u:%u/%u", CFG.aka[i].zone, CFG.aka[i].net, CFG.aka[i].node); fill_list(sbl, sbe, NULL); } tidy_faddr(p_from); } } /* * Add seen-by lines for all systems that will receive this file. */ for (tmpq = qal; tmpq; tmpq = tmpq->next) { if (tmpq->send) { if (CFG.aka[i].point) snprintf(sbe, 24, "%u:%u/%u.%u", tmpq->aka.zone, tmpq->aka.net, tmpq->aka.node, tmpq->aka.point); else snprintf(sbe, 24, "%u:%u/%u", tmpq->aka.zone, tmpq->aka.net, tmpq->aka.node); fill_list(sbl, sbe, NULL); } } uniq_list(sbl); sort_list(sbl); /* * Now forward this file to the qualified downlinks. */ for (tmpq = qal; tmpq; tmpq = tmpq->next) { if (tmpq->send) { ForwardFile(tmpq->aka, *sbl); tic_out++; } } } Magic_ExecCommand(); Magic_CopyFile(); Magic_UnpackFile(); Magic_AdoptFile(); snprintf(Temp, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicName); if (unlink(Temp)) { WriteError("$Can't delete %s", Temp); } free(Temp); tidy_qualify(&qal); return 0; }
FILE *CreatePkt(char *Queue, fidoaddr Orig, fidoaddr Dest, char *Extension) { static FILE *qp; unsigned char buffer[0x3a]; time_t Now; int i; struct tm *Tm; char str[81]; if ((qp = fopen(Queue, "a")) == NULL) { WriteError("$Can't create Queue %s", Queue); return NULL; } /* * Write .PKT header, see FSC-0039 rev. 4 */ memset(&buffer, 0, sizeof(buffer)); Now = time(NULL); Tm = localtime(&Now); if (Tm->tm_sec > 59) Tm->tm_sec = 59; buffer[0x00] = (Orig.node & 0x00ff); buffer[0x01] = (Orig.node & 0xff00) >> 8; buffer[0x02] = (Dest.node & 0x00ff); buffer[0x03] = (Dest.node & 0xff00) >> 8; buffer[0x04] = ((Tm->tm_year + 1900) & 0x00ff); buffer[0x05] = ((Tm->tm_year + 1900) & 0xff00) >> 8; buffer[0x06] = Tm->tm_mon; buffer[0x08] = Tm->tm_mday; buffer[0x0a] = Tm->tm_hour; buffer[0x0c] = Tm->tm_min; buffer[0x0e] = Tm->tm_sec; buffer[0x12] = 2; buffer[0x14] = (Orig.net & 0x00ff); buffer[0x15] = (Orig.net & 0xff00) >> 8; buffer[0x16] = (Dest.net & 0x00ff); buffer[0x17] = (Dest.net & 0xff00) >> 8; buffer[0x18] = (PRODCODE & 0x00ff); buffer[0x19] = (VERSION_MAJOR & 0x00ff); memset(&str, 0, 8); /* Packet password */ if (SearchNode(Dest)) { if (strlen(nodes.Epasswd)) { snprintf(str, 81, "%s", nodes.Epasswd); } } for (i = 0; i < 8; i++) buffer[0x1a + i] = toupper(str[i]); /* FSC-0039 only talks about A-Z, 0-9, so force uppercase */ buffer[0x22] = (Orig.zone & 0x00ff); buffer[0x23] = (Orig.zone & 0xff00) >> 8; buffer[0x24] = (Dest.zone & 0x00ff); buffer[0x25] = (Dest.zone & 0xff00) >> 8; buffer[0x29] = 1; buffer[0x2a] = (PRODCODE & 0xff00) >> 8; buffer[0x2b] = (VERSION_MINOR & 0x00ff); buffer[0x2c] = 1; buffer[0x2e] = buffer[0x22]; buffer[0x2f] = buffer[0x23]; buffer[0x30] = buffer[0x24]; buffer[0x31] = buffer[0x25]; buffer[0x32] = (Orig.point & 0x00ff); buffer[0x33] = (Orig.point & 0xff00) >> 8; buffer[0x34] = (Dest.point & 0x00ff); buffer[0x35] = (Dest.point & 0xff00) >> 8; buffer[0x36] = 'm'; buffer[0x37] = 'b'; buffer[0x38] = 's'; buffer[0x39] = 'e'; fwrite(buffer, 1, 0x3a, qp); fsync(fileno(qp)); return qp; }
int main() { LinkTable *Link=CreatLinkTable(); tstudent student; char chose; int i=0; clock_t start,end; double cost; for(i=0;i<1000000;i++) { student.id=i; strcpy(student.name,"aaadfadfad"); InsertNode(Link,&student,sizeof(tstudent)); } print(); while(1) { printf("\nplease input you want to user function !"); scanf(" %c",&chose); if(islower(chose)) { chose=chose-('a'-'A'); } switch(chose) { case 'I' : { printf("please input id: "); scanf("%d",&student.id); printf("please input name: "); scanf("%s",&student.name); InsertNode(Link,&student,sizeof(tstudent)); } break; case 'D': { printf("\nplease input you want to Delete id:"); scanf("%d",&key); if(DeleteNode(Link,condition)) { printf(" \t SUCCESS "); } else printf("\t ERROR"); } break; case 'S': { printf("\nplease input you want to search id:"); scanf("%d",&key); start=clock(); if(display(SearchNode(Link,condition))) { end=clock(); cost = (double )(end-start )/CLOCKS_PER_SEC; printf(" \t use time is %lf ",cost); } else printf("\t ERROR"); } break; case 'C': { printf("\nplease input you want to Change id:"); scanf("%d",&key); printf("%d",sizeof(tstudent)); UpdataNode(Link,condition,handle,sizeof(tstudent)); } break; case 'P': { if( Display(Link,display) ) { printf("\nSUCCESS"); } else { printf("ERROR!"); } } break; case 'O' : version(); break; case 'A': { start=clock(); for(i=0;i<1000;i++) { key=rand() % 100000; if(display(SearchNode(Link,condition))) { printf("Search Success"); } else printf("\t ERROR"); } end=clock(); cost = (double )(end-start )/CLOCKS_PER_SEC; printf(" \t use time is %lf ",cost); } break; } } }
bool nuiPopupMenu::MouseMoved(nuiSize X, nuiSize Y) { bool IsInside; int cpt = SearchRectIndex(X,Y); IsInside = cpt >= 0 ? true : false; if (IsInside) { // Do the auto scroll feature: nuiMenuRect* pMenuRect = mRects[cpt]; NGL_ASSERT(pMenuRect); if (pMenuRect->mpSBar->IsVisible()) { nuiScrollBar* pSB = pMenuRect->mpSBar; NGL_ASSERT(pSB); nuiRange& rRange(pSB->GetRange()); if (Y > mRect.Bottom() - AUTOSCROLL_HEIGHT) { // Scroll down if (rRange.GetValue() + rRange.GetPageSize() < rRange.GetMaximum()) { mScrollUp = false; if (!mScrollTimer.IsRunning()) mScrollTimer.Start(false, false); return true; } } if (Y < AUTOSCROLL_HEIGHT) { // Scroll up if (rRange.GetValue() > rRange.GetMinimum()) { mScrollUp = true; if (!mScrollTimer.IsRunning()) mScrollTimer.Start(false, false); return true; } } } if (mScrollTimer.IsRunning()) // Disable scroll timer if it was still running... mScrollTimer.Stop(); nuiTreeNodePtr pNode = SearchNode(X,Y,cpt); if (pNode) { if (pNode->GetElement()->IsDisabled()) return true; if (!mSelectionTimer.IsRunning()) { if ((!pNode->IsEmpty() && !pNode->IsOpened()) || (mpSelectedNode && ((mpSelectedNode->GetDepth()-1 != pNode->GetDepth()-1) || mpSelectedNode->IsOpened()))) { //may be opened, so start the timer if (mpSelectedNode && mpSelectedNode != pNode) { nuiRect WidgetRect = mpSelectedNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[mpSelectedNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); mpSelectedNode->Select(false); Invalidate(); //(r); mpSelectedNode->GetElement()->Invalidate(); } mpNewSelectedNode = pNode; nuiRect WidgetRect = mpNewSelectedNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[mpNewSelectedNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); mpNewSelectedNode->Select(true); Invalidate(); //(r); mpNewSelectedNode->GetElement()->Invalidate(); mSelectionTimer.SetPeriod(nglTime(TIMER_PERIOD)); mSelectionTimer.Start(false); } else { //empty node, no need to time this if (mpSelectedNode != pNode) { if (mpSelectedNode) { mpSelectedNode->Select(false); nuiRect WidgetRect = mpSelectedNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[mpSelectedNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); Invalidate(); //(r); mpSelectedNode->GetElement()->Invalidate(); } pNode->Select(true); nuiRect WidgetRect = pNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[pNode->GetDepth()-1]; /// get the current menuRect uint32 dbg = pNode->GetDepth()-1; nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); Invalidate(); //(r); pNode->GetElement()->Invalidate(); mpSelectedNode = pNode; } } } else { // Timer is active if (mpNewSelectedNode && pNode != mpNewSelectedNode) { nuiRect WidgetRect = mpNewSelectedNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[mpNewSelectedNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); mpNewSelectedNode->Select(false); Invalidate(); //(r); mpNewSelectedNode->GetElement()->Invalidate(); } mpNewSelectedNode = pNode; nuiRect WidgetRect = mpNewSelectedNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[mpNewSelectedNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); mpNewSelectedNode->Select(true); Invalidate(); //(r); mpNewSelectedNode->GetElement()->Invalidate(); } return true; } } return false; }
bool nuiPopupMenu::MouseClicked(nuiSize X, nuiSize Y, nglMouseInfo::Flags Button) { mSelectionTimer.Stop(); if (Button & nglMouseInfo::ButtonWheelUp) { IncrementScrollBar(false); mWheelMoved = true; return true; } else if (Button & nglMouseInfo::ButtonWheelDown) { IncrementScrollBar(true); mWheelMoved = true; return true; } bool IsInside; int cpt = SearchRectIndex(X,Y); IsInside = cpt >= 0 ? true : false; if (!IsInside) { // Out of bounds, had to close menu if (mpSelectedNode) { mpSelectedNode->Select(false); mpSelectedNode = NULL; } if (!MenuDone()) Trash(); else RemoveMenu(); return true; } else { // Search the clicked node nuiTreeNodePtr pNode = SearchNode(X,Y,cpt); if (pNode) { if (pNode->GetElement()->IsDisabled()) return true; if (mpSelectedNode && mpSelectedNode != pNode) mpSelectedNode->Select(false); nuiTreeNodePtr pParent = GetParentNode(mpTree, pNode); if (pParent) { pParent->OpenAllChildren(false); pParent->SelectAllChildren(false); } mpSelectedNode = mpNewSelectedNode = pNode; pNode->Select(true); if (!pNode->IsEmpty()) { pNode->Open(true); if (!pNode->GetChildrenCount()) pNode->Open(false); else { ResetScrolling(pNode->GetDepth()); FillSelectedNodes(); } } Invalidate(); InvalidateLayout(); return true; } } return true; }
bool nuiPopupMenu::MouseUnclicked(nuiSize X, nuiSize Y, nglMouseInfo::Flags Button) { if (mWheelMoved) { mWheelMoved = false; return true; } if (nglTime() - mStartTime < mDelayTime) { return true; } bool IsInside; int cpt = SearchRectIndex(X,Y); IsInside = cpt >= 0 ? true : false; if (!IsInside) { // Out of bounds, had to close menu mpTree->OpenAllChildren(false); mpTree->SelectAllChildren(false); mpSelectedNode = NULL; FillSelectedNodes(); if (!MenuDone()) Trash(); else RemoveMenu(); return true; } else { nuiTreeNodePtr pNode = SearchNode(X,Y,cpt); if (pNode) { if (!pNode->IsSelectionEnabled() || pNode->GetElement()->IsDisabled()) return true; if (mpSelectedNode) { mpSelectedNode->Select(false); } nuiTreeNodePtr pParent = GetParentNode(mpTree, pNode); if (pParent) { pParent->OpenAllChildren(false); pParent->SelectAllChildren(false); } mpSelectedNode = mpNewSelectedNode = pNode; pNode->Select(true); if (!pNode->IsEmpty()) { pNode->Open(true); if (!pNode->GetChildrenCount()) pNode->Open(false); else { ResetScrolling(pNode->GetDepth()); FillSelectedNodes(); } } else { FillSelectedNodes(); if (mpSelectedNode) mpSelectedNode->Activated(); if (!MenuDone()) Trash(); else RemoveMenu(); } Invalidate(); InvalidateLayout(); } return true; } return false; }