Ignore:
Timestamp:
May 23, 2007, 7:31:19 AM (18 years ago)
Author:
bird
Message:

Merged with the 2007-05-23 CVS. Added rsort and fixed a couple of windows build issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmakenew/vmsify.c

    r503 r903  
    6464
    6565static int
    66 copyto (char **to, char **from, char upto, int as_dir)
     66copyto (char **to, const char **from, char upto, int as_dir)
    6767{
    68   char *s;
     68  const char *s;
    6969
    7070  s = strrchr (*from, '.');
     
    112112
    113113static char *
    114 trnlog (char *name)
     114trnlog (const char *name)
    115115{
    116116  int stat;
     
    135135  reslt[resltlen] = '\0';
    136136
    137   s = (char *)malloc (resltlen+1);
     137  s = malloc (resltlen+1);
    138138  if (s == 0)
    139139    return "";
     
    20620626  filenames with a single pair of '[' ']' are left unchanged
    207207
    208   the input string is not written to
     208  The input string is not written to.  The result is also const because
     209  it's a static buffer; we don't want to change it.
    209210*/
    210211
    211 char *
    212 vmsify (char *name, int type)
     212const char *
     213vmsify (const char *name, int type)
    213214{
    214215/* max 255 device
     
    222223  enum namestate nstate;
    223224  static char vmsname[MAXPATHLEN+1];
    224   char *fptr;
     225  const char *fptr;
     226  const char *t;
    225227  char *vptr;
    226   char *s,*s1;
    227228  int as_dir;
    228229  int count;
     
    235236
    236237  /* case 25a */
    237 
    238   s = strpbrk (name, "$:");
    239   if (s != 0)
    240     {
    241       char *s1;
    242       char *s2;
     238  t = strpbrk (name, "$:");
     239
     240  if (t != 0)
     241    {
     242      const char *s1;
     243      const char *s2;
    243244
    244245      if (type == 1)
    245         {
    246           s1 = strchr (s+1, '[');
    247           s2 = strchr (s+1, ']');
    248         }
    249 
    250       if (*s == '$')
    251         {
    252           if (strchr (name, '/') == 0)
    253             {
    254               if ((type == 1) && (s1 != 0) && (s2 == 0))
    255                 {
    256                   strcpy (vmsname, name);
    257                   strcat (vmsname, "]");
    258                   return vmsname;
    259                 }
    260               else
    261                 return name;
    262             }
    263         }
     246        {
     247          s1 = strchr (t+1, '[');
     248          s2 = strchr (t+1, ']');
     249        }
     250
     251      if (*t == '$')
     252        {
     253          if (strchr (name, '/') == 0)
     254            {
     255              strcpy (vmsname, name);
     256              if ((type == 1) && (s1 != 0) && (s2 == 0))
     257                strcat (vmsname, "]");
     258              return vmsname;
     259            }
     260        }
    264261      else
    265         {
    266           if ((type == 1) && (s1 != 0) && (s2 == 0))
    267             {
    268               strcpy (vmsname, name);
    269               strcat (vmsname, "]");
    270               return vmsname;
    271             }
    272           else
    273             return name;
    274         }
     262        {
     263          strcpy (vmsname, name);
     264          if ((type == 1) && (s1 != 0) && (s2 == 0))
     265            strcat (vmsname, "]");
     266          return vmsname;
     267        }
    275268    }
    276269
    277270  /* case 26 */
    278 
    279   s = strchr (name, '[');
    280 
    281   if (s != 0)
    282     {
    283       s1 = strchr (s+1, '[');
     271  t = strchr (name, '[');
     272
     273  if (t != 0)
     274    {
     275      const char *s;
     276      const char *s1 = strchr (t+1, '[');
    284277      if (s1 == 0)
    285278        {
    286           if ((type == 1)
    287                && (strchr (s+1, ']') == 0))
    288             {
    289               strcpy (vmsname, name);
    290               strcat (vmsname, "]");
    291               return vmsname;
    292             }
    293           else
    294             return name;                        /* single [, keep unchanged */
     279          strcpy (vmsname, name);
     280          if ((type == 1) && (strchr (t+1, ']') == 0))
     281            strcat (vmsname, "]");
     282          return vmsname;
    295283        }
    296284      s1--;
    297285      if (*s1 != ']')
    298286        {
    299           return name;                  /* not ][, keep unchanged */
     287          strcpy (vmsname, name);
     288          return vmsname;               /* not ][, keep unchanged */
    300289        }
    301290
     
    306295      /* s  -> starting char
    307296         s1 -> ending ']'  */
    308 
    309297      do
    310298        {
     
    330318
    331319    }
    332 
    333320  else          /* no [ in name */
    334 
    335     {
    336 
    337       int state;
     321    {
     322      int state = 0;
    338323      int rooted = 1;   /* flag if logical is rooted, else insert [000000] */
    339 
    340       state = 0;
    341324
    342325      do
    343326        {
    344 
    345327      switch (state)
    346328        {
     
    371353
    372354          case 2:                               /* no '/' at start */
    373             s = strchr (fptr, '/');
     355            {
     356            const char *s = strchr (fptr, '/');
    374357            if (s == 0)                 /* no '/' (16) */
    375358              {
     
    402385              }
    403386            break;
     387            }
    404388
    405389          case 3:                               /* '//' at start */
     390            {
     391            const char *s;
     392            const char *s1;
     393            char *vp;
    406394            while (*fptr == '/')        /* collapse all '/' */
    407395              fptr++;
     
    413401                if (s1 == 0)
    414402                  {
    415                     return "";          /* FIXME, err getcwd */
     403                    vmsname[0] = '\0';
     404                    return vmsname;     /* FIXME, err getcwd */
    416405                  }
    417406                s = strchr (s1, ':');
    418407                if (s == 0)
    419408                  {
    420                     return "";          /* FIXME, err no device */
     409                    vmsname[0] = '\0';
     410                    return vmsname;     /* FIXME, err no device */
    421411                  }
    422412                strncpy (vptr, s1, s-s1+1);
     
    445435            *vptr = 0;
    446436                                /* check logical for [000000] insertion */
    447             s1 = trnlog (s);
    448             if (*s1 != 0)
     437            vp = trnlog (s);
     438            if (*vp != '\0')
    449439              {                 /* found translation */
    450                 char *s2;
    451440                for (;;)        /* loop over all nested logicals */
    452441                  {
    453                     s2 = s1 + strlen (s1) - 1;
    454                     if (*s2 == ':')     /* translation ends in ':' */
    455                       {
    456                         s2 = trnlog (s1);
    457                         free (s1);
    458                         if (*s2 == 0)
     442                    char *vp2 = vp + strlen (vp) - 1;
     443                    if (*vp2 == ':')    /* translation ends in ':' */
     444                      {
     445                        vp2 = trnlog (vp);
     446                        free (vp);
     447                        if (*vp2 == 0)
    459448                          {
    460449                            rooted = 0;
    461450                            break;
    462451                          }
    463                         s1 = s2;
     452                        vp = vp2;
    464453                        continue;       /* next iteration */
    465454                      }
    466                     if (*s2 == ']')     /* translation ends in ']' */
    467                       {
    468                         if (*(s2-1) == '.')     /* ends in '.]' */
     455                    if (*vp2 == ']')    /* translation ends in ']' */
     456                      {
     457                        if (*(vp2-1) == '.')    /* ends in '.]' */
    469458                          {
    470459                            if (strncmp (fptr, "000000", 6) != 0)
     
    474463                          {
    475464                            strcpy (vmsname, s1);
    476                             s = strchr (vmsname, ']');
    477                             *s = '.';
     465                            vp = strchr (vmsname, ']');
     466                            *vp = '.';
    478467                            nstate = N_DOT;
    479                             vptr = s;
     468                            vptr = vp;
    480469                          }
    481470                      }
    482471                    break;
    483472                  }
    484                 free (s1);
     473                free (vp);
    485474              }
    486475            else
     
    497486            if (rooted == 0)
    498487              {
     488                nstate = N_DOT;
    499489                strcpy (vptr, "[000000.");
    500490                vptr += 8;
    501                 s1 = vptr-1;
    502                 nstate = N_DOT;
    503               }
    504             else
    505               s1 = 0;
    506 
    507         /* s1-> '.' after 000000 or NULL */
     491                vp = vptr-1;
     492              }
     493            else
     494              vp = 0;
     495
     496            /* vp-> '.' after 000000 or NULL */
    508497
    509498            s = strchr (fptr, '/');
     
    532521            else
    533522              if ((nstate == N_DOT)
    534                  && (s1 != 0)
     523                 && (vp != 0)
    535524                 && (*(s+1) == 0))
    536525                {
    537526                  if (type == 2)
    538527                    {
    539                       *s1 = ']';
     528                      *vp = ']';
    540529                      nstate = N_CLOSED;
    541530                    }
     
    543532            state = 9;
    544533            break;
    545 
     534            }
    546535          case 4:                               /* single '/' at start (9..15) */
    547536            if (*fptr == 0)
     
    565554            break;
    566555
    567           case 6:                               /* chars following '/' at start 10..15 */
     556          case 6:               /* chars following '/' at start 10..15 */
     557            {
     558            const char *s;
    568559            *vptr++ = '[';
    569560            nstate = N_OPEN;
     
    596587              }
    597588            break;
     589            }
    598590
    599591          case 7:                               /* add '.dir' and exit */
     
    601593                || (nstate == N_DOT))
    602594              {
    603                 s = vptr-1;
    604                 while (s > vmsname)
    605                   {
    606                     if (*s == ']')
     595                char *vp = vptr-1;
     596                while (vp > vmsname)
     597                  {
     598                    if (*vp == ']')
    607599                      {
    608600                        break;
    609601                      }
    610                     if (*s == '.')
    611                       {
    612                         *s = ']';
     602                    if (*vp == '.')
     603                      {
     604                        *vp = ']';
    613605                        break;
    614606                      }
    615                     s--;
     607                    vp--;
    616608                  }
    617609              }
     
    626618            break;
    627619
    628           case 9:                               /* 17..21, fptr -> 1st '/' + 1 */
     620          case 9:                       /* 17..21, fptr -> 1st '/' + 1 */
     621            {
     622            const char *s;
    629623            if (*fptr == 0)
    630624              {
     
    688682                    || (*(fptr+2) == 0)) )
    689683              {
     684                char *vp;
    690685                fptr += 2;
    691686                if (*fptr == '/')
     
    700695                  type = 1;
    701696                vptr--;                         /* vptr -> '.' or ']' */
    702                 s1 = vptr;
     697                vp = vptr;
    703698                for (;;)
    704699                  {
    705                     s1--;
    706                     if (*s1 == '.')             /* one back */
    707                       {
    708                         vptr = s1;
     700                    vp--;
     701                    if (*vp == '.')             /* one back */
     702                      {
     703                        vptr = vp;
    709704                        nstate = N_OPEN;
    710705                        break;
    711706                      }
    712                     if (*s1 == '[')             /* top level reached */
     707                    if (*vp == '[')             /* top level reached */
    713708                      {
    714709                        if (*fptr == 0)
    715710                          {
    716                             strcpy (s1, "[000000]");
    717                             vptr = s1 + 8;
     711                            strcpy (vp, "[000000]");
     712                            vptr = vp + 8;
    718713                            nstate = N_CLOSED;
    719714                            s = 0;
     
    722717                        else
    723718                          {
    724                             vptr = s1+1;
     719                            vptr = vp+1;
    725720                            nstate = N_OPEN;
    726721                            break;
     
    757752              }
    758753            break;
     754            }
    759755
    760756          case 10:                              /* 1,2 first is '.' */
     
    774770                if (*fptr != '/')               /* got ..xxx */
    775771                  {
    776                     return name;
     772                    strcpy (vmsname, name);
     773                    return vmsname;
    777774                  }
    778775                do                              /* got ../ */
     
    792789              }
    793790            {                                   /* got '..' or '../' */
     791              char *vp;
    794792              char cwdbuf[MAXPATHLEN+1];
    795793
    796               s1 = getcwd(cwdbuf, MAXPATHLEN);
    797               if (s1 == 0)
     794              vp = getcwd(cwdbuf, MAXPATHLEN);
     795              if (vp == 0)
    798796                {
    799                   return "";        /* FIXME, err getcwd */
     797                  vmsname[0] = '\0';
     798                  return vmsname;    /* FIXME, err getcwd */
    800799                }
    801               strcpy (vptr, s1);
    802               s = strchr (vptr, ']');
    803               if (s != 0)
     800              strcpy (vptr, vp);
     801              vp = strchr (vptr, ']');
     802              if (vp != 0)
    804803                {
    805804                  nstate = N_OPEN;
    806                   while (s > vptr)
     805                  while (vp > vptr)
    807806                    {
    808                       s--;
    809                       if (*s == '[')
     807                      vp--;
     808                      if (*vp == '[')
    810809                        {
    811                           s++;
    812                           strcpy (s, "000000]");
     810                          vp++;
     811                          strcpy (vp, "000000]");
    813812                          state = -1;
    814813                          break;
    815814                        }
    816                       else if (*s == '.')
     815                      else if (*vp == '.')
    817816                        {
    818817                          if (--count == 0)
     
    820819                              if (*fptr == 0)   /* had '..' or '../' */
    821820                                {
    822                                   *s++ = ']';
     821                                  *vp++ = ']';
    823822                                  state = -1;
    824823                                }
     
    827826                                  state = 9;
    828827                                }
    829                               *s = 0;
     828                              *vp = '\0';
    830829                              break;
    831830                            }
     
    842841                if (*fptr != '/')
    843842                  {
    844                     return name;
     843                    strcpy (vmsname, name);
     844                    return vmsname;
    845845                  }
    846846                while (*fptr == '/')
     
    849849
    850850            {
     851              char *vp;
    851852              char cwdbuf[MAXPATHLEN+1];
    852853
    853               s1 = getcwd(cwdbuf, MAXPATHLEN);
    854               if (s1 == 0)
     854              vp = getcwd(cwdbuf, MAXPATHLEN);
     855              if (vp == 0)
    855856                {
    856                   return "";        /*FIXME, err getcwd */
     857                  vmsname[0] = '\0';
     858                  return vmsname;    /*FIXME, err getcwd */
    857859                }
    858               strcpy (vptr, s1);
    859               if (*fptr == 0)
    860                 {
    861                   state = -1;
    862                   break;
    863                 }
    864               else
    865                 {
    866                   s = strchr (vptr, ']');
    867                   if (s == 0)
    868                     {
    869                       state = -1;
    870                       break;
    871                     }
    872                   *s = 0;
    873                   nstate = N_OPEN;
    874                   vptr += strlen (vptr);
    875                   state = 9;
    876                 }
    877             }
     860              strcpy (vptr, vp);
     861            }
     862            if (*fptr == 0)
     863              {
     864                state = -1;
     865                break;
     866              }
     867            else
     868              {
     869                char *vp = strchr (vptr, ']');
     870                if (vp == 0)
     871                  {
     872                    state = -1;
     873                    break;
     874                  }
     875                *vp = '\0';
     876                nstate = N_OPEN;
     877                vptr += strlen (vptr);
     878                state = 9;
     879              }
    878880            break;
    879881        }
     
    904906*/
    905907
    906 char *
    907 unixify (char *name)
     908const char *
     909unixify (const char *name)
    908910{
    909911  static char piece[512];
    910   char *s, *p;
     912  const char *s;
     913  char *p;
    911914
    912915  if (strchr (name, '/') != 0)          /* already in unix style */
    913     return name;
     916    {
     917      strcpy (piece, name);
     918      return piece;
     919    }
    914920
    915921  p = piece;
     
    922928  if (s != 0)
    923929    {
    924       *s = 0;
     930      int l = s - name;
    925931      *p++ = '/';
    926932      *p++ = '/';
    927       strcpy (p, name);
    928       p += strlen (p);
    929       *s = ':';
     933      strncpy (p, name, l);
     934      p += l;
    930935    }
    931936
Note: See TracChangeset for help on using the changeset viewer.