Skip to content

Commit b4683dc

Browse files
committed
New args to enable generation of relative links to other projects.
1 parent 981f025 commit b4683dc

File tree

2 files changed

+148
-6
lines changed

2 files changed

+148
-6
lines changed

Tools/AGSOutput.m

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,8 @@ - (void) outputUnit: (NSMutableDictionary*)d to: (NSMutableString*)str
13791379
to: str];
13801380
}
13811381

1382+
static NSString *padding[100];
1383+
13821384
- (unsigned) reformat: (NSString*)str
13831385
withIndent: (unsigned)ind
13841386
to: (NSMutableString*)buf
@@ -1387,8 +1389,20 @@ - (unsigned) reformat: (NSString*)str
13871389
unsigned l = [str length];
13881390
NSRange r = [str rangeOfString: @"<example"];
13891391
unsigned i = 0;
1392+
unsigned c;
13901393
NSArray *a;
13911394

1395+
if (nil == padding[0])
1396+
{
1397+
int p;
1398+
1399+
padding[0] = @" ";
1400+
for (p = 1; p < sizeof(padding)/sizeof(*padding); p++)
1401+
{
1402+
padding[p] = [[padding[p-1] stringByAppendingString: @" "] copy];
1403+
}
1404+
}
1405+
13921406
/*
13931407
* Split out <example>...</example> sequences and output them literally.
13941408
* All other text has reformatting applied as necessary.
@@ -1442,10 +1456,11 @@ - (unsigned) reformat: (NSString*)str
14421456
}
14431457

14441458
/*
1445-
* Split the string up into parts separated by newlines.
1459+
* Split the string up into parts separated by whitespace.
14461460
*/
14471461
a = [self split: str];
1448-
for (i = 0; i < [a count]; i++)
1462+
c = [a count];
1463+
for (i = 0; i < c; i++)
14491464
{
14501465
unsigned int j;
14511466

@@ -1460,9 +1475,14 @@ - (unsigned) reformat: (NSString*)str
14601475
*/
14611476
ind -= 2;
14621477
}
1463-
for (j = 0; j < ind; j++)
1478+
while (j < ind)
14641479
{
1465-
[buf appendString: @" "];
1480+
unsigned size = ind - j;
1481+
1482+
if (size > sizeof(padding)/sizeof(*padding))
1483+
size = sizeof(padding)/sizeof(*padding);
1484+
[buf appendString: padding[size - 1]];
1485+
j += size;
14661486
}
14671487
[buf appendString: str];
14681488
[buf appendString: @"\n"];
@@ -1472,9 +1492,14 @@ - (unsigned) reformat: (NSString*)str
14721492
unsigned size = 70 - ind - [str length];
14731493
unsigned end;
14741494

1475-
for (j = 0; j < ind; j++)
1495+
if (j < ind)
14761496
{
1477-
[buf appendString: @" "];
1497+
unsigned size = ind - j;
1498+
1499+
if (size > sizeof(padding)/sizeof(*padding))
1500+
size = sizeof(padding)/sizeof(*padding);
1501+
[buf appendString: padding[size - 1]];
1502+
j += size;
14781503
}
14791504
end = [self fitWords: a
14801505
from: i

Tools/autogsdoc.m

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,21 @@ source files (not headers), and more importantly, it is used as the
354354
searched for in <code>DocumentationDirectory</code> (even though they
355355
may not have been autogenerated).
356356
</item>
357+
<item><strong>InstallationDomain</strong>
358+
May be used to specify where the documentation is to be installed,
359+
so that relative references to documentation in other projects can
360+
be used (otherwise references to other docuentation will use the
361+
absolute loacation of that documentation in the filesystem).
362+
By default this is the LOCAL domain, but it can also be set to
363+
SYSTEM, NETWORK, or USER.
364+
</item>
365+
<item><strong>InstallDir</strong>
366+
This is used to enable generation of HTML output with relative links
367+
to documentation created for other projects. The value of this must
368+
be the relative path at which this documentation will be installed
369+
within the installation domain (see -InstallationDomain) used.
370+
Relative links will not work until the documentation is installed.
371+
</item>
357372
<item><strong>Files</strong>
358373
Specifies the name of a file containing a list of file names as
359374
a property list array <em>(name1,name2,...)</em> format. If this
@@ -623,16 +638,42 @@ standard PropertyList format (not the XML format of OS X), using
623638
#import "GNUstepBase/NSString+GNUstepBase.h"
624639
#import "GNUstepBase/NSMutableString+GNUstepBase.h"
625640

641+
static NSString *
642+
commonRoot(NSString *s1, NSString *s2)
643+
{
644+
NSString *s;
645+
unsigned l;
646+
647+
if (nil == s1) return s2;
648+
649+
s = [s1 commonPrefixWithString: s2 options: NSLiteralSearch];
650+
l = [s length];
651+
while (l > 0 && [s characterAtIndex: l - 1] != '/')
652+
{
653+
l--;
654+
}
655+
if (0 == l)
656+
{
657+
NSLog(@"Unable to make relative links because projects '%@' and '%@'"
658+
@" share no common prefix.", s1, s2);
659+
exit(1);
660+
}
661+
return [s substringToIndex: l];
662+
}
663+
626664
int
627665
main(int argc, char **argv, char **env)
628666
{
629667
NSProcessInfo *proc;
630668
unsigned i;
669+
NSString *str;
631670
NSMutableDictionary *safe;
632671
NSDictionary *argsRecognized;
633672
NSUserDefaults *defs;
634673
NSFileManager *mgr;
635674
NSString *documentationDirectory;
675+
int installationDomain = 0;
676+
NSString *installDir;
636677
NSString *declared;
637678
NSString *headerDirectory;
638679
NSString *project;
@@ -779,6 +820,10 @@ standard PropertyList format (not the XML format of OS X), using
779820
@"search for gsdoc files",
780821
@"DocumentationDirectory",
781822
@"\t\t\tSTR\t(\"\")\n\tname of file containing filenames to document",
823+
@"InstallationDomain",
824+
@"\t\t\tSTR\t(LOCAL)\n\tfor relative links, the expected installation domain",
825+
@"InstallDir",
826+
@"\t\t\tSTR\t(\"\")\n\tfor relative links, location within domain",
782827
@"Files",
783828
@"\t\t\tBOOL\t(NO)\n\tremove all generated files",
784829
@"Clean",
@@ -940,6 +985,25 @@ standard PropertyList format (not the XML format of OS X), using
940985
error: NULL];
941986
}
942987

