Changeset 903 for trunk/src/gmakenew/vmsify.c
- Timestamp:
- May 23, 2007, 7:31:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/vmsify.c
r503 r903 64 64 65 65 static int 66 copyto (char **to, c har **from, char upto, int as_dir)66 copyto (char **to, const char **from, char upto, int as_dir) 67 67 { 68 c har *s;68 const char *s; 69 69 70 70 s = strrchr (*from, '.'); … … 112 112 113 113 static char * 114 trnlog (c har *name)114 trnlog (const char *name) 115 115 { 116 116 int stat; … … 135 135 reslt[resltlen] = '\0'; 136 136 137 s = (char *)malloc (resltlen+1);137 s = malloc (resltlen+1); 138 138 if (s == 0) 139 139 return ""; … … 206 206 26 filenames with a single pair of '[' ']' are left unchanged 207 207 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. 209 210 */ 210 211 211 c har *212 vmsify (c har *name, int type)212 const char * 213 vmsify (const char *name, int type) 213 214 { 214 215 /* max 255 device … … 222 223 enum namestate nstate; 223 224 static char vmsname[MAXPATHLEN+1]; 224 char *fptr; 225 const char *fptr; 226 const char *t; 225 227 char *vptr; 226 char *s,*s1;227 228 int as_dir; 228 229 int count; … … 235 236 236 237 /* case 25a */ 237 238 s = strpbrk (name, "$:"); 239 if ( s!= 0)240 { 241 c har *s1;242 c har *s2;238 t = strpbrk (name, "$:"); 239 240 if (t != 0) 241 { 242 const char *s1; 243 const char *s2; 243 244 244 245 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 } 264 261 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 } 275 268 } 276 269 277 270 /* 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, '['); 284 277 if (s1 == 0) 285 278 { 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; 295 283 } 296 284 s1--; 297 285 if (*s1 != ']') 298 286 { 299 return name; /* not ][, keep unchanged */ 287 strcpy (vmsname, name); 288 return vmsname; /* not ][, keep unchanged */ 300 289 } 301 290 … … 306 295 /* s -> starting char 307 296 s1 -> ending ']' */ 308 309 297 do 310 298 { … … 330 318 331 319 } 332 333 320 else /* no [ in name */ 334 335 { 336 337 int state; 321 { 322 int state = 0; 338 323 int rooted = 1; /* flag if logical is rooted, else insert [000000] */ 339 340 state = 0;341 324 342 325 do 343 326 { 344 345 327 switch (state) 346 328 { … … 371 353 372 354 case 2: /* no '/' at start */ 373 s = strchr (fptr, '/'); 355 { 356 const char *s = strchr (fptr, '/'); 374 357 if (s == 0) /* no '/' (16) */ 375 358 { … … 402 385 } 403 386 break; 387 } 404 388 405 389 case 3: /* '//' at start */ 390 { 391 const char *s; 392 const char *s1; 393 char *vp; 406 394 while (*fptr == '/') /* collapse all '/' */ 407 395 fptr++; … … 413 401 if (s1 == 0) 414 402 { 415 return ""; /* FIXME, err getcwd */ 403 vmsname[0] = '\0'; 404 return vmsname; /* FIXME, err getcwd */ 416 405 } 417 406 s = strchr (s1, ':'); 418 407 if (s == 0) 419 408 { 420 return ""; /* FIXME, err no device */ 409 vmsname[0] = '\0'; 410 return vmsname; /* FIXME, err no device */ 421 411 } 422 412 strncpy (vptr, s1, s-s1+1); … … 445 435 *vptr = 0; 446 436 /* check logical for [000000] insertion */ 447 s1= trnlog (s);448 if (* s1 != 0)437 vp = trnlog (s); 438 if (*vp != '\0') 449 439 { /* found translation */ 450 char *s2;451 440 for (;;) /* loop over all nested logicals */ 452 441 { 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) 459 448 { 460 449 rooted = 0; 461 450 break; 462 451 } 463 s1 = s2;452 vp = vp2; 464 453 continue; /* next iteration */ 465 454 } 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 '.]' */ 469 458 { 470 459 if (strncmp (fptr, "000000", 6) != 0) … … 474 463 { 475 464 strcpy (vmsname, s1); 476 s= strchr (vmsname, ']');477 * s= '.';465 vp = strchr (vmsname, ']'); 466 *vp = '.'; 478 467 nstate = N_DOT; 479 vptr = s;468 vptr = vp; 480 469 } 481 470 } 482 471 break; 483 472 } 484 free ( s1);473 free (vp); 485 474 } 486 475 else … … 497 486 if (rooted == 0) 498 487 { 488 nstate = N_DOT; 499 489 strcpy (vptr, "[000000."); 500 490 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 */ 508 497 509 498 s = strchr (fptr, '/'); … … 532 521 else 533 522 if ((nstate == N_DOT) 534 && ( s1!= 0)523 && (vp != 0) 535 524 && (*(s+1) == 0)) 536 525 { 537 526 if (type == 2) 538 527 { 539 * s1= ']';528 *vp = ']'; 540 529 nstate = N_CLOSED; 541 530 } … … 543 532 state = 9; 544 533 break; 545 534 } 546 535 case 4: /* single '/' at start (9..15) */ 547 536 if (*fptr == 0) … … 565 554 break; 566 555 567 case 6: /* chars following '/' at start 10..15 */ 556 case 6: /* chars following '/' at start 10..15 */ 557 { 558 const char *s; 568 559 *vptr++ = '['; 569 560 nstate = N_OPEN; … … 596 587 } 597 588 break; 589 } 598 590 599 591 case 7: /* add '.dir' and exit */ … … 601 593 || (nstate == N_DOT)) 602 594 { 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 == ']') 607 599 { 608 600 break; 609 601 } 610 if (* s== '.')611 { 612 * s= ']';602 if (*vp == '.') 603 { 604 *vp = ']'; 613 605 break; 614 606 } 615 s--;607 vp--; 616 608 } 617 609 } … … 626 618 break; 627 619 628 case 9: /* 17..21, fptr -> 1st '/' + 1 */ 620 case 9: /* 17..21, fptr -> 1st '/' + 1 */ 621 { 622 const char *s; 629 623 if (*fptr == 0) 630 624 { … … 688 682 || (*(fptr+2) == 0)) ) 689 683 { 684 char *vp; 690 685 fptr += 2; 691 686 if (*fptr == '/') … … 700 695 type = 1; 701 696 vptr--; /* vptr -> '.' or ']' */ 702 s1= vptr;697 vp = vptr; 703 698 for (;;) 704 699 { 705 s1--;706 if (* s1== '.') /* one back */707 { 708 vptr = s1;700 vp--; 701 if (*vp == '.') /* one back */ 702 { 703 vptr = vp; 709 704 nstate = N_OPEN; 710 705 break; 711 706 } 712 if (* s1== '[') /* top level reached */707 if (*vp == '[') /* top level reached */ 713 708 { 714 709 if (*fptr == 0) 715 710 { 716 strcpy ( s1, "[000000]");717 vptr = s1+ 8;711 strcpy (vp, "[000000]"); 712 vptr = vp + 8; 718 713 nstate = N_CLOSED; 719 714 s = 0; … … 722 717 else 723 718 { 724 vptr = s1+1;719 vptr = vp+1; 725 720 nstate = N_OPEN; 726 721 break; … … 757 752 } 758 753 break; 754 } 759 755 760 756 case 10: /* 1,2 first is '.' */ … … 774 770 if (*fptr != '/') /* got ..xxx */ 775 771 { 776 return name; 772 strcpy (vmsname, name); 773 return vmsname; 777 774 } 778 775 do /* got ../ */ … … 792 789 } 793 790 { /* got '..' or '../' */ 791 char *vp; 794 792 char cwdbuf[MAXPATHLEN+1]; 795 793 796 s1= getcwd(cwdbuf, MAXPATHLEN);797 if ( s1== 0)794 vp = getcwd(cwdbuf, MAXPATHLEN); 795 if (vp == 0) 798 796 { 799 return ""; /* FIXME, err getcwd */ 797 vmsname[0] = '\0'; 798 return vmsname; /* FIXME, err getcwd */ 800 799 } 801 strcpy (vptr, s1);802 s= strchr (vptr, ']');803 if ( s!= 0)800 strcpy (vptr, vp); 801 vp = strchr (vptr, ']'); 802 if (vp != 0) 804 803 { 805 804 nstate = N_OPEN; 806 while ( s> vptr)805 while (vp > vptr) 807 806 { 808 s--;809 if (* s== '[')807 vp--; 808 if (*vp == '[') 810 809 { 811 s++;812 strcpy ( s, "000000]");810 vp++; 811 strcpy (vp, "000000]"); 813 812 state = -1; 814 813 break; 815 814 } 816 else if (* s== '.')815 else if (*vp == '.') 817 816 { 818 817 if (--count == 0) … … 820 819 if (*fptr == 0) /* had '..' or '../' */ 821 820 { 822 * s++ = ']';821 *vp++ = ']'; 823 822 state = -1; 824 823 } … … 827 826 state = 9; 828 827 } 829 * s = 0;828 *vp = '\0'; 830 829 break; 831 830 } … … 842 841 if (*fptr != '/') 843 842 { 844 return name; 843 strcpy (vmsname, name); 844 return vmsname; 845 845 } 846 846 while (*fptr == '/') … … 849 849 850 850 { 851 char *vp; 851 852 char cwdbuf[MAXPATHLEN+1]; 852 853 853 s1= getcwd(cwdbuf, MAXPATHLEN);854 if ( s1== 0)854 vp = getcwd(cwdbuf, MAXPATHLEN); 855 if (vp == 0) 855 856 { 856 return ""; /*FIXME, err getcwd */ 857 vmsname[0] = '\0'; 858 return vmsname; /*FIXME, err getcwd */ 857 859 } 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 } 878 880 break; 879 881 } … … 904 906 */ 905 907 906 c har *907 unixify (c har *name)908 const char * 909 unixify (const char *name) 908 910 { 909 911 static char piece[512]; 910 char *s, *p; 912 const char *s; 913 char *p; 911 914 912 915 if (strchr (name, '/') != 0) /* already in unix style */ 913 return name; 916 { 917 strcpy (piece, name); 918 return piece; 919 } 914 920 915 921 p = piece; … … 922 928 if (s != 0) 923 929 { 924 *s = 0;930 int l = s - name; 925 931 *p++ = '/'; 926 932 *p++ = '/'; 927 strcpy (p, name); 928 p += strlen (p); 929 *s = ':'; 933 strncpy (p, name, l); 934 p += l; 930 935 } 931 936
Note:
See TracChangeset
for help on using the changeset viewer.