From b48a74556fd21dfc175d754058d22b9216e6b12e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Mon, 25 Jan 2016 00:53:42 +0100 Subject: [PATCH] Fix problems from porting Qt3->Qt4, which were caused by introducing takeFirst() method in place of next --- src/help/help.cpp | 37 ++++++----- src/lgconfig/lgconfig.cpp | 27 ++++---- src/net/lognet.cpp | 134 ++++++++++++++++++++------------------ src/preproc/prep.cpp | 25 +++---- 4 files changed, 120 insertions(+), 103 deletions(-) diff --git a/src/help/help.cpp b/src/help/help.cpp index 7145892..9645f41 100644 --- a/src/help/help.cpp +++ b/src/help/help.cpp @@ -233,11 +233,12 @@ void HTMLAnalyzer::AnalyzeTag(QString *t) void HTMLAnalyzer::DumpList() { Tag *pom; - pom = tags.first(); - while (pom != NULL) { + QListIterator tagsIterator(tags); + + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); fprintf(stderr, "%s:%s,%s,%s\n", names[pom->tag_type], pom->tag_text, pom->tag_link, pom->tag_label); - pom=tags.takeFirst(); } } @@ -245,12 +246,13 @@ void HTMLAnalyzer::PackLinks() { Tag *pom,*pom1; char s[255]; + QListIterator tagsIterator(tags); - pom = tags.first(); - while (pom!=NULL) { + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); if ((pom->tag_type == TAG_LINK) || (pom->tag_type == TAG_ANCHOR)) { - pom1 = tags.takeFirst(); + pom1 = tagsIterator.next(); strcpy(s, ""); while ((pom1 != NULL) && (pom1->tag_type != TAG_LINK_END)) { @@ -263,7 +265,7 @@ void HTMLAnalyzer::PackLinks() tags.removeOne(pom1); pom = tags.current(); } else { - pom = tags.takeFirst(); + pom = tagsIterator.next(); } } } @@ -272,14 +274,15 @@ void HTMLAnalyzer::PackLinks() Tag *HTMLAnalyzer::CheckTag(int x,int y) { Tag *pom; - pom=tags.first(); - while (pom != NULL) { + QListIterator tagsIterator(tags); + + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); if (pom->tag_type==TAG_LINK) if ((x >= pom->x) && (x <= pom->x + pom->w) && (y >= pom->y) && (y <= pom->y + pom->h)) { return pom; } - pom=tags.takeFirst(); } return NULL; } @@ -287,13 +290,14 @@ Tag *HTMLAnalyzer::CheckTag(int x,int y) Tag *HTMLAnalyzer::FindAnchor(char *name) { Tag *pom; - pom = tags.first(); - while (pom != NULL) { + QListIterator tagsIterator(tags); + + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); if ((pom->tag_type == TAG_ANCHOR) && (strcmp(pom->tag_label, name) == 0)) { return(pom); } - pom=tags.takeFirst(); } return pom; } @@ -473,8 +477,10 @@ void QHTML::DrawList() map->fill(backgroundColor()); p.begin(map); - pom = analyzer->tags.first(); - while (pom != NULL) { + QListIterator tagsIterator(tags); + + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); switch(pom->tag_type) { case TAG_TEXT: p.setFont(*actual_font); @@ -576,7 +582,6 @@ void QHTML::DrawList() cy = cy + p.fontMetrics().height(); break; } - pom = analyzer->tags.takeFirst(); } p.end(); repaint(); diff --git a/src/lgconfig/lgconfig.cpp b/src/lgconfig/lgconfig.cpp index 2ef36ed..58872ca 100644 --- a/src/lgconfig/lgconfig.cpp +++ b/src/lgconfig/lgconfig.cpp @@ -86,12 +86,12 @@ QInstall::QInstall() bool QInstall::check_id(int id) { VLPEntry *pom; + QListIterator nodesIterator(Nodes); - pom = Nodes.first(); - while (pom != NULL) { + while (nodesIterator.hasNext()) { + pom = nodesIterator.next(); if (pom->ID == id) return FALSE; - pom = Nodes.takeFirst(); } return TRUE; } @@ -99,12 +99,12 @@ bool QInstall::check_id(int id) bool QInstall::check_addr(char *addr) { VLPEntry *pom; + QListIterator nodesIterator(Nodes); - pom = Nodes.first(); - while (pom != NULL) { + while (nodesIterator.hasNext()) { + pom = nodesIterator.next(); if (strcmp(pom->addr, addr) == 0) return FALSE; - pom = Nodes.takeFirst(); } return TRUE; } @@ -213,11 +213,13 @@ void QInstall::DelNode() if (nodelist->currentItem() >= 0) { strcpy(pom, nodelist->text(nodelist->currentItem()).toStdString().c_str()); - vpom = Nodes.first(); - while (vpom != NULL) { + + QListIterator nodesIterator(Nodes); + + while (nodesIterator.hasNext()) { + vpom = nodesIterator.next(); if (strcmp(pom, vpom->item) == 0) break; - vpom = Nodes.takeFirst(); } if (vpom != NULL) if (QMessageBox::question(this, "Delete VLP", "Are you sure?", "Yes", "No")) { @@ -268,8 +270,10 @@ void QInstall::SetOptions() if (dlg.exec()) { if (!Nodes.isEmpty()) { - pom = Nodes.first(); - while (pom != NULL) { + QListIterator nodesIterator(Nodes); + + while (nodesIterator.hasNext()) { + pom = nodesIterator.next(); j = Nodes.indexOf(pom); sprintf(pomstr, "%s.cfg", pom->addr); @@ -320,7 +324,6 @@ void QInstall::SetOptions() config_destroy(&cfg); pom = Nodes.at(j); - pom = Nodes.takeFirst(); } } } diff --git a/src/net/lognet.cpp b/src/net/lognet.cpp index 58e4813..4109c1d 100644 --- a/src/net/lognet.cpp +++ b/src/net/lognet.cpp @@ -377,16 +377,17 @@ void NETMOD::check_node(int n, int sc) m.msg_type = MSG_NET; m.param.pword[0] = NET_NODE_EXIST; - - pomlink = Links.first(); m.param.pword[1] = 0; - while (pomlink != NULL) { + + QListIterator linksIterator(Links); + + while (linksIterator.hasNext()) { + pomlink = linksIterator.next(); if (pomlink->node_number == n) { m.param.pword[1] = 1; strcpy(m.param.pstr, pomlink->addr); break; } - pomlink = Links.takeFirst(); } write(sc, &m, sizeof(MESSAGE)); } @@ -413,21 +414,22 @@ void NETMOD::get_internal() FD_SET(kernel_sock, &readset); nrset = kernel_sock; - pomlink = Interpreters.first(); - while (pomlink != NULL) { + QListIterator interpretersIterator(Interpreters); + while (interpretersIterator.hasNext()) { + pomlink = interpretersIterator.next(); FD_SET(pomlink->sock, &readset); if (nrset < pomlink->sock) { nrset = pomlink->sock; } - pomlink = Interpreters.takeFirst(); } if (select(nrset + 1, &readset, &writeset, 0, (struct timeval *)&tout) > 0) { /* Check request sockets */ - pomlink = Interpreters.first(); - while (pomlink != NULL) { + interpretersIterator.toFront(); + while (interpretersIterator.hasNext()) { + pomlink = interpretersIterator.next(); if (FD_ISSET(pomlink->sock, &readset)) { nr = read(pomlink->sock, &msg, sizeof(MESSAGE)); if (nr > 0) { @@ -451,7 +453,6 @@ void NETMOD::get_internal() } } } /* ISSET */ - pomlink=Interpreters.takeFirst(); } // while /* Check internal socket */ @@ -645,24 +646,24 @@ void NETMOD::remote_messages() FD_ZERO(&wset); max = 0; - pomlink = Links.first(); - while (pomlink != NULL) { + QListIterator linksIterator(Links); + while (linksIterator.hasNext()) { + pomlink = linksIterator.next(); if (pomlink->connected) { FD_SET(pomlink->sock, &rset); if (max < pomlink->sock){ max = pomlink->sock; } } - pomlink=Links.takeFirst(); } if (select(max + 1, &rset, &wset, 0, (struct timeval *)&tout) > 0) { - pomlink=Links.first(); - while (pomlink!=NULL) { + linksIterator.toFront(); + while (linksIterator.hasNext()) { + pomlink = linksIterator.next(); if (FD_ISSET(pomlink->sock,&rset)) { get_message(pomlink); } - pomlink=Links.takeFirst(); } } } @@ -685,23 +686,25 @@ void NETMOD::doitall() { if (max < kernel_sock) { max=kernel_sock; } - pomlink2 = Interpreters.first(); - while (pomlink2 != NULL) { + + QListIterator interpretersIterator(Interpreters); + while (interpretersIterator.hasNext()) { + pomlink2 = interpretersIterator.next(); FD_SET(pomlink2->sock, &rset); if (max < pomlink2->sock) { - max=pomlink2->sock; + max = pomlink2->sock; } - pomlink2 = Interpreters.takeFirst(); } - pomlink = Links.first(); - while (pomlink != NULL) { + + QListIterator linksIterator(Links); + while (linksIterator.hasNext()) { + pomlink = linksIterator.next(); if (pomlink->connected) { FD_SET(pomlink->sock, &rset); if (max < pomlink->sock) { max = pomlink->sock; } } - pomlink=Links.takeFirst(); } /* odczyt */ @@ -727,8 +730,9 @@ void NETMOD::doitall() { /* get internal message*/ /* Check request sockets */ - pomlink2 = Interpreters.first(); - while (pomlink2 != NULL) { + interpretersIterator.toFront(); + while (interpretersIterator.hasNext()) { + pomlink2 = interpretersIterator.next(); if (FD_ISSET(pomlink2->sock,&rset)) { nr = read(pomlink2->sock, &msg, sizeof(MESSAGE)); if (nr > 0) { @@ -752,7 +756,6 @@ void NETMOD::doitall() { } } }/* ISSET */ - pomlink2 = Interpreters.takeFirst(); }/* while */ /* Check internal socket */ @@ -818,11 +821,11 @@ void NETMOD::doitall() { /* get remote message*/ - pomlink=Links.first(); - while (pomlink != NULL) { + linksIterator.toFront(); + while (linksIterator.hasNext()) { + pomlink = linksIterator.next(); if (FD_ISSET(pomlink->sock, &rset)) get_message(pomlink); - pomlink=Links.takeFirst(); } } // select } @@ -855,11 +858,11 @@ void NETMOD::connect_seq(char *a) struct sockaddr_in svr; int j, on; - pom = Links.first(); - while (pom != NULL) { + QListIterator linksIterator(Links); + while (linksIterator.hasNext()) { + pom = linksIterator.next(); if (strcmp(pom->addr, a) == 0) return; - pom = Links.takeFirst(); } pom = new NETlink; strcpy(pom->addr, a); @@ -889,11 +892,12 @@ void NETMOD::check_links() int j = 1; struct sockaddr_in svr; NETlink *pomlink; + QListIterator linksIterator(Links); /* connect to all other nodes */ if (!all_connected) { - pomlink = Links.first(); - while (pomlink != NULL) { + while (linksIterator.hasNext()) { + pomlink = linksIterator.next(); if (!(pomlink->connected)) { bzero(&svr, sizeof(svr)); svr.sin_family = AF_INET; @@ -913,17 +917,16 @@ void NETMOD::check_links() sock_reopen(pomlink); } } /* not connected */ - pomlink = Links.takeFirst(); } /* while */ } /* if */ all_connected = TRUE; - pomlink = Links.first(); - while(pomlink != NULL) { + linksIterator.toFront(); + while(linksIterator.hasNext()) { + pomlink = linksIterator.next(); if (pomlink->connected == FALSE) { all_connected = FALSE; break; } - pomlink = Links.takeFirst(); } } @@ -977,10 +980,11 @@ void NETMOD::send_code_ack(NETlink *lnk) void NETMOD::send_to_all(MESSAGE *msg) { NETlink *pomlink; - pomlink = Links.first(); - while (pomlink != NULL) { + + QListIterator linksIterator(Links); + while (linksIterator.hasNext()) { + pomlink = linksIterator.next(); write(pomlink->sock, msg, sizeof(MESSAGE)); - pomlink = Links.takeFirst(); } } @@ -1004,10 +1008,11 @@ void NETMOD::exit_sequence() ::close(kernel_sock); ::close(listen_sock); unlink(kername); - pomlink = Links.first(); - while (pomlink != NULL) { + + QListIterator linksIterator(Links); + while (linksIterator.hasNext()) { + pomlink = linksIterator.next(); ::close(pomlink->sock); - pomlink = Links.takeFirst(); } exit(0); } @@ -1022,40 +1027,42 @@ void NETMOD::disconnect_seq() m.param.pword[0] = NET_DISCONNECT; m.param.pword[1] = MyNode; - p = Links.first(); - while(p != NULL) { + QListIterator linksIterator(Links); + while(linksIterator.hasNext()) { + p = linksIterator.next(); send_to_node(p, &m); - p=Links.takeFirst(); } - p = Links.first(); - while(p != NULL) { + + linksIterator.toFront(); + while(linksIterator.hasNext()) { + p = linksIterator.next(); ::close(p->sock); - p = Links.takeFirst(); } Links.clear(); } NETlink * NETMOD::findNETlink(int node) { - NETlink *pomlink; - pomlink = Links.first(); - while(pomlink != NULL) { + NETlink *pomlink = NULL; + QListIterator linksIterator(Links); + + while(linksIterator.hasNext()) { + pomlink = linksIterator.next(); + if (pomlink->node_number == node) return pomlink; - - pomlink = Links.takeFirst(); - } + } return pomlink; } INTlink * NETMOD::findINTlink(int id) { - INTlink *pomlink; - pomlink = Interpreters.first(); - while(pomlink != NULL) { + INTlink *pomlink = NULL; + QListIterator interpretersIterator(Interpreters); + while(interpretersIterator.hasNext()) { + pomlink = interpretersIterator.next(); if (pomlink->ID == id) return pomlink; - pomlink = Interpreters.takeFirst(); } return pomlink; } @@ -1206,8 +1213,10 @@ void NETMOD::conn_info(int sk) m.msg_type = MSG_NET; m.param.pword[0] = NET_INFO; strcpy(m.param.pstr, ""); - pom = Links.first(); - while (pom != NULL) { + + QListIterator linksIterator(Links); + while (linksIterator.hasNext()) { + pom = linksIterator.next(); sprintf(poms, "%d=%s;", pom->node_number, pom->addr); strcat(m.param.pstr, poms); k++; @@ -1216,7 +1225,6 @@ void NETMOD::conn_info(int sk) write(sk, &m, sizeof(MESSAGE)); k = 0; } - pom = Links.takeFirst(); } if (k > 0) { m.param.pword[1] = k; diff --git a/src/preproc/prep.cpp b/src/preproc/prep.cpp index dda3901..00b564e 100644 --- a/src/preproc/prep.cpp +++ b/src/preproc/prep.cpp @@ -31,41 +31,42 @@ IncFile *findTrueLine(int ln, int *trueline) int c1 = 0; // int c2 = 0; - if (inc.isEmpty()) { + QListIterator incFileIterator(inc); + if (!incFileIterator.hasNext()) { *trueline = ln; return NULL; - } + } pl.clear(); - pom = inc.first(); + pom = incFileIterator.next(); if (pom->start > ln) { *trueline = ln; return NULL; } - while ((pom != NULL) && (ln > pom->start)) { + while ((incFileIterator.hasNext()) && (ln > pom->start)) { if (ln < pom->start + pom->len) { *trueline = ln-pom->start; return pom; } pl.append(pom); - pom=inc.takeFirst(); + pom=incFileIterator.next(); } - if (pom != NULL) { - pom1 = pl.first(); + if (incFileIterator.hasNext()) { + QListIterator plIterator(pl); c1=0; - while (pom1 != NULL) { + while (plIterator.hasNext()) { + pom1 = plIterator.next(); c1 += pom1->len; - pom1 = pl.takeFirst(); } *trueline = ln - c1; return NULL; } else { - pom1 = inc.first(); + incFileIterator.toFront(); c1 = 0; - while (pom1 != NULL) { + while (incFileIterator.hasNext()) { + pom1 = incFileIterator.next(); c1 += pom1->len; - pom1=inc.takeFirst(); } *trueline = ln - c1; return NULL; -- 2.30.2