988+
str = [[defs stringForKey: @"InstallationlDomain"] uppercaseString];
989+
if ([str isEqualToString: @"SYSTEM"])
990+
installationDomain = NSSystemDomainMask;
991+
else if ([str isEqualToString: @"LOCAL"])
992+
installationDomain = NSLocalDomainMask;
993+
else if ([str isEqualToString: @"NETWORK"])
994+
installationDomain = NSNetworkDomainMask;
995+
else if ([str isEqualToString: @"USER"])
996+
installationDomain = NSUserDomainMask;
997+
else if (nil == str)
998+
installationDomain = NSLocalDomainMask;
999+
else
1000+
{
1001+
NSLog(@"Bad value for -InstallationDomain. If specified this must be one of SYSTEM, LOCAL, NETWORK, or USER");
1002+
exit(1);
1003+
}
1004+
1005+
installDir = [defs stringForKey: @"InstallDir"];
1006+
9431007
symbolDeclsFile = [documentationDirectory
9441008
stringByAppendingPathComponent: @"OrderedSymbolDeclarations.plist"];
9451009

@@ -1781,6 +1845,7 @@ standard PropertyList format (not the XML format of OS X), using
17811845
NSMutableDictionary *projects;
17821846
NSString *systemProjects;
17831847
NSString *localProjects;
1848+
NSString *installRoot = nil;
17841849
CREATE_AUTORELEASE_POOL (pool);
17851850

17861851
localProjects = [defs stringForKey: @"LocalProjects"];
@@ -1833,6 +1898,8 @@ standard PropertyList format (not the XML format of OS X), using
18331898
val
18341899
= [systemProjects stringByAppendingPathComponent: val];
18351900
[projects setObject: val forKey: key];
1901+
if (installDir)
1902+
installRoot = commonRoot(installRoot, key);
18361903
}
18371904
}
18381905
}
@@ -1876,6 +1943,8 @@ standard PropertyList format (not the XML format of OS X), using
18761943
val = [file stringByDeletingLastPathComponent];
18771944
val = [localProjects stringByAppendingPathComponent: val];
18781945
[projects setObject: val forKey: key];
1946+
if (installDir)
1947+
installRoot = commonRoot(installRoot, key);
18791948
}
18801949
}
18811950
}
@@ -1889,6 +1958,46 @@ standard PropertyList format (not the XML format of OS X), using
18891958
NSEnumerator *e = [projects keyEnumerator];
18901959
NSMutableArray *merged;
18911960
NSString *k;
1961+
NSString *relative = @"";
1962+
unsigned installLength = 0;
1963+
1964+
if (installDir)
1965+
{
1966+
NSString *base;
1967+
NSString *file;
1968+
NSString *path;
1969+
1970+
base = [NSSearchPathForDirectoriesInDomains(
1971+
NSDocumentationDirectory, installationDomain, NO) lastObject];
1972+
base = [base stringByAppendingPathComponent: installDir];
1973+
base = [base stringByStandardizingPath];
1974+
file = [project stringByAppendingPathExtension: @"html"];
1975+
path = [base stringByAppendingPathComponent: file];
1976+
installRoot = commonRoot(installRoot, path);
1977+
installLength = [installRoot length];
1978+
if ([base length] < installLength)
1979+
{
1980+
/* All referenced project documentation is relative to the
1981+
* directory that this project will be installed in.
1982+
*/
1983+
relative = @"";
1984+
}
1985+
else
1986+
{
1987+
unsigned c;
1988+
1989+
base = [base substringFromIndex: installLength];
1990+
1991+
/* Build the prefix to get from the package being generated
1992+
* up to the documentation installation root.
1993+
*/
1994+
c = [[base componentsSeparatedByString: @"/"] count];
1995+
while (c--)
1996+
{
1997+
relative = [relative stringByAppendingString: @"../"];
1998+
}
1999+
}
2000+
}
18922001

18932002
merged = [NSMutableArray arrayWithCapacity: [projects count]];
18942003
while ((k = [e nextObject]) != nil)
@@ -1923,6 +2032,14 @@ standard PropertyList format (not the XML format of OS X), using
19232032
{
19242033
p = [k stringByDeletingLastPathComponent];
19252034
}
2035+
if (installRoot)
2036+
{
2037+
/* Replace the root part with the prefix
2038+
* to make the path relative.
2039+
*/
2040+
p = [p substringFromIndex: installLength];
2041+
p = [relative stringByAppendingString: p];
2042+
}
19262043
[tmp setDirectory: p];
19272044
[globalRefs mergeRefs: [tmp refs] override: YES];
19282045
RELEASE(tmp);

0 commit comments

Comments
 (0)