Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site watrose.UUCP Path: utzoo!watmath!watrose!jmsellens From: jmsellens@watrose.UUCP (John M Sellens) Newsgroups: net.micro.pc Subject: PATH Environment variable finder for IBM PC Message-ID: <6702@watrose.UUCP> Date: Sat, 7-Apr-84 05:11:05 EST Article-I.D.: watrose.6702 Posted: Sat Apr 7 05:11:05 1984 Date-Received: Sat, 7-Apr-84 06:24:45 EST Organization: U of Waterloo, Ontario Lines: 193 X - bug killer These routines are used by 'Find' and 'Make' (see adjacent articles. Hope they're useful. - John ---------------------------------------------------------- /* The following are two routines to make it easier to access the PATH environment variable. They are written for use with the DeSmet C Compiler. Known portability problems: - assembler code embedded in the C code - requires that code segment register (CS) be set to the same value as at program invocation so that the program segment prefix can be located. This would probably only be a problem if a "large model" compiler is used. The code is a little kludgy in places but... Any suggestions for improvements gratefully accepted. */ /* Written by John M Sellens, April, 1984 Code is all original except where indicated otherwise. Until August, 1984: jmsellens@watrose.UUCP 107 - 180 Brybeck Cres. Kitchener, Ontario N2M 5G4 After August, 1984: c/o 1135 Lansdowne Ave. SW Calgary, Alberta T2S 1A4 (c) Copyright 1984 John M Sellens Permission is granted to use, distribute and/or modify this code unless done for direct commercial profit. If you find these routines useful, modest contributions (monetary or otherwise) will be gratefully accepted. Author's name, address and this notice must be included in any copies. */ #include typedef char *char_ptr; main() { /* Example of how to use parse_path() and get_path() */ int i; char *get_path(); char_ptr *paths, *parse_path(); paths = parse_path(get_path()); if (paths != NULL) for (i=0; paths[i]!=NULL; i++) printf("%s\n",paths[i]); else printf("No path is set\n"); } char_ptr *parse_path(ps) char *ps; { /* Takes the path string returned by get_path and destroys it, by inserting NULL's and returning an array of pointers to characters that point to locations in the original path string. The pointer after the last pointer into the path string is NULL. If the path string is NULL, then NULL is returned. */ int i, j, num; char_ptr *pa; if (ps[0] == '\0') /* no path */ return(NULL); /* count the number of semi-colons, add 1 = number of paths */ for (num=1, i=0; ps[i] != '\0'; i++) if (ps[i] == ';') num++; pa = (char_ptr *)malloc(sizeof(char_ptr) * (num+1)); pa[num] = NULL; /* now loop through and point to each path */ for (i=j=0; i