/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */ # include "jam.h" # include "filesys.h" # ifdef OS_MAC # define DELIM ':' /* * pathunix.c - manipulate file names on UNIX, NT, OS2 * * External routines: * * file_parse() - split a file name into dir/base/suffix/member * file_build() - build a filename given dir/base/suffix/member * file_parent() - make a FILENAME point to its parent dir * * File_parse() and file_build() just manipuate a string and a structure; * they do not make system calls. * * 04/08/94 (seiwald) - Coherent/386 support added. * 12/26/93 (seiwald) - handle dir/.suffix properly in file_build() * 12/19/94 (mikem) - solaris string table insanity support * 12/21/94 (wingerd) Use backslashes for pathnames - the NT way. * 02/14/95 (seiwald) - parse and build /xxx properly * 02/23/95 (wingerd) Compilers on NT can handle "/" in pathnames, so we * should expect hdr searches to come up with strings * like "thing/thing.h". So we need to test for "/" as * well as "\" when parsing pathnames. * 03/16/95 (seiwald) - fixed accursed typo on line 69. * 05/03/96 (seiwald) - split from filent.c, fileunix.c * 12/20/96 (seiwald) - when looking for the rightmost . in a file name, * don't include the archive member name. */ /* * file_parse() - split a file name into dir/base/suffix/member */ void file_parse( char *file, FILENAME *f ) { char *p, *q; char *end; memset( (char *)f, 0, sizeof( *f ) ); /* Look for <grist> */ if( file[0] == '<' && ( p = strchr( file, '>' ) ) ) { f->f_grist.ptr = file; f->f_grist.len = p - file; file = p + 1; } /* Look for dir: */ p = strrchr( file, DELIM ); if( p ) { f->f_dir.ptr = file; f->f_dir.len = p - file; /* Dir of : is : */ f->f_dir.len++; file = p + 1; } end = file + strlen( file ); /* Look for (member) */ if( ( p = strchr( file, '(' ) ) && end[-1] == ')' ) { f->f_member.ptr = p + 1; f->f_member.len = end - p - 2; end = p; } /* Look for .suffix */ /* This would be memrchr() */ p = 0; q = file; while( q = memchr( q, '.', end - q ) ) p = q++; if( p ) { f->f_suffix.ptr = p; f->f_suffix.len = end - p; end = p; } /* Leaves base */ f->f_base.ptr = file; f->f_base.len = end - file; } /* * file_build() - build a filename given dir/base/suffix/member */ # define DIR_EMPTY 0 /* "" */ # define DIR_DOT 1 /* : */ # define DIR_DOTDOT 2 /* :: */ # define DIR_ABS 3 /* dira:dirb: */ # define DIR_REL 4 /* :dira:dirb: */ # define G_DIR 0 /* take dir */ # define G_ROOT 1 /* take root */ # define G_CAT 2 /* prepend root to dir */ # define G_DTDR 3 /* :: of rel dir */ # define G_DDDD 4 /* make it ::: (../..) */ # define G_MT 5 /* leave it empty */ char grid[5][5] = { /* EMPTY DOT DOTDOT ABS REL */ /* EMPTY */ { G_MT, G_DIR, G_DIR, G_DIR, G_DIR }, /* DOT */ { G_ROOT, G_DIR, G_DIR, G_DIR, G_DIR }, /* DOTDOT */ { G_ROOT, G_ROOT, G_DDDD, G_DIR, G_DTDR }, /* ABS */ { G_ROOT, G_ROOT, G_ROOT, G_DIR, G_CAT }, /* REL */ { G_ROOT, G_ROOT, G_ROOT, G_DIR, G_CAT } } ; static int file_flags( char *ptr, int len ) { if( !len ) return DIR_EMPTY; if( len == 1 && ptr[0] == DELIM ) return DIR_DOT; if( len == 2 && ptr[0] == DELIM && ptr[1] == DELIM ) return DIR_DOTDOT; if( ptr[0] == DELIM ) return DIR_REL; return DIR_ABS; } void file_build( FILENAME *f, char *file, int binding ) { char *ofile = file; int dflag, rflag, act; if( DEBUG_SEARCH ) { printf("build file: "); if( f->f_root.len ) printf( "root = '%.*s' ", f->f_root.len, f->f_root.ptr ); if( f->f_dir.len ) printf( "dir = '%.*s' ", f->f_dir.len, f->f_dir.ptr ); if( f->f_base.len ) printf( "base = '%.*s' ", f->f_base.len, f->f_base.ptr ); } /* Start with the grist. If the current grist isn't */ /* surrounded by <>'s, add them. */ if( f->f_grist.len ) { if( f->f_grist.ptr[0] != '<' ) *file++ = '<'; memcpy( file, f->f_grist.ptr, f->f_grist.len ); file += f->f_grist.len; if( file[-1] != '>' ) *file++ = '>'; } /* Combine root & directory, according to the grid. */ dflag = file_flags( f->f_dir.ptr, f->f_dir.len ); rflag = file_flags( f->f_root.ptr, f->f_root.len ); switch( act = grid[ rflag ][ dflag ] ) { case G_DTDR: /* :: of rel dir */ *file++ = DELIM; /* fall through */ case G_DIR: /* take dir */ memcpy( file, f->f_dir.ptr, f->f_dir.len ); file += f->f_dir.len; break; case G_ROOT: /* take root */ memcpy( file, f->f_root.ptr, f->f_root.len ); file += f->f_root.len; break; case G_CAT: /* prepend root to dir */ memcpy( file, f->f_root.ptr, f->f_root.len ); file += f->f_root.len; if( file[-1] == DELIM ) --file; memcpy( file, f->f_dir.ptr, f->f_dir.len ); file += f->f_dir.len; break; case G_DDDD: /* make it ::: (../..) */ strcpy( file, ":::" ); file += 3; break; } /* Put : between dir and file (if none already) */ if( act != G_MT && file[-1] != DELIM && ( f->f_base.len || f->f_suffix.len ) ) { *file++ = DELIM; } if( f->f_base.len ) { memcpy( file, f->f_base.ptr, f->f_base.len ); file += f->f_base.len; } if( f->f_suffix.len ) { memcpy( file, f->f_suffix.ptr, f->f_suffix.len ); file += f->f_suffix.len; } if( f->f_member.len ) { *file++ = '('; memcpy( file, f->f_member.ptr, f->f_member.len ); file += f->f_member.len; *file++ = ')'; } *file = 0; if( DEBUG_SEARCH ) printf(" -> '%s'\n", ofile); } /* * file_parent() - make a FILENAME point to its parent dir */ void file_parent( FILENAME *f ) { /* just set everything else to nothing */ f->f_base.ptr = f->f_suffix.ptr = f->f_member.ptr = ""; f->f_base.len = f->f_suffix.len = f->f_member.len = 0; } # endif /* OS_MAC */
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 2850 | rmg |
Mac classic MPW Codewarrior 7 upgrades: minor compiling issues, new paths in Jambase for libraries and includes, and separate out GenFile1 that sets PATH for UNIX only, as it does't work under MPW (or anything other than with sh). Porting change, noted in RELNOTES. === computer:1666: Change 41285 by evalynne@evalynne-bld-mac on 2003/02/05 11:47:19 |
||
#6 | 2493 | rmg |
Rewrite the past: update all jam's source with comments to reflect changes since about 2.3, very early 2001. Whitespace only change. === computer:1666: Change 37660 by seiwald@play-seiwald on 2002/11/06 22:41:35 Note: I regenerated jamgram.c on my linux 7.3 system prior to the submit, since patch was so unhappy trying to lay down the changes from Christopher's change. Presumably this is just due to different yacc/bison/whatever particulars on the system where Christopher made the changes originally. - rmg |
||
#5 | 2491 | rmg |
Some consting in jam to make it more compilable by C++ compilers. No functional change. === computer:1666: Change 37433 by perforce@perforce on 2002/10/30 16:08:51 Recreational const-ing of jam, for compilers that don't allow "string" to be passed as a non-const char *. This included a few places where we were modifying what could possibly have been read-only storage, oddly enough. No functional change. === computer:1666: Change 37602 by seiwald@play-seiwald on 2002/11/04 17:25:40 |
||
#4 | 1352 | rmg |
Integrates Change 350 by grant_glouser Change 352 by grant_glouser Resolved -ay, since the changes were already present in Jam 2.3 from other sources. (This change is for the benefit of the integration history, only.) |
||
#3 | 1319 | rmg |
Jam 2.3 + Perforce's internal changes. This change is a drop of the Perforce internal Jam changes since the 2.3 public release. The individual changes represented herein are preserved in the //guest/richard_geiger/intjam/ branch. The intent of this drop is to provide a base, from which other contributors' Jam branches may be integrated into. It is not intended to become a packaged release in this state. We will be integrating changes from other users prior to creating the next packaged release. Please refer to the src/RELNOTES file for an overview of the changes present in this integration. - Richard Geiger Open Source Engineer at Perforce |
||
#2 | 486 | Perforce staff |
Jam 2.3. See RELNOTES for a list of changes from 2.2.x. Just about every source file was touched when jam got ANSI-fied. |
||
#1 | 2 | laura | Add Jam/MR 2.2 source |