Ignore:
Timestamp:
08/18/17 15:24:59 (7 years ago)
Author:
Maciej Komosinski
Message:

Unified property names of f1 and f4; improved docs; 3.141 -> M_PI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/f4_general.cpp

    r375 r671  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2017  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    2020f4_Props::f4_Props()
    2121{
    22         len = 1.0;
    23         curv = 0.0;
    24         mass = 1.0;
     22        length = 1.0;
     23        curvedness = 0.0;
     24        weight = 1.0;
    2525        friction = 0.4;
    26         ruch = 0.25; // bio
    27         assim = 0.25; // bio
    28         odpor = 0.25; // bio
    29         ingest = 0.25; // bio
     26        muscle_power = 0.25; // biol
     27        assimilation = 0.25; // biol
     28        stamina = 0.25; // biol
     29        ingestion = 0.25; // biol
    3030        twist = 0.0;
    31         energ = 1.0;
     31        energy = 1.0;
    3232        normalizeBiol4();
    3333}
     
    3535void f4_Props::normalizeBiol4()
    3636{
    37         // must sum to 1
    38         double sum = ruch + assim + odpor + ingest;
    39         if (0 == sum)
    40         {
    41                 ruch = assim = odpor = ingest = 0.25;
    42         }
    43         else {
    44                 ruch /= sum;
    45                 assim /= sum;
    46                 odpor /= sum;
    47                 ingest /= sum;
     37        // make them sum to 1
     38        double sum = muscle_power + assimilation + stamina + ingestion;
     39        if (sum == 0)
     40        {
     41                muscle_power = assimilation = stamina = ingestion = 0.25;
     42        }
     43        else
     44        {
     45                muscle_power /= sum;
     46                assimilation /= sum;
     47                stamina /= sum;
     48                ingestion /= sum;
    4849        }
    4950}
     
    5354        switch (modif)
    5455        {
    55         case 'L': len += (2.5 - len) * 0.3;
    56                 len = min(len, Model::getMaxJoint().d.x); break;
    57         case 'l': len += (0.3 - len) * 0.3;
    58                 len = max(len, Model::getMinJoint().d.x); break;
    59         case 'C': curv += (2.0 - curv) * 0.25;  break;
    60         case 'c': curv += (-2.0 - curv) * 0.25;  break;
     56        case 'L': length += (2.5 - length) * 0.3;
     57                length = min(length, Model::getMaxJoint().d.x); break;
     58        case 'l': length += (0.3 - length) * 0.3;
     59                length = max(length, Model::getMinJoint().d.x); break;
     60        case 'C': curvedness += (2.0 - curvedness) * 0.25;  break;
     61        case 'c': curvedness += (-2.0 - curvedness) * 0.25;  break;
    6162        case 'Q': twist += (1.58 - twist) * 0.3; break;
    6263        case 'q': twist += (-1.58 - twist) * 0.3; break;
    63         case 'A': assim += (1 - assim) * 0.8; normalizeBiol4(); break;
    64         case 'a': assim -= assim * 0.4;       normalizeBiol4(); break;
    65         case 'I': ingest += (1 - ingest) * 0.8;   normalizeBiol4(); break;
    66         case 'i': ingest -= ingest * 0.4;         normalizeBiol4(); break;
    67         case 'S': odpor += (1 - odpor) * 0.8; normalizeBiol4(); break;
    68         case 's': odpor -= odpor * 0.4;       normalizeBiol4(); break;
    69         case 'M': ruch += (1 - ruch) * 0.8;   normalizeBiol4(); break;
    70         case 'm': ruch -= ruch * 0.4;         normalizeBiol4(); break;
     64        case 'A': assimilation += (1 - assimilation) * 0.8; normalizeBiol4(); break;
     65        case 'a': assimilation -= assimilation * 0.4;       normalizeBiol4(); break;
     66        case 'I': ingestion += (1 - ingestion) * 0.8;   normalizeBiol4(); break;
     67        case 'i': ingestion -= ingestion * 0.4;         normalizeBiol4(); break;
     68        case 'S': stamina += (1 - stamina) * 0.8; normalizeBiol4(); break;
     69        case 's': stamina -= stamina * 0.4;       normalizeBiol4(); break;
     70        case 'M': muscle_power += (1 - muscle_power) * 0.8;   normalizeBiol4(); break;
     71        case 'm': muscle_power -= muscle_power * 0.4;         normalizeBiol4(); break;
    7172        case 'F': friction += (4 - friction) * 0.2; break;
    7273        case 'f': friction -= friction * 0.2;       break;
    73         case 'W': mass += (2.0 - mass) * 0.3;   break;
    74         case 'w': mass += (0.5 - mass) * 0.3;   break;
    75         case 'E': energ += (10.0 - energ) * 0.1; break;
    76         case 'e': energ -= energ * 0.1;          break;
     74        case 'W': weight += (2.0 - weight) * 0.3;   break;
     75        case 'w': weight += (0.5 - weight) * 0.3;   break;
     76        case 'E': energy += (10.0 - energy) * 0.1; break;
     77        case 'e': energy -= energy * 0.1;          break;
    7778        }
    7879}
     
    8081void f4_Props::adjust()
    8182{
    82         len = 0.5*len + 0.5*stdProps.len;
    83         curv = 0.66 * curv;
     83        length = 0.5*length + 0.5*stdProps.length;
     84        curvedness = 0.66 * curvedness;
    8485        twist = 0.66 * twist;
    8586}
     
    8889
    8990
    90 void rolling_dec(double * v) {
     91void rolling_dec(double * v)
     92{
    9193        *v -= 0.7853;  // 0.7853981  45 degrees
    9294}
    93 void rolling_inc(double * v) {
     95
     96void rolling_inc(double * v)
     97{
    9498        *v += 0.7853;  // 0.7853981  45 degrees
    9599}
     
    106110                if (stopchar == s[i])  // bumped into stopchar
    107111                        return i;
    108                 if (i < slen - 1)
    109                 { // s[i] is not the last char
     112                if (i < slen - 1) // s[i] is not the last char
     113                {
    110114                        if (s[i] == '(')
    111115                        {
     
    183187
    184188
    185 f4_Cell::f4_Cell(f4_Cells * nO, int nname, f4_node * ngeno, f4_node * ngcur,
    186         f4_Cell * ndad, int nangle, f4_Props newP)
     189f4_Cell::f4_Cell(f4_Cells * nO, int nname, f4_node * ngeno, f4_node * ngcur, f4_Cell * ndad, int nangle, f4_Props newP)
    187190{
    188191        name = nname;
     
    218221        {
    219222                // make sure it is a stick (and not a stick f4_Cell!)
    220                 if (T_STICK4 == ndad->type) {
     223                if (T_STICK4 == ndad->type)
     224                {
    221225                        //firstend = ndad->lastend;
    222226                        //OM = ndad->OM;
     
    279283
    280284                        // error: sticks cannot divide
    281                         if (T_STICK4 == type) {
     285                        if (T_STICK4 == type)
     286                        {
    282287                                // cannot fix
    283288                                org->setError(gcur->pos);
     
    286291
    287292                        // undiff divides
    288                         if (T_UNDIFF4 == type) {
     293                        if (T_UNDIFF4 == type)
     294                        {
    289295                                // commacount is set only when daughter turns into X
    290296                                // daughter cell
     
    292298                                f4_Props newP = P;
    293299                                newP.adjust();
    294                                 tmp = new f4_Cell(org, org->nc, genot, gcur->child2,
    295                                         this, commacount, newP);
     300                                tmp = new f4_Cell(org, org->nc, genot, gcur->child2, this, commacount, newP);
    296301                                tmp->repeat = repeat;
    297302                                repeat.null();
     
    310315                                // duplicate links
    311316                                f4_CellLink * ll;
    312                                 for (i = 0; i < nolink; i++) {
     317                                for (i = 0; i < nolink; i++)
     318                                {
    313319                                        ll = links[i];
    314320                                        tmp->addlink(ll->from, ll->w, ll->t);
     
    334340                                                gcur = repeat.first()->node->child;
    335341                                        }
    336                                         else {
     342                                        else
     343                                        {
    337344                                                // continue
    338345                                                gcur = repeat.first()->node->child2;
     
    341348                                        break;
    342349                                }
    343                                 else {
     350                                else
     351                                {
    344352                                        repeat.pop();
    345353                                }
    346354                        }
    347                         else {
     355                        else
     356                        {
    348357                                // error: still undiff
    349358                                if (T_UNDIFF4 == type)
     
    351360                                        // fix it: insert an 'X'
    352361                                        f4_node * insertnode = new f4_node('X', NULL, gcur->pos);
    353                                         if (org->setRepairInsert(gcur->pos, gcur, insertnode))
    354                                                 // not in repair mode, release
     362                                        if (org->setRepairInsert(gcur->pos, gcur, insertnode)) // not in repair mode, release                                           
    355363                                                delete insertnode;
    356364                                        return 1;
     
    383391                case 'r':  case 'R':
    384392                        // error: if neuron
    385                         if (T_NEURON4 == type) {
     393                        if (T_NEURON4 == type)
     394                        {
    386395                                // fix: delete it
    387396                                org->setRepairRemove(gcur->pos, gcur);
    388397                                return 1;  // stop
    389398                        }
    390                         switch (gcur->name) {
     399                        switch (gcur->name)
     400                        {
    391401                        case 'r':   rolling_dec(&rolling); break;
    392402                        case 'R':   rolling_inc(&rolling); break;
     
    406416                case 'e':  case 'E':
    407417                        // error: if neuron
    408                         if (T_NEURON4 == type) {
     418                        if (T_NEURON4 == type)
     419                        {
    409420                                // fix: delete it
    410421                                org->setRepairRemove(gcur->pos, gcur);
     
    418429                        // turn undiff. cell into a stick
    419430                        // error: already differentiated
    420                         if (T_UNDIFF4 != type) {
     431                        if (T_UNDIFF4 != type)
     432                        {
    421433                                // fix: delete this node
    422434                                org->setRepairRemove(gcur->pos, gcur);
     
    425437                        type = T_STICK4;
    426438                        // fix dad commacount and own anglepos
    427                         if (NULL != dadlink) {
     439                        if (NULL != dadlink)
     440                        {
    428441                                dadlink->commacount++;
    429442                                anglepos = dadlink->commacount;
     
    436449                        // turn undiff. cell into a neuron
    437450                        // error: already differentiated
    438                         if (T_UNDIFF4 != type) {
     451                        if (T_UNDIFF4 != type)
     452                        {
    439453                                // fix: delete this node
    440454                                org->setRepairRemove(gcur->pos, gcur);
     
    442456                        }
    443457                        // error: if no previous
    444                         if (NULL == dadlink) {
     458                        if (NULL == dadlink)
     459                        {
    445460                                // fix: delete it
    446461                                org->setRepairRemove(gcur->pos, gcur);
     
    461476                        if ('|' == gcur->name) j = 2; // bend
    462477                        // error: not a neuron (undiff)
    463                         if (T_UNDIFF4 == type) {
     478                        if (T_UNDIFF4 == type)
     479                        {
    464480                                // fix: delete it
    465481                                org->setRepairRemove(gcur->pos, gcur);
     
    467483                        }
    468484                        // error: not a neuron (stick)
    469                         if (T_NEURON4 != type) {
     485                        if (T_NEURON4 != type)
     486                        {
    470487                                // fix: delete it
    471488                                org->setRepairRemove(gcur->pos, gcur);
     
    473490                        }
    474491                        // error: already has control
    475                         if (ctrl != 0) {
     492                        if (ctrl != 0)
     493                        {
    476494                                // fix: delete it
    477495                                org->setRepairRemove(gcur->pos, gcur);
     
    486504                        // link to neuron
    487505                        // error: not a neuron
    488                         if (T_NEURON4 != type) {
     506                        if (T_NEURON4 != type)
     507                        {
    489508                                // fix: delete it
    490509                                org->setRepairRemove(gcur->pos, gcur);
     
    495514                        relfrom = gcur->l1;
    496515                        w = gcur->f1;
    497                         if (t > 0) {
     516                        if (t > 0)
     517                        {
    498518                                // * or G
    499519                                tneu = NULL;
     
    504524                                // find own index
    505525                                j = 0; k = 0;
    506                                 for (i = 0; i < org->nc; i++) {
     526                                for (i = 0; i < org->nc; i++)
     527                                {
    507528                                        if (org->C[i]->type == T_NEURON4) k++;
    508529                                        if (org->C[i] == this) { j = k - 1; break; }
     
    514535                                // find that neuron
    515536                                k = 0;
    516                                 for (i = 0; i < org->nc; i++) {
     537                                for (i = 0; i < org->nc; i++)
     538                                {
    517539                                        if (org->C[i]->type == T_NEURON4) k++;
    518540                                        if (j == (k - 1)) break;
     
    523545                        // add link
    524546                        // error: could not add link (too many?)
    525                         if (addlink(tneu, w, t)) {
     547                        if (addlink(tneu, w, t))
     548                        {
    526549                                // cannot fix
    527550                                org->setError(gcur->pos);
     
    535558                        active = 0;
    536559                        j = 0;
    537                         for (i = 0; i<org->nc; i++) {
     560                        for (i = 0; i < org->nc; i++)
     561                        {
    538562                                if (org->C[i]->active) j++;
    539563                        }
    540                         if (j>0)
     564                        if (j > 0)
    541565                                return 0;  // there is other active, halt, try again
    542566                        // no more actives, cannot add link, ignore, but treat not as an error
     
    547571                        // neuron parameter
    548572                        // error: not a neuron
    549                         if (T_NEURON4 != type) {
     573                        if (T_NEURON4 != type)
     574                        {
    550575                                // fix: delete it
    551576                                org->setRepairRemove(gcur->pos, gcur);
     
    553578                        }
    554579                        j = (int)gcur->l1;
    555                         switch ((char)gcur->i1) {
     580                        switch ((char)gcur->i1)
     581                        {
    556582                        case '!':
    557583                                if (j) force += (1.0 - force) * 0.2;
     
    604630{
    605631        //f4_OrientMat rot;
    606         int     i;
     632        int i;
    607633
    608634        if (recProcessedFlag)
     
    635661                        mz = 1;
    636662                }
    637                 else {
     663                else
     664                {
    638665                        //firstend = dadlink->lastend;
    639666                        f4_Props Pdad = dadlink->P;
     
    650677                        {
    651678                                // rotation due to curvedness
    652                                 zrot = Padj.curv;
    653                         }
    654                         else {
    655                                 zrot = Padj.curv +
    656                                         // SDK uses 3.141 instead of PI!
    657                                         (anglepos * 1.0 / (dadlink->commacount + 1) - 0.5) * 3.141 * 2.0;
     679                                zrot = Padj.curvedness;
     680                        }
     681                        else
     682                        {
     683                                zrot = Padj.curvedness + (anglepos * 1.0 / (dadlink->commacount + 1) - 0.5) * M_PI * 2.0;
    658684                        }
    659685
     
    722748
    723749        // create ancestor cell
    724         C[0] = new f4_Cell(this, 0, f4rootnode->child, f4rootnode->child,
    725                 NULL, 0, stdProps);
     750        C[0] = new f4_Cell(this, 0, f4rootnode->child, f4rootnode->child, NULL, 0, stdProps);
    726751        nc = 1;
    727752}
     
    747772        oldnc = nc;
    748773        ret = 0;
    749         for (i = 0; i<oldnc; i++) {
     774        for (i = 0; i < oldnc; i++)
     775        {
    750776                ret2 = C[i]->onestep();
    751                 if (ret2>0) {
     777                if (ret2 > 0)
     778                {
    752779                        // error
    753780                        C[i]->active = 0;  // stop
     
    776803        // fix neuron attachements
    777804        for (i = 0; i < nc; i++)
    778                 if (C[i]->type == T_NEURON4) {
    779                         while (T_NEURON4 == C[i]->dadlink->type) {
     805        {
     806                if (C[i]->type == T_NEURON4)
     807                {
     808                        while (T_NEURON4 == C[i]->dadlink->type)
     809                        {
    780810                                C[i]->dadlink = C[i]->dadlink->dadlink;
    781811                        }
    782812                }
     813        }
    783814
    784815        // there should be no undiff. cells
    785816        // make undifferentiated cells sticks
    786817        for (i = 0; i < nc; i++)
    787                 if (C[i]->type == T_UNDIFF4) {
     818        {
     819                if (C[i]->type == T_UNDIFF4)
     820                {
    788821                        C[i]->type = T_STICK4;
    789822                        //seterror();
    790823                }
     824        }
    791825
    792826        // recursive adjust
     
    806840void f4_Cells::addCell(f4_Cell * newcell)
    807841{
    808         if (nc >= MAX4CELLS - 1) {
     842        if (nc >= MAX4CELLS - 1)
     843        {
    809844                delete newcell;
    810845                return;
     
    823858void f4_Cells::setRepairRemove(int nerrpos, f4_node * rem)
    824859{
    825         if (!repair) {
     860        if (!repair)
     861        {
    826862                // not in repair mode, treat as repairable error
    827863                error = GENOPER_REPAIR;
    828864                errorpos = nerrpos;
    829865        }
    830         else {
     866        else
     867        {
    831868                error = GENOPER_REPAIR;
    832869                errorpos = nerrpos;
     
    837874int f4_Cells::setRepairInsert(int nerrpos, f4_node * parent, f4_node * insert)
    838875{
    839         if (!repair) {
     876        if (!repair)
     877        {
    840878                // not in repair mode, treat as repairable error
    841879                error = GENOPER_REPAIR;
     
    843881                return -1;
    844882        }
    845         else {
     883        else
     884        {
    846885                error = GENOPER_REPAIR;
    847886                errorpos = nerrpos;
     
    863902        if (NULL == g2)
    864903                return;
    865         if (g2 == repair_remove) {
     904        if (g2 == repair_remove)
     905        {
    866906                f4_node * oldgeno;
    867907                geno->removeChild(g2);
    868                 if (g2->child) {
     908                if (g2->child)
     909                {
    869910                        // add g2->child as child to geno
    870911                        if (1 == whichchild) geno->child = g2->child;
     
    880921                return;
    881922        }
    882         if (g2 == repair_parent) {
     923        if (g2 == repair_parent)
     924        {
    883925                geno->removeChild(g2);
    884926                geno->addChild(repair_insert);
     
    921963        // adjust length, curvedness, etc.
    922964        tmpcel->P.adjust();
    923         while (tmpcel->P.len > thisti->P.len)
     965        while (tmpcel->P.length > thisti->P.length)
    924966        {
    925967                tmpcel->P.executeModifier('l');
    926968                out += "l";
    927969        }
    928         while (tmpcel->P.len < thisti->P.len)
     970        while (tmpcel->P.length < thisti->P.length)
    929971        {
    930972                tmpcel->P.executeModifier('L');
    931973                out += "L";
    932974        }
    933         while (tmpcel->P.curv > thisti->P.curv)
     975        while (tmpcel->P.curvedness > thisti->P.curvedness)
    934976        {
    935977                tmpcel->P.executeModifier('c');
    936978                out += "c";
    937979        }
    938         while (tmpcel->P.curv < thisti->P.curv)
     980        while (tmpcel->P.curvedness < thisti->P.curvedness)
    939981        {
    940982                tmpcel->P.executeModifier('C');
    941983                out += "C";
    942984        }
    943         while (thisti->rolling > 0.0f) {
     985        while (thisti->rolling > 0.0f)
     986        {
    944987                rolling_dec(&(thisti->rolling));
    945988                out += "R";
    946989        }
    947         while (thisti->rolling < 0.0f) {
     990        while (thisti->rolling < 0.0f)
     991        {
    948992                rolling_inc(&(thisti->rolling));
    949993                out += "r";
     
    955999        // neurons attached to it
    9561000        for (i = 0; i < nc; i++)
    957                 if (C[i]->type == T_NEURON4) {
    958                         if (C[i]->dadlink == thisti) {
     1001        {
     1002                if (C[i]->type == T_NEURON4)
     1003                {
     1004                        if (C[i]->dadlink == thisti)
     1005                        {
    9591006                                thneu = C[i];
    9601007                                out += "[";
     
    9741021                                                if (4 == thneu->links[j]->t) out += "S";
    9751022                                        }
    976                                         else {
     1023                                        else
     1024                                        {
    9771025                                                sprintf(buf, "%d", thneu->links[j]->from->name - thneu->name);
    9781026                                                out += buf;
    9791027                                        }
    9801028                                        out += ":";
    981                                         // weight
     1029                                        // connection weight
    9821030                                        sprintf(buf, "%g", thneu->links[j]->w);
    9831031                                        out += buf;
     
    9861034                        }
    9871035                }
     1036        }
    9881037
    9891038        // sticks connected to it
     
    9931042        ccount = 1;
    9941043        for (i = 0; i < nc; i++)
     1044        {
    9951045                if (C[i]->type == T_STICK4)
    996                         if (C[i]->dadlink == thisti) {
    997                                 while (ccount < (C[i])->anglepos) {
     1046                {
     1047                        if (C[i]->dadlink == thisti)
     1048                        {
     1049                                while (ccount < (C[i])->anglepos)
     1050                                {
    9981051                                        ccount++;
    9991052                                        out += ",";
     
    10011054                                toF1GenoRec(i, out);
    10021055                        }
    1003         while (ccount < thisti->commacount) {
     1056                }
     1057        }
     1058
     1059        while (ccount < thisti->commacount)
     1060        {
    10041061                ccount++;
    10051062                out += ",";
     
    10121069
    10131070
    1014 // to organize a f4 genotype in a tree structure
     1071// to organize an f4 genotype in a tree structure
    10151072
    10161073f4_node::f4_node()
     
    10431100int f4_node::addChild(f4_node * nchi)
    10441101{
    1045         if (NULL == child) {
     1102        if (NULL == child)
     1103        {
    10461104                child = nchi;
    10471105                return 0;
    10481106        }
    1049         if (NULL == child2) {
     1107        if (NULL == child2)
     1108        {
    10501109                child2 = nchi;
    10511110                return 0;
     
    10561115int f4_node::removeChild(f4_node * nchi)
    10571116{
    1058         if (nchi == child2) {
     1117        if (nchi == child2)
     1118        {
    10591119                child2 = NULL;
    10601120                return 0;
    10611121        }
    1062         if (nchi == child) {
     1122        if (nchi == child)
     1123        {
    10631124                child = NULL;
    10641125                return 0;
     
    10691130int f4_node::childCount()
    10701131{
    1071         if (NULL != child) {
     1132        if (NULL != child)
     1133        {
    10721134                if (NULL != child2) return 2;
    10731135                else return 1;
    10741136        }
    1075         else {
     1137        else
     1138        {
    10761139                if (NULL != child2) return 1;
    10771140                else return 0;
     
    10921155        if (0 == n) return this;
    10931156        n--;
    1094         if (NULL != child) {
     1157        if (NULL != child)
     1158        {
    10951159                n1 = child->count();
    10961160                if (n < n1) return child->ordNode(n);
    10971161                n -= n1;
    10981162        }
    1099         if (NULL != child2) {
     1163        if (NULL != child2)
     1164        {
    11001165                n1 = child2->count();
    11011166                if (n < n1) return child2->ordNode(n);
     
    11191184        f4_node * nod = NULL;
    11201185        maxlim = count();
    1121         for (i = 0; i < maxlim; i++) {
     1186        for (i = 0; i < maxlim; i++)
     1187        {
    11221188                nod = randomNode();
    11231189                n = nod->count();
     
    11351201        {
    11361202                out += "#";
    1137                 if (i1 != 1) {
     1203                if (i1 != 1)
     1204                {
    11381205                        sprintf(buf2, "%d", i1);
    11391206                        out += buf2;
     
    11421209        else {
    11431210                // special case: neuron link
    1144                 if ('[' == name) {
     1211                if ('[' == name)
     1212                {
    11451213                        out += "[";
    1146                         if (i1 > 0) {
     1214                        if (i1 > 0)
     1215                        {
    11471216                                // sensor input
    11481217                                if (1 == i1) out += "*";
     
    11511220                                if (4 == i1) out += "S";
    11521221                        }
    1153                         else {
     1222                        else
     1223                        {
    11541224                                sprintf(buf2, "%ld", l1);
    11551225                                out += buf2;
     
    11581228                        out += buf2;
    11591229                }
    1160                 else if (':' == name) {
     1230                else if (':' == name)
     1231                {
    11611232                        sprintf(buf2, ":%c%c:", l1 ? '+' : '-', (char)i1);
    11621233                        out += buf2;
    11631234                }
    1164                 else {
     1235                else
     1236                {
    11651237                        buf2[0] = name;
    11661238                        buf2[1] = 0;
     
    11941266        // copy back to string
    11951267        // if new is longer, reallocate buf
    1196         if (len + 1 > strlen(buf)) {
     1268        if (len + 1 > strlen(buf))
     1269        {
    11971270                buf = (char*)realloc(buf, len + 1);
    11981271        }
     
    12071280        copy->child = NULL;
    12081281        copy->child2 = NULL;
    1209         if (NULL != child) {
     1282        if (NULL != child)
     1283        {
    12101284                copy->child = child->duplicate();
    12111285                copy->child->parent = copy;
    12121286        }
    1213         if (NULL != child2) {
     1287        if (NULL != child2)
     1288        {
    12141289                copy->child2 = child2->duplicate();
    12151290                copy->child2->parent = copy;
     
    12411316        par = parent;
    12421317        if (gpos >= strlen(genot)) return 1;
    1243         while (gpos < strlen(genot)) {
     1318        while (gpos < strlen(genot))
     1319        {
    12441320                //DB( printf(" processing '%c' %d %s\n", genot[gpos], gpos, genot); )
    1245                 switch (genot[gpos]) {
     1321                switch (genot[gpos])
     1322                {
    12461323                case '<':
    12471324                        // cell division!
     
    12551332                        res = f4_processrec(genot, gpos + 1, par);
    12561333                        if (res) return res;
    1257                         if (gpos + j + 2 < strlen(genot)) {
     1334                        if (gpos + j + 2 < strlen(genot))
     1335                        {
    12581336                                res = f4_processrec(genot, gpos + j + 2, par);
    12591337                                if (res) return res;
    12601338                        }
    1261                         else {  // ran out
     1339                        else // ran out
     1340                        {
    12621341                                node1 = new f4_node('>', par, strlen(genot) - 1);
    12631342                                par = node1;
     
    12871366                        res = f4_processrec(genot, gpos, node1);
    12881367                        if (res) return res;
    1289                         if (oldpos + j + 2 < strlen(genot)) {
     1368                        if (oldpos + j + 2 < strlen(genot))
     1369                        {
    12901370                                res = f4_processrec(genot, oldpos + j + 2, node1);
    12911371                                if (res) return res;
    12921372                        }
    1293                         else {  // ran out
     1373                        else // ran out
     1374                        {
    12941375                                node1 = new f4_node('>', par, strlen(genot) - 1);
    12951376                        }
     
    13441425                        else if ('-' == tc1) j = 0;
    13451426                        else return gpos + 1 + 1;
    1346                         switch (tc2) {
     1427                        switch (tc2)
     1428                        {
    13471429                        case '!':  case '=':  case '/':  break;
    13481430                        default:
     
    13771459        // should end with a '>'
    13781460        if (par)
    1379                 if ('>' != par->name) {
     1461        {
     1462                if ('>' != par->name)
     1463                {
    13801464                        node1 = new f4_node('>', par, strlen(genot) - 1);
    13811465                        par = node1;
    13821466                }
     1467        }
     1468
    13831469        return 0;  // OK
    13841470}
     
    13941480        //DB( printf("test f4  "); )
    13951481        DB(
    1396                 if (root->child) {
    1397                         char * buf = (char*)malloc(300);
    1398                         DB(printf("(%d) ", root->child->count());)
    1399                                 buf[0] = 0;
    1400                         root->child->sprintAdj(buf);
    1401                         DB(printf("%s\n", buf);)
    1402                                 free(buf);
     1482                if (root->child)
     1483                {
     1484                char * buf = (char*)malloc(300);
     1485                DB(printf("(%d) ", root->child->count());)
     1486                        buf[0] = 0;
     1487                root->child->sprintAdj(buf);
     1488                DB(printf("%s\n", buf);)
     1489                        free(buf);
    14031490                }
    14041491        )
Note: See TracChangeset for help on using the changeset viewer.