Home » Archimedes archive » Acorn User » AU 1995-07.adf » !Internet_StarterPak » !Newsbase/Support/taylor/csrc/c/upath
!Newsbase/Support/taylor/csrc/c/upath
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1995-07.adf » !Internet_StarterPak |
Filename: | !Newsbase/Support/taylor/csrc/c/upath |
Read OK: | ✔ |
File size: | 0874 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* upath.c - convert a "poor mans unix path" to a riscos path. * designed for interaction with Taylor UUCP's UucpFS$* * Variables. * * Author: Gunnar Z�tl * Date: 14-Sep-1994 * Last Modified: 14-Sep-1994 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "upath.h" /* we convert a path in "poor mans unix path" notation. * it is quite simple: * - if there's a leading slash, we extract the head of the path * until the 2nd slash and see wether a variable UucpFS$<prefix> * exists. If so, we use that as a root for the remaining path, * otherwise we look for UucpFS$/ and use that as a prefix for * the whole path. If UucpFS$/ is undefined, we try "$" instead. * - Now we traverse the whole path, converting "/" to ".". If there * still is a leading slash, we remove it. */ char *upath(char *upath) { static char rpath[UPLEN]; char buffer[UPLEN]; char *q, *s; *rpath = 0; s = NULL; if (*upath == '/') { q = strchr(upath + 1, '/'); if (q != NULL) { *q = 0; strcpy(buffer, UUCPFSP); strcat(buffer, upath); *q = '/'; s = getenv(buffer); } if (s != NULL) { if (*s == '/') strcpy(rpath, s + 1); else strcpy(rpath, s); strcat(rpath, q); } else { strcpy(buffer, UUCPFSP); strcat(buffer, "/"); s = getenv(buffer); if (s != NULL) { if (*s == '/') strcpy(rpath, s + 1); else strcpy(rpath, s); strcat(rpath, upath); } else { strcpy(rpath, "$"); strcat(rpath, upath); } } } else strcpy(rpath, upath); for (q = rpath; *q; ++q) if (*q == '/') *q = '.'; return rpath; } #ifdef TEST int main(int argc, char **argv) { if (argc == 2) puts(upath(argv[1])); else puts("Give a path argument"); exit(0); } #endif
00000000 2f 2a 20 75 70 61 74 68 2e 63 20 2d 20 63 6f 6e |/* upath.c - con| 00000010 76 65 72 74 20 61 20 22 70 6f 6f 72 20 6d 61 6e |vert a "poor man| 00000020 73 20 75 6e 69 78 20 70 61 74 68 22 20 74 6f 20 |s unix path" to | 00000030 61 20 72 69 73 63 6f 73 20 70 61 74 68 2e 0a 20 |a riscos path.. | 00000040 2a 20 09 20 20 20 20 20 64 65 73 69 67 6e 65 64 |* . designed| 00000050 20 66 6f 72 20 69 6e 74 65 72 61 63 74 69 6f 6e | for interaction| 00000060 20 77 69 74 68 20 54 61 79 6c 6f 72 20 55 55 43 | with Taylor UUC| 00000070 50 27 73 20 55 75 63 70 46 53 24 2a 0a 20 2a 09 |P's UucpFS$*. *.| 00000080 20 20 20 20 20 56 61 72 69 61 62 6c 65 73 2e 0a | Variables..| 00000090 20 2a 0a 20 2a 20 41 75 74 68 6f 72 3a 20 20 09 | *. * Author: .| 000000a0 20 20 20 20 47 75 6e 6e 61 72 20 5a f6 74 6c 0a | Gunnar Z.tl.| 000000b0 20 2a 20 44 61 74 65 3a 20 20 20 20 09 20 20 20 | * Date: . | 000000c0 20 31 34 2d 53 65 70 2d 31 39 39 34 0a 20 2a 20 | 14-Sep-1994. * | 000000d0 4c 61 73 74 20 4d 6f 64 69 66 69 65 64 3a 20 20 |Last Modified: | 000000e0 20 31 34 2d 53 65 70 2d 31 39 39 34 0a 20 2a 2f | 14-Sep-1994. */| 000000f0 0a 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 |..#include <stdi| 00000100 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 |o.h>.#include <s| 00000110 74 64 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 |tdlib.h>.#includ| 00000120 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e |e <string.h>.#in| 00000130 63 6c 75 64 65 20 22 75 70 61 74 68 2e 68 22 0a |clude "upath.h".| 00000140 0a 2f 2a 20 77 65 20 63 6f 6e 76 65 72 74 20 61 |./* we convert a| 00000150 20 70 61 74 68 20 69 6e 20 22 70 6f 6f 72 20 6d | path in "poor m| 00000160 61 6e 73 20 75 6e 69 78 20 70 61 74 68 22 20 6e |ans unix path" n| 00000170 6f 74 61 74 69 6f 6e 2e 0a 20 2a 20 69 74 20 69 |otation.. * it i| 00000180 73 20 71 75 69 74 65 20 73 69 6d 70 6c 65 3a 0a |s quite simple:.| 00000190 20 2a 20 2d 20 69 66 20 74 68 65 72 65 27 73 20 | * - if there's | 000001a0 61 20 6c 65 61 64 69 6e 67 20 73 6c 61 73 68 2c |a leading slash,| 000001b0 20 77 65 20 65 78 74 72 61 63 74 20 74 68 65 20 | we extract the | 000001c0 68 65 61 64 20 6f 66 20 74 68 65 20 70 61 74 68 |head of the path| 000001d0 0a 20 2a 20 20 20 75 6e 74 69 6c 20 74 68 65 20 |. * until the | 000001e0 32 6e 64 20 73 6c 61 73 68 20 61 6e 64 20 73 65 |2nd slash and se| 000001f0 65 20 77 65 74 68 65 72 20 61 20 76 61 72 69 61 |e wether a varia| 00000200 62 6c 65 20 55 75 63 70 46 53 24 3c 70 72 65 66 |ble UucpFS$<pref| 00000210 69 78 3e 0a 20 2a 20 20 20 65 78 69 73 74 73 2e |ix>. * exists.| 00000220 20 49 66 20 73 6f 2c 20 77 65 20 75 73 65 20 74 | If so, we use t| 00000230 68 61 74 20 61 73 20 61 20 72 6f 6f 74 20 66 6f |hat as a root fo| 00000240 72 20 74 68 65 20 72 65 6d 61 69 6e 69 6e 67 20 |r the remaining | 00000250 70 61 74 68 2c 0a 20 2a 20 20 20 6f 74 68 65 72 |path,. * other| 00000260 77 69 73 65 20 77 65 20 6c 6f 6f 6b 20 66 6f 72 |wise we look for| 00000270 20 55 75 63 70 46 53 24 2f 20 61 6e 64 20 75 73 | UucpFS$/ and us| 00000280 65 20 74 68 61 74 20 61 73 20 61 20 70 72 65 66 |e that as a pref| 00000290 69 78 20 66 6f 72 0a 20 2a 20 20 20 74 68 65 20 |ix for. * the | 000002a0 77 68 6f 6c 65 20 70 61 74 68 2e 20 49 66 20 55 |whole path. If U| 000002b0 75 63 70 46 53 24 2f 20 69 73 20 75 6e 64 65 66 |ucpFS$/ is undef| 000002c0 69 6e 65 64 2c 20 77 65 20 74 72 79 20 22 24 22 |ined, we try "$"| 000002d0 20 69 6e 73 74 65 61 64 2e 0a 20 2a 20 2d 20 4e | instead.. * - N| 000002e0 6f 77 20 77 65 20 74 72 61 76 65 72 73 65 20 74 |ow we traverse t| 000002f0 68 65 20 77 68 6f 6c 65 20 70 61 74 68 2c 20 63 |he whole path, c| 00000300 6f 6e 76 65 72 74 69 6e 67 20 22 2f 22 20 74 6f |onverting "/" to| 00000310 20 22 2e 22 2e 20 49 66 20 74 68 65 72 65 0a 20 | ".". If there. | 00000320 2a 20 20 20 73 74 69 6c 6c 20 69 73 20 61 20 6c |* still is a l| 00000330 65 61 64 69 6e 67 20 73 6c 61 73 68 2c 20 77 65 |eading slash, we| 00000340 20 72 65 6d 6f 76 65 20 69 74 2e 0a 20 2a 2f 0a | remove it.. */.| 00000350 0a 63 68 61 72 20 2a 75 70 61 74 68 28 63 68 61 |.char *upath(cha| 00000360 72 20 2a 75 70 61 74 68 29 0a 7b 0a 20 20 20 20 |r *upath).{. | 00000370 73 74 61 74 69 63 20 63 68 61 72 20 72 70 61 74 |static char rpat| 00000380 68 5b 55 50 4c 45 4e 5d 3b 0a 20 20 20 20 63 68 |h[UPLEN];. ch| 00000390 61 72 20 62 75 66 66 65 72 5b 55 50 4c 45 4e 5d |ar buffer[UPLEN]| 000003a0 3b 0a 20 20 20 20 63 68 61 72 20 2a 71 2c 20 2a |;. char *q, *| 000003b0 73 3b 0a 20 20 20 20 2a 72 70 61 74 68 20 3d 20 |s;. *rpath = | 000003c0 30 3b 0a 20 20 20 20 73 20 3d 20 4e 55 4c 4c 3b |0;. s = NULL;| 000003d0 0a 20 20 20 20 69 66 20 28 2a 75 70 61 74 68 20 |. if (*upath | 000003e0 3d 3d 20 27 2f 27 29 0a 20 20 20 20 7b 0a 20 20 |== '/'). {. | 000003f0 20 20 20 20 20 20 71 20 3d 20 73 74 72 63 68 72 | q = strchr| 00000400 28 75 70 61 74 68 20 2b 20 31 2c 20 27 2f 27 29 |(upath + 1, '/')| 00000410 3b 0a 20 20 20 20 20 20 20 20 69 66 20 28 71 20 |;. if (q | 00000420 21 3d 20 4e 55 4c 4c 29 0a 20 20 20 20 20 20 20 |!= NULL). | 00000430 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 2a | {. *| 00000440 71 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 20 |q = 0;. | 00000450 20 20 20 73 74 72 63 70 79 28 62 75 66 66 65 72 | strcpy(buffer| 00000460 2c 20 55 55 43 50 46 53 50 29 3b 0a 20 20 20 20 |, UUCPFSP);. | 00000470 20 20 20 20 20 20 20 20 73 74 72 63 61 74 28 62 | strcat(b| 00000480 75 66 66 65 72 2c 20 75 70 61 74 68 29 3b 0a 20 |uffer, upath);. | 00000490 20 20 20 20 20 20 20 20 20 20 20 2a 71 20 3d 20 | *q = | 000004a0 27 2f 27 3b 0a 20 20 20 20 20 20 20 20 20 20 20 |'/';. | 000004b0 20 73 20 3d 20 67 65 74 65 6e 76 28 62 75 66 66 | s = getenv(buff| 000004c0 65 72 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 |er);. }. | 000004d0 20 20 20 20 20 20 20 69 66 20 28 73 20 21 3d 20 | if (s != | 000004e0 4e 55 4c 4c 29 0a 20 20 20 20 20 20 20 20 7b 0a |NULL). {.| 000004f0 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 | if (| 00000500 2a 73 20 3d 3d 20 27 2f 27 29 0a 20 20 20 20 20 |*s == '/'). | 00000510 20 20 20 20 20 20 20 20 20 20 20 73 74 72 63 70 | strcp| 00000520 79 28 72 70 61 74 68 2c 20 73 20 2b 20 31 29 3b |y(rpath, s + 1);| 00000530 0a 20 20 20 20 20 20 20 20 20 20 20 20 65 6c 73 |. els| 00000540 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |e. | 00000550 20 20 73 74 72 63 70 79 28 72 70 61 74 68 2c 20 | strcpy(rpath, | 00000560 73 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 |s);. | 00000570 73 74 72 63 61 74 28 72 70 61 74 68 2c 20 71 29 |strcat(rpath, q)| 00000580 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 |;. }. | 00000590 20 20 20 20 65 6c 73 65 0a 20 20 20 20 20 20 20 | else. | 000005a0 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 | {. s| 000005b0 74 72 63 70 79 28 62 75 66 66 65 72 2c 20 55 55 |trcpy(buffer, UU| 000005c0 43 50 46 53 50 29 3b 0a 20 20 20 20 20 20 20 20 |CPFSP);. | 000005d0 20 20 20 20 73 74 72 63 61 74 28 62 75 66 66 65 | strcat(buffe| 000005e0 72 2c 20 22 2f 22 29 3b 0a 20 20 20 20 20 20 20 |r, "/");. | 000005f0 20 20 20 20 20 73 20 3d 20 67 65 74 65 6e 76 28 | s = getenv(| 00000600 62 75 66 66 65 72 29 3b 0a 20 20 20 20 20 20 20 |buffer);. | 00000610 20 20 20 20 20 69 66 20 28 73 20 21 3d 20 4e 55 | if (s != NU| 00000620 4c 4c 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 |LL). | 00000630 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 09 69 |{. .i| 00000640 66 20 28 2a 73 20 3d 3d 20 27 2f 27 29 0a 20 20 |f (*s == '/'). | 00000650 20 20 20 20 20 20 20 20 20 20 20 20 20 09 20 20 | . | 00000660 20 20 73 74 72 63 70 79 28 72 70 61 74 68 2c 20 | strcpy(rpath, | 00000670 73 20 2b 20 31 29 3b 0a 20 20 20 20 20 20 20 20 |s + 1);. | 00000680 20 20 20 20 09 65 6c 73 65 0a 20 20 20 20 20 20 | .else. | 00000690 20 20 20 20 20 20 20 09 20 20 20 20 73 74 72 63 | . strc| 000006a0 70 79 28 72 70 61 74 68 2c 20 73 29 3b 0a 20 20 |py(rpath, s);. | 000006b0 20 20 20 20 20 20 20 20 20 20 09 73 74 72 63 61 | .strca| 000006c0 74 28 72 70 61 74 68 2c 20 75 70 61 74 68 29 3b |t(rpath, upath);| 000006d0 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 |. }. | 000006e0 20 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 0a | else.| 000006f0 20 20 20 20 20 20 20 20 20 20 20 20 7b 0a 20 20 | {. | 00000700 20 20 20 20 20 20 09 73 74 72 63 70 79 28 72 70 | .strcpy(rp| 00000710 61 74 68 2c 20 22 24 22 29 3b 0a 20 20 20 20 20 |ath, "$");. | 00000720 20 20 20 09 73 74 72 63 61 74 28 72 70 61 74 68 | .strcat(rpath| 00000730 2c 20 75 70 61 74 68 29 3b 0a 20 20 20 20 20 20 |, upath);. | 00000740 09 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 7d |. }. }| 00000750 0a 20 20 20 20 7d 0a 20 20 20 20 65 6c 73 65 0a |. }. else.| 00000760 20 20 20 20 09 73 74 72 63 70 79 28 72 70 61 74 | .strcpy(rpat| 00000770 68 2c 20 75 70 61 74 68 29 3b 0a 0a 20 20 20 20 |h, upath);.. | 00000780 66 6f 72 20 28 71 20 3d 20 72 70 61 74 68 3b 20 |for (q = rpath; | 00000790 2a 71 3b 20 2b 2b 71 29 0a 20 20 20 20 09 69 66 |*q; ++q). .if| 000007a0 20 28 2a 71 20 3d 3d 20 27 2f 27 29 0a 20 20 20 | (*q == '/'). | 000007b0 20 09 20 20 20 20 2a 71 20 3d 20 27 2e 27 3b 0a | . *q = '.';.| 000007c0 0a 20 20 20 20 72 65 74 75 72 6e 20 72 70 61 74 |. return rpat| 000007d0 68 3b 0a 7d 0a 0a 23 69 66 64 65 66 20 54 45 53 |h;.}..#ifdef TES| 000007e0 54 0a 69 6e 74 20 6d 61 69 6e 28 69 6e 74 20 61 |T.int main(int a| 000007f0 72 67 63 2c 20 63 68 61 72 20 2a 2a 61 72 67 76 |rgc, char **argv| 00000800 29 0a 7b 0a 20 20 20 20 69 66 20 28 61 72 67 63 |).{. if (argc| 00000810 20 3d 3d 20 32 29 0a 20 20 20 20 09 70 75 74 73 | == 2). .puts| 00000820 28 75 70 61 74 68 28 61 72 67 76 5b 31 5d 29 29 |(upath(argv[1]))| 00000830 3b 0a 20 20 20 20 65 6c 73 65 0a 20 20 20 20 09 |;. else. .| 00000840 70 75 74 73 28 22 47 69 76 65 20 61 20 70 61 74 |puts("Give a pat| 00000850 68 20 61 72 67 75 6d 65 6e 74 22 29 3b 0a 20 20 |h argument");. | 00000860 20 20 65 78 69 74 28 30 29 3b 0a 7d 0a 23 65 6e | exit(0);.}.#en| 00000870 64 69 66 0a |dif.| 00000874