~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Tools/AGSHtml.m

Tags: upstream-1.11.2
ImportĀ upstreamĀ versionĀ 1.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
   You should have received a copy of the GNU General Public
17
17
   License along with this program; see the file COPYING.LIB.
18
18
   If not, write to the Free Software Foundation,
19
 
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 
21
21
   */
22
22
 
25
25
#include "GNUstepBase/GNUstep.h"
26
26
#include "GNUstepBase/GSCategories.h"
27
27
 
 
28
/*
 
29
 * Define constants for use if we are built with apple Foundation
 
30
 */
 
31
#ifndef GS_API_OSSPEC
 
32
#define GS_API_OSSPEC   10000
 
33
#endif
 
34
#ifndef GS_API_OPENSTEP
 
35
#define GS_API_OPENSTEP 40000
 
36
#endif
 
37
#ifndef GS_API_MACOSX
 
38
#define GS_API_MACOSX   100000
 
39
#endif
 
40
 
28
41
static int      XML_ELEMENT_NODE;
29
42
static int      XML_ENTITY_REF_NODE;
30
43
static int      XML_TEXT_NODE;
84
97
 
85
98
- (void) dealloc
86
99
{
 
100
  RELEASE(project);
87
101
  RELEASE(globalRefs);
88
102
  RELEASE(localRefs);
89
103
  RELEASE(projectRefs);
109
123
- (id) init
110
124
{
111
125
  indent = [[NSMutableString alloc] initWithCapacity: 64];
 
126
  project = RETAIN([[NSUserDefaults standardUserDefaults]
 
127
    stringForKey: @"Project"]);
112
128
  return self;
113
129
}
114
130
 
171
187
      s = [NSString stringWithFormat: @"<a %@=\"%@%@%@$%@\">",
172
188
        kind, s, hash, t, r];
173
189
    }
174
 
  return s;
 
190
  return [s stringByReplacingString: @":" withString: @"$"];
175
191
}
176
192
 
177
193
/**
201
217
    }
202
218
  else if (u == nil)
203
219
    {
204
 
      s = [localRefs unitRef: r type: t unit: &u];
 
220
      NSString  *tmp = unit;
 
221
 
 
222
      s = [localRefs unitRef: r type: t unit: &tmp];
205
223
      if (s == nil)
206
224
        {
207
 
          s = [globalRefs unitRef: r type: t unit: &u];
 
225
          tmp = u;
 
226
          s = [localRefs unitRef: r type: t unit: &tmp];
 
227
          if (s == nil)
 
228
            {
 
229
              tmp = unit;
 
230
              s = [globalRefs unitRef: r type: t unit: &tmp];
 
231
              if (s == nil)
 
232
                {
 
233
                  tmp = nil;
 
234
                  s = [globalRefs unitRef: r type: t unit: &tmp];
 
235
                }
 
236
            }
208
237
        }
 
238
      u = tmp;
209
239
    }
210
240
  if (s == nil)
211
241
    {
242
272
            kind, s, hash, t, u, sep, r];
243
273
        }
244
274
    }
245
 
  return s;
 
275
  return [s stringByReplacingString: @":" withString: @"$"];
246
276
}
247
277
 
248
278
- (NSString*) outputDocument: (GSXMLNode*)node
256
286
    }
257
287
  buf = [NSMutableString stringWithCapacity: 4096];
258
288
 
259
 
  [buf appendString: @"<html>\n"];
 
289
  /* Declaration */
 
290
  [buf appendString: @"<!DOCTYPE html PUBLIC "];
 
291
  [buf appendString: @"\"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"];
 
292
  [buf appendString: @"\"http://www.w3.org/TR/xhtml1/DTD/"];
 
293
  [buf appendString: @"xhtml1-strict.dtd\">\n"];
 
294
  [buf appendString: @"<html xmlns=\"http://www.w3.org/1999/xhtml\" "];
 
295
  [buf appendString: @"xml:lang=\"en\" lang=\"en\">\n"];
 
296
 
260
297
  [self incIndent];
261
298
  [self outputNodeList: node to: buf];
262
299
  [self decIndent];
332
369
          NSString      *text = [dict objectForKey: ref];
333
370
          NSString      *file = ref;
334
371
 
 
372
          ref = [ref stringByReplacingString: @":" withString: @"$"];
335
373
          if ([file isEqual: base] == YES)
336
374
            {
337
375
              continue; // Don't list current file.
396
434
              else if (classname != nil && category == nil)
397
435
                {
398
436
                  NSArray       *catNames;
 
437
                  NSDictionary  *d;
399
438
 
400
439
                  /*
401
440
                   * For a class, we want to list methods in any associated
402
441
                   * categories as well as those of the class itself.
403
442
                   */
404
 
                  catNames = [[[refs objectForKey: @"categories"]
405
 
                    objectForKey: classname] allKeys];
 
443
                  d = [refs objectForKey: @"categories"];
 
444
                  d = [d objectForKey: classname];
 
445
                  catNames = [d allKeys];
406
446
                  if ((c = [catNames count]) > 0)
407
447
                    {
408
448
                      NSMutableDictionary       *m = [dict mutableCopy];
431
471
                              NSString  *ref = [NSString stringWithFormat:
432
472
                                @"(%@)%@", catName, mname];
433
473
 
 
474
                              ref = [ref stringByReplacingString: @":"
 
475
                                                      withString: @"$"];
434
476
                              [m setObject: file forKey: ref];
435
477
                            }
436
478
                        }
463
505
          NSString      *file = [dict objectForKey: ref];
464
506
          NSString      *text = ref;
465
507
 
 
508
          ref = [ref stringByReplacingString: @":" withString: @"$"];
 
509
 
466
510
          /*
467
511
           * If a reference to a method contains a leading category name,
468
512
           * we don't want it in the visible method name, however if it's
504
548
          else
505
549
            {
506
550
              if  (([type isEqual: @"protocol"] == YES)
507
 
                   && ([text hasPrefix: @"&lt;"] == NO))
 
551
                && ([text hasPrefix: @"&lt;"] == NO))
508
552
                {
509
553
                  // it's an informal protocol, detected earlier as an
510
554
                  // unimplemented category of NSObject; make proper link
702
746
          children = node;
703
747
          if ([[children name] isEqual: @"standards"])
704
748
            {
705
 
              [self outputNode: children to: buf];
 
749
              node = [node nextElement];
706
750
            }
 
751
          [self outputVersion: prop to: buf];
707
752
 
708
753
          if ([[node name] isEqual: @"desc"])
709
754
            {
808
853
      else if ([name isEqual: @"declared"] == YES)
809
854
        {
810
855
          [buf appendString: indent];
811
 
          [buf appendString: @"<blockquote>\n"];
 
856
          [buf appendString: @"<blockquote class=\"declared\">\n"];
812
857
          [self incIndent];
813
858
          [buf appendString: indent];
814
859
          [buf appendString: @"<dl>\n"];
829
874
      else if ([name isEqual: @"desc"] == YES)
830
875
        {
831
876
          [buf appendString: indent];
832
 
          [buf appendString: @"<p>\n"];
 
877
          [buf appendString: @"<div class=\"desc\">\n"];
833
878
          [self incIndent];
834
879
          while (children != nil)
835
880
            {
837
882
            }
838
883
          [self decIndent];
839
884
          [buf appendString: indent];
840
 
          [buf appendString: @"</p>\n"];
 
885
          [buf appendString: @"</div>\n"];
841
886
        }
842
887
      else if ([name isEqual: @"em"] == YES)
843
888
        {
1021
1066
          children = node;
1022
1067
          if ([[children name] isEqual: @"standards"])
1023
1068
            {
1024
 
              [self outputNode: children to: buf];
 
1069
              node = [node nextElement];
1025
1070
            }
 
1071
          [self outputVersion: prop to: buf];
1026
1072
 
1027
1073
          if ([[node name] isEqual: @"desc"])
1028
1074
            {
1071
1117
          [self outputText: [children firstChild] to: buf];
1072
1118
          [self decIndent];
1073
1119
          [buf appendString: @"</title>\n"];
 
1120
#if 0
 
1121
          /** Css : TODO print.css **/
 
1122
          [buf appendString:@"<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"/>\n"];
 
1123
          [buf appendString:@"<link rel=\"stylesheet\" type=\"text/css\" href=\"screen.css\" media=\"screen\" title=\"Normal\" />\n"];
 
1124
          /** Robots **/
 
1125
          [buf appendString:@"<meta name=\"robots\" content=\"all\" />\n"];
 
1126
#endif
1074
1127
          [self decIndent];
1075
1128
          [buf appendString: indent];
1076
1129
          [buf appendString: @"</head>\n"];
1320
1373
          /*
1321
1374
           * List standards with which ivar complies
1322
1375
           */
1323
 
          if ([[children name] isEqual: @"standards"])
1324
 
            {
1325
 
              [self outputNode: children to: buf];
1326
 
            }
 
1376
          [self outputVersion: prop to: buf];
1327
1377
          if ([[tmp name] isEqual: @"desc"])
1328
1378
            {
1329
1379
              [self outputNode: tmp to: buf];
1449
1499
          children = node;
1450
1500
          if ([[children name] isEqual: @"standards"])
1451
1501
            {
1452
 
              [self outputNode: children to: buf];
 
1502
              node = [node nextElement];
1453
1503
            }
 
1504
          [self outputVersion: prop to: buf];
1454
1505
 
1455
1506
          if ([[node name] isEqual: @"desc"])
1456
1507
            {
1467
1518
          GSXMLNode     *tmp = children;
1468
1519
          BOOL          hadArg = NO;
1469
1520
 
 
1521
          [buf appendString:@"<div class=\"method\">\n"];
 
1522
 
1470
1523
          sel = [prop objectForKey: @"factory"];
1471
1524
          str = [prop objectForKey: @"type"];
1472
1525
          if (sel != nil && [sel boolValue] == YES)
1563
1616
              [linkRef setString:sel];
1564
1617
              [linkRef replaceString: @"&nbsp;" withString: @""];
1565
1618
 
1566
 
              s = [self makeLink: linkRef ofType: @"method" inUnit: nil isRef: NO];
 
1619
              s = [self makeLink: linkRef
 
1620
                          ofType: @"method"
 
1621
                          inUnit: nil
 
1622
                           isRef: NO];
1567
1623
              if (s != nil)
1568
1624
                {
1569
1625
                  [buf appendString: s];
1584
1640
              /*
1585
1641
               * List standards with which method complies
1586
1642
               */
1587
 
              children = firstElement(node);
 
1643
              children = node;
1588
1644
              if ([[children name] isEqual: @"standards"])
1589
1645
                {
1590
 
                  [self outputNode: children to: buf];
 
1646
                  node = [node nextElement];
1591
1647
                }
 
1648
              [self outputVersion: prop to: buf];
1592
1649
 
1593
1650
              if ((str = [prop objectForKey: @"init"]) != nil
1594
1651
                && [str boolValue] == YES)
1602
1659
                  [buf appendString: @"Subclasses <strong>should</strong> "
1603
1660
                    @"override this method.<br />\n"];
1604
1661
                }
 
1662
              else if ([str isEqual: @"dummy"] == YES)
 
1663
                {
 
1664
                  [buf appendString: @"An empty method provided for subclasses "
 
1665
                    @"to override.<br />\n"];
 
1666
                }
1605
1667
              else if ([str isEqual: @"never"] == YES)
1606
1668
                {
1607
1669
                  [buf appendString: @"Subclasses should <strong>NOT</strong> "
1615
1677
              [buf appendString: indent];
1616
1678
              [buf appendString: @"<hr width=\"25%\" align=\"left\" />\n"];
1617
1679
            }
 
1680
          [buf appendString:@"</div>\n"];
1618
1681
        }
1619
1682
      else if ([name isEqual: @"p"] == YES)
1620
1683
        {
1634
1697
 
1635
1698
          // fill in default value
1636
1699
          if ((type == nil) || [type isEqual: @""])
 
1700
            {
1637
1701
              type = @"label";
1638
 
 
 
1702
            }
1639
1703
          if ([type isEqual: @"method"] || [type isEqual: @"ivariable"])
1640
1704
            {
1641
1705
              s = [self makeLink: r ofType: type inUnit: c isRef: YES];
1724
1788
        }
1725
1789
      else if ([name isEqual: @"standards"])
1726
1790
        {
1727
 
          GSXMLNode     *tmp = [node firstChild];
1728
 
          BOOL          first = YES;
1729
 
 
1730
 
          if (tmp != nil)
1731
 
            {
1732
 
              [buf appendString: indent];
1733
 
              [buf appendString: @"<b>Standards:</b>"];
1734
 
              while (tmp != nil)
1735
 
                {
1736
 
                  if ([tmp type] == XML_ELEMENT_NODE)
1737
 
                    {
1738
 
                      if (first == YES)
1739
 
                        {
1740
 
                          first = NO;
1741
 
                          [buf appendString: @" "];
1742
 
                        }
1743
 
                      else
1744
 
                        {
1745
 
                          [buf appendString: @", "];
1746
 
                        }
1747
 
                      [buf appendString: [tmp name]];
1748
 
                    }
1749
 
                  tmp = [tmp nextElement];
1750
 
                }
1751
 
              [buf appendString: @"<br />\n"];
1752
 
            }
1753
1791
        }
1754
1792
      else if ([name isEqual: @"strong"] == YES)
1755
1793
        {
1815
1853
          children = node;
1816
1854
          if ([[children name] isEqual: @"standards"])
1817
1855
            {
1818
 
              [self outputNode: children to: buf];
 
1856
              node = [node nextElement];
1819
1857
            }
 
1858
          [self outputVersion: prop to: buf];
1820
1859
 
1821
1860
          if (node != nil && [[node name] isEqual: @"desc"] == YES)
1822
1861
            {
1893
1932
          children = node;
1894
1933
          if ([[children name] isEqual: @"standards"])
1895
1934
            {
1896
 
              [self outputNode: children to: buf];
 
1935
              node = [node nextElement];
1897
1936
            }
 
1937
          [self outputVersion: prop to: buf];
1898
1938
 
1899
1939
          if ([[node name] isEqual: @"desc"])
1900
1940
            {
2250
2290
 
2251
2291
- (void) outputUnit: (GSXMLNode*)node to: (NSMutableString*)buf
2252
2292
{
2253
 
  GSXMLNode     *t;
2254
2293
  NSArray       *a;
2255
2294
  NSMutableString *ivarBuf = ivarsAtEnd ?
2256
2295
    [NSMutableString stringWithCapacity: 1024] : nil;
 
2296
  NSDictionary  *prop = [node attributes];
2257
2297
 
2258
2298
  node = [node firstChildElement];
2259
2299
  if (node != nil && [[node name] isEqual: @"declared"] == YES)
2291
2331
      [buf appendString: @"</blockquote>\n"];
2292
2332
    }
2293
2333
 
2294
 
  t = node;
2295
 
  while (t != nil && [[t name] isEqual: @"standards"] == NO)
2296
 
    {
2297
 
      t = [t nextElement];
2298
 
    }
2299
 
  if (t != nil && [t firstChild] != nil)
2300
 
    {
2301
 
      t = [t firstChild];
2302
 
      [buf appendString: indent];
2303
 
      [buf appendString: @"<blockquote>\n"];
2304
 
      [self incIndent];
2305
 
      [buf appendString: indent];
2306
 
      [buf appendString: @"<b>Standards:</b>\n"];
2307
 
      [buf appendString: indent];
2308
 
      [buf appendString: @"<ul>\n"];
2309
 
      [self incIndent];
2310
 
      while (t != nil)
2311
 
        {
2312
 
          if ([t type] == XML_ELEMENT_NODE)
2313
 
            {
2314
 
              [buf appendString: indent];
2315
 
              [buf appendString: @"<li>"];
2316
 
              [buf appendString: [t name]];
2317
 
              [buf appendString: @"</li>\n"];
2318
 
            }
2319
 
          t = [t nextElement];
2320
 
        }
2321
 
      [self decIndent];
2322
 
      [buf appendString: indent];
2323
 
      [buf appendString: @"</ul>\n"];
2324
 
      [self decIndent];
2325
 
      [buf appendString: indent];
2326
 
      [buf appendString: @"</blockquote>\n"];
2327
 
    }
 
2334
  while (node != nil && [[node name] isEqual: @"desc"] == NO)
 
2335
    {
 
2336
      node = [node nextElement];
 
2337
    }
 
2338
  [self outputVersion: prop to: buf];
2328
2339
 
2329
2340
  if (node != nil && [[node name] isEqual: @"desc"] == YES)
2330
2341
    {
2394
2405
    }
2395
2406
}
2396
2407
 
 
2408
- (void) outputVersion: (NSDictionary*)prop to: (NSMutableString*)buf
 
2409
{
 
2410
  NSString      *ovadd = [prop objectForKey: @"ovadd"];
 
2411
  NSString      *gvadd = [prop objectForKey: @"gvadd"];
 
2412
  NSString      *ovdep = [prop objectForKey: @"ovdep"];
 
2413
  NSString      *gvdep = [prop objectForKey: @"gvdep"];
 
2414
  NSString      *ovrem = [prop objectForKey: @"ovrem"];
 
2415
  NSString      *gvrem = [prop objectForKey: @"gvrem"];
 
2416
  const char    *str;
 
2417
  int           maj;
 
2418
  int           min;
 
2419
  int           sub;
 
2420
 
 
2421
  if ([ovadd length] > 0)
 
2422
    {
 
2423
      int       add;
 
2424
      int       dep;
 
2425
      int       rem;
 
2426
 
 
2427
      str = [ovadd UTF8String];
 
2428
      if (str != 0 && sscanf(str, "%d.%d.%d", &maj, &min, &sub) == 3)
 
2429
        add = maj * 10000 + min * 100 + sub;
 
2430
      else
 
2431
        add = 0;
 
2432
 
 
2433
      str = [ovdep UTF8String];
 
2434
      if (str != 0 && sscanf(str, "%d.%d.%d", &maj, &min, &sub) == 3)
 
2435
        dep = maj * 10000 + min * 100 + sub;
 
2436
      else
 
2437
        dep = 0;
 
2438
 
 
2439
      str = [ovrem UTF8String];
 
2440
      if (str != 0 && sscanf(str, "%d.%d.%d", &maj, &min, &sub) == 3)
 
2441
        rem = maj * 10000 + min * 100 + sub;
 
2442
      else
 
2443
        rem = 0;
 
2444
 
 
2445
      [buf appendString: indent];
 
2446
      [buf appendString: @"<div class=\"availability\">\n"];
 
2447
      [buf appendString: @"<b>Availability:</b> "];
 
2448
      if (add < GS_API_OSSPEC)
 
2449
        {
 
2450
          [buf appendString: @"Not in OpenStep/MacOS-X"];
 
2451
        }
 
2452
      else if (add < GS_API_OPENSTEP)
 
2453
        {
 
2454
          [buf appendString: @"OpenStep"];
 
2455
        }
 
2456
      else if (add < GS_API_MACOSX)
 
2457
        {
 
2458
          [buf appendString: @"OPENSTEP "];
 
2459
          [buf appendString: ovadd];
 
2460
        }
 
2461
      else
 
2462
        {
 
2463
          [buf appendString: @"MacOS-X "];
 
2464
          [buf appendString: ovadd];
 
2465
        }
 
2466
      if (dep > add)
 
2467
        {
 
2468
          [buf appendString: @" deprecated at "];
 
2469
          if (dep < GS_API_MACOSX)
 
2470
            {
 
2471
              [buf appendString: @"OPENSTEP "];
 
2472
              [buf appendString: ovdep];
 
2473
            }
 
2474
          else
 
2475
            {
 
2476
              [buf appendString: @"MacOS-X "];
 
2477
              [buf appendString: ovdep];
 
2478
            }
 
2479
        }
 
2480
      if (rem > add)
 
2481
        {
 
2482
          [buf appendString: @" removed at "];
 
2483
          if (rem < GS_API_MACOSX)
 
2484
            {
 
2485
              [buf appendString: @"OPENSTEP "];
 
2486
              [buf appendString: ovrem];
 
2487
            }
 
2488
          else
 
2489
            {
 
2490
              [buf appendString: @"MacOS-X "];
 
2491
              [buf appendString: ovrem];
 
2492
            }
 
2493
        }
 
2494
      if ([gvadd length] > 0)
 
2495
        {
 
2496
          [buf appendString: @", "];
 
2497
          [buf appendString: project];
 
2498
          [buf appendString: @" "];
 
2499
          [buf appendString: gvadd];
 
2500
          if ([gvdep length] > 0)
 
2501
            {
 
2502
              [buf appendString: @" deprecated at "];
 
2503
              [buf appendString: gvdep];
 
2504
            }
 
2505
          if ([gvrem length] > 0)
 
2506
            {
 
2507
              [buf appendString: @" removed at "];
 
2508
              [buf appendString: gvrem];
 
2509
            }
 
2510
        }
 
2511
      [buf appendString:@"</div>\n"];
 
2512
      [buf appendString: @"<br />\n"];
 
2513
    }
 
2514
  else if ([gvadd length] > 0)
 
2515
    {
 
2516
      [buf appendString: indent];
 
2517
      [buf appendString: @"<div class=\"availability\">\n"];
 
2518
      [buf appendString: @"<b>Availability:</b> "];
 
2519
      [buf appendString: project];
 
2520
      [buf appendString: @" "];
 
2521
      [buf appendString: gvadd];
 
2522
      if ([gvdep length] > 0)
 
2523
        {
 
2524
          [buf appendString: @" deprecated at "];
 
2525
          [buf appendString: gvdep];
 
2526
        }
 
2527
      [buf appendString: @"<br />\n"];
 
2528
      if ([gvrem length] > 0)
 
2529
        {
 
2530
          [buf appendString: @" removed at "];
 
2531
          [buf appendString: gvrem];
 
2532
        }
 
2533
      [buf appendString:@"</div>\n"];
 
2534
      [buf appendString: @"<br />\n"];
 
2535
    }
 
2536
}
 
2537
 
2397
2538
/**
2398
2539
 * Try to make a link to the documentation for the supplied protocol.
2399
2540
 */