home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume2 / tools / part6 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  47.1 KB

  1. From: ihnp4!mnetor!clewis (Chris Lewis)
  2. Subject: Software Tools in Pascal (Part 5 of 6)
  3. Newsgroups: mod.sources
  4. Approved: john@genrad.UUCP
  5.  
  6. Mod.sources:  Volume 2, Issue 11
  7. Submitted by: ihnp4!mnetor!clewis (Chris Lewis)
  8.  
  9. #!/bin/sh
  10. echo 'Start of pack.out, part 05 of 06:'
  11. echo 'x - append.pascal'
  12. sed 's/^X//' > append.pascal << '/'
  13. X{
  14. X    Copyright (c) 1981
  15. X    By:    Bell Telephone Laboratories, Inc. and
  16. X        Whitesmiths, Ltd.,
  17. X
  18. X    This software is derived from the book
  19. X        "Software Tools In Pascal", by
  20. X        Brian W. Kernighan and P.J. Plauger
  21. X        Addison-Wesley, 1981
  22. X        ISBN 0-201-10342-7
  23. X
  24. X    Right is hereby granted to freely distribute or duplicate this
  25. X    software, providing distribution or duplication is not for profit
  26. X    or other commerical gain and that this copyright notice remains 
  27. X    intact.
  28. X}
  29. X{ Append -- append lines after "line" }
  30. Xsegment Append;
  31. X%include swtools
  32. X%include editcons
  33. X%include edittype
  34. X%include editproc
  35. X%include editref
  36. Xfunction Append;
  37. Xvar
  38. X    inLine: StringType;
  39. X    stat: STCode;
  40. X    done: Boolean;
  41. Xbegin
  42. X    if (glob) then
  43. X        stat := ERR
  44. X    else begin
  45. X        curLn := line;
  46. X        stat := OK;
  47. X        done := false;
  48. X        while (not done) and (stat = OK) do
  49. X            if (not GetLine(inLine, STDIN, MAXSTR)) then
  50. X                stat := ENDDATA
  51. X            else if (inLine[1] = PERIOD) and
  52. X              (inLine[2] = NEWLINE) then
  53. X                done := true
  54. X            else if (PutTxt(inLine) = ERR) then
  55. X                stat := ERR
  56. X    end;
  57. X    Append := stat
  58. Xend;
  59. /
  60. echo 'x - catsub.pascal'
  61. sed 's/^X//' > catsub.pascal << '/'
  62. X{
  63. X    Copyright (c) 1981
  64. X    By:    Bell Telephone Laboratories, Inc. and
  65. X        Whitesmiths, Ltd.,
  66. X
  67. X    This software is derived from the book
  68. X        "Software Tools In Pascal", by
  69. X        Brian W. Kernighan and P.J. Plauger
  70. X        Addison-Wesley, 1981
  71. X        ISBN 0-201-10342-7
  72. X
  73. X    Right is hereby granted to freely distribute or duplicate this
  74. X    software, providing distribution or duplication is not for profit
  75. X    or other commerical gain and that this copyright notice remains 
  76. X    intact.
  77. X}
  78. X{ CatSub -- add replacement text to end of new }
  79. Xsegment CatSub;
  80. X%include swtools
  81. X%include subdef
  82. X%include metadef
  83. Xprocedure CatSub;
  84. Xvar
  85. X    i,j: Integer;
  86. X    junk: Boolean;
  87. X    l: Integer;
  88. Xbegin
  89. X    i := 1;
  90. X    while (sub[i] <> ENDSTR) do begin
  91. X        if (sub[i] = DITTO) then begin
  92. X            l := Ord(sub[i+1]);
  93. X            if (l in [0..9]) then begin
  94. X                for j := metaTable[l].first to metaTable[l].last -1 do
  95. X                    junk := AddStr(lin[j], new, k, maxNew);
  96. X                i := i + 1
  97. X            end
  98. X            else
  99. X                for j := s1 to s2-1 do
  100. X                   junk := AddStr(lin[j], new, k, maxNew)
  101. X        end
  102. X        else
  103. X            junk := AddStr(sub[i], new, k, maxNew);
  104. X        i := i + 1
  105. X    end
  106. Xend;
  107. /
  108. echo 'x - ckp.pascal'
  109. sed 's/^X//' > ckp.pascal << '/'
  110. X{
  111. X    Copyright (c) 1981
  112. X    By:    Bell Telephone Laboratories, Inc. and
  113. X        Whitesmiths, Ltd.,
  114. X
  115. X    This software is derived from the book
  116. X        "Software Tools In Pascal", by
  117. X        Brian W. Kernighan and P.J. Plauger
  118. X        Addison-Wesley, 1981
  119. X        ISBN 0-201-10342-7
  120. X
  121. X    Right is hereby granted to freely distribute or duplicate this
  122. X    software, providing distribution or duplication is not for profit
  123. X    or other commerical gain and that this copyright notice remains 
  124. X    intact.
  125. X}
  126. X{ CkP -- check for "p" after command }
  127. Xsegment CkP;
  128. X%include swtools
  129. X%include editcons
  130. X%include edittype
  131. X%include editproc
  132. X%include editref
  133. Xfunction CkP;
  134. Xbegin
  135. X    SkipBl(lin, i);
  136. X    if (lin[i] = PCMD) then begin
  137. X        i := i + 1;
  138. X        pFlag := true
  139. X    end
  140. X    else
  141. X        pFlag := false;
  142. X    if (lin[i] = NEWLINE) then
  143. X        status := OK
  144. X    else
  145. X        status := ERR;
  146. X    CkP := status
  147. Xend;
  148. /
  149. echo 'x - cscopy.pascal'
  150. sed 's/^X//' > cscopy.pascal << '/'
  151. X{
  152. X    Copyright (c) 1981
  153. X    By:    Bell Telephone Laboratories, Inc. and
  154. X        Whitesmiths, Ltd.,
  155. X
  156. X    This software is derived from the book
  157. X        "Software Tools In Pascal", by
  158. X        Brian W. Kernighan and P.J. Plauger
  159. X        Addison-Wesley, 1981
  160. X        ISBN 0-201-10342-7
  161. X
  162. X    Right is hereby granted to freely distribute or duplicate this
  163. X    software, providing distribution or duplication is not for profit
  164. X    or other commerical gain and that this copyright notice remains 
  165. X    intact.
  166. X}
  167. X{ CSCopy -- copy cb[i]... to string s }
  168. Xsegment CSCopy;
  169. X%include swtools
  170. X%include defdef
  171. X%include defref
  172. X%include defproc
  173. Xprocedure CSCopy;
  174. Xvar
  175. X    j: Integer;
  176. Xbegin
  177. X    j := 1;
  178. X    while (cb[i] <> ENDSTR) do begin
  179. X        s[j] := cb[i];
  180. X        i := i + 1;
  181. X        j := j + 1
  182. X    end;
  183. X    s[j] := ENDSTR
  184. Xend;
  185. /
  186. echo 'x - ctoi.pascal'
  187. sed 's/^X//' > ctoi.pascal << '/'
  188. X{
  189. X    Copyright (c) 1981
  190. X    By:    Bell Telephone Laboratories, Inc. and
  191. X        Whitesmiths, Ltd.,
  192. X
  193. X    This software is derived from the book
  194. X        "Software Tools In Pascal", by
  195. X        Brian W. Kernighan and P.J. Plauger
  196. X        Addison-Wesley, 1981
  197. X        ISBN 0-201-10342-7
  198. X
  199. X    Right is hereby granted to freely distribute or duplicate this
  200. X    software, providing distribution or duplication is not for profit
  201. X    or other commerical gain and that this copyright notice remains 
  202. X    intact.
  203. X}
  204. X{ CToI -- convert string at s[i] to integer, increment i }
  205. Xsegment ctoi;
  206. X%include swtools
  207. Xfunction CToI;
  208. Xvar
  209. X    n, sign: Integer;
  210. Xbegin
  211. X    while (s[i] = BLANK) or (s[i] = TAB) do
  212. X        i := i + 1;
  213. X    if (s[i] = MINUS) then
  214. X        sign := -1
  215. X    else
  216. X        sign := 1;
  217. X    if (s[i] = MINUS) or (s[i] = PLUS) then
  218. X        i := i + 1;
  219. X    n := 0;
  220. X    while(IsDigit(s[i])) do begin
  221. X        n := 10 * n + Ord(s[i]) - Ord(DIG0);
  222. X        i := i + 1;
  223. X    end;
  224. X    CToI := sign * n;
  225. Xend;
  226. /
  227. echo 'x - dochq.pascal'
  228. sed 's/^X//' > dochq.pascal << '/'
  229. X{
  230. X    Copyright (c) 1981
  231. X    By:    Bell Telephone Laboratories, Inc. and
  232. X        Whitesmiths, Ltd.,
  233. X
  234. X    This software is derived from the book
  235. X        "Software Tools In Pascal", by
  236. X        Brian W. Kernighan and P.J. Plauger
  237. X        Addison-Wesley, 1981
  238. X        ISBN 0-201-10342-7
  239. X
  240. X    Right is hereby granted to freely distribute or duplicate this
  241. X    software, providing distribution or duplication is not for profit
  242. X    or other commerical gain and that this copyright notice remains 
  243. X    intact.
  244. X}
  245. X{ DoChq -- Change quote characters }
  246. Xsegment DoChq;
  247. X%include swtools
  248. X%include macdefs
  249. X%include macproc
  250. Xprocedure DoChq;
  251. Xvar
  252. X    temp: StringType;
  253. X    n: Integer;
  254. Xbegin
  255. X    CsCopy(evalStk, argStk[i+2], temp);
  256. X    n := StrLength(temp);
  257. X    if (n <= 0) then begin
  258. X        lQuote := GRAVE;
  259. X        rQuote := ACUTE;
  260. X    end {elseif}
  261. X    else if (n = 1) then begin
  262. X        lQuote := temp[1];
  263. X        rQuote := lQuote
  264. X    end {elseif}
  265. X    else begin
  266. X        lQuote := temp[1];
  267. X        rQuote := temp[2]
  268. X    end {if}
  269. Xend {DoCkq};
  270. /
  271. echo 'x - dodef.pascal'
  272. sed 's/^X//' > dodef.pascal << '/'
  273. X{
  274. X    Copyright (c) 1981
  275. X    By:    Bell Telephone Laboratories, Inc. and
  276. X        Whitesmiths, Ltd.,
  277. X
  278. X    This software is derived from the book
  279. X        "Software Tools In Pascal", by
  280. X        Brian W. Kernighan and P.J. Plauger
  281. X        Addison-Wesley, 1981
  282. X        ISBN 0-201-10342-7
  283. X
  284. X    Right is hereby granted to freely distribute or duplicate this
  285. X    software, providing distribution or duplication is not for profit
  286. X    or other commerical gain and that this copyright notice remains 
  287. X    intact.
  288. X}
  289. X{ DoDef -- install definition in table }
  290. Xsegment DoDef;
  291. X%include swtools
  292. X%include macdefs
  293. X%include macproc
  294. Xprocedure DoDef;
  295. Xvar
  296. X    temp1, temp2: StringType;
  297. Xbegin
  298. X    if (j - i > 2) then begin
  299. X        CsCopy(evalStk, argStk[i+2], temp1);
  300. X        CsCopy(evalStk, argStk[i+3], temp2);
  301. X        Install(temp1, temp2, MACTYPE)
  302. X    end {if};
  303. Xend {DoDef};
  304. /
  305. echo 'x - doglob.pascal'
  306. sed 's/^X//' > doglob.pascal << '/'
  307. X{
  308. X    Copyright (c) 1981
  309. X    By:    Bell Telephone Laboratories, Inc. and
  310. X        Whitesmiths, Ltd.,
  311. X
  312. X    This software is derived from the book
  313. X        "Software Tools In Pascal", by
  314. X        Brian W. Kernighan and P.J. Plauger
  315. X        Addison-Wesley, 1981
  316. X        ISBN 0-201-10342-7
  317. X
  318. X    Right is hereby granted to freely distribute or duplicate this
  319. X    software, providing distribution or duplication is not for profit
  320. X    or other commerical gain and that this copyright notice remains 
  321. X    intact.
  322. X}
  323. X{ DoGlob -- do command at lin[i] on all marked lines }
  324. Xsegment DoGlob;
  325. X%include swtools
  326. X%include editcons
  327. X%include edittype
  328. X%include editproc
  329. X%include editref
  330. Xfunction DoGlob;
  331. Xvar
  332. X    count, iStart, n: Integer;
  333. Xbegin
  334. X    status := OK;
  335. X    count := 0;
  336. X    n := line1;
  337. X    iStart := i;
  338. X    repeat
  339. X        if (GetMark(n)) then begin
  340. X            PutMark(n, false);
  341. X            curLn := n;
  342. X            curSave := curLn;
  343. X            i := iStart;
  344. X            if (GetList(lin, i, status) = OK) then
  345. X                if (DoCmd(lin, i, true, status) = OK) then
  346. X                    count := 0;
  347. X        end
  348. X        else begin
  349. X            n := NextLn(n);
  350. X            count := count + 1
  351. X        end
  352. X    until (count > lastLn) or (status <> OK);
  353. X    DoGlob := status
  354. Xend;
  355. /
  356. echo 'x - doif.pascal'
  357. sed 's/^X//' > doif.pascal << '/'
  358. X{
  359. X    Copyright (c) 1981
  360. X    By:    Bell Telephone Laboratories, Inc. and
  361. X        Whitesmiths, Ltd.,
  362. X
  363. X    This software is derived from the book
  364. X        "Software Tools In Pascal", by
  365. X        Brian W. Kernighan and P.J. Plauger
  366. X        Addison-Wesley, 1981
  367. X        ISBN 0-201-10342-7
  368. X
  369. X    Right is hereby granted to freely distribute or duplicate this
  370. X    software, providing distribution or duplication is not for profit
  371. X    or other commerical gain and that this copyright notice remains 
  372. X    intact.
  373. X}
  374. X{ DoIf -- Select one of two arguments }
  375. Xsegment DoIf;
  376. X%include swtools
  377. X%include macdefs
  378. X%include macproc
  379. Xprocedure DoIf;
  380. Xvar
  381. X    temp1, temp2, temp3: StringType;
  382. Xbegin
  383. X    if (j - i >= 4) then begin
  384. X        CsCopy(evalStk, argStk[i+2], temp1);
  385. X        CsCopy(evalStk, argStk[i+3], temp2);
  386. X        if (Equal(temp1, temp2)) then
  387. X            CsCopy(evalStk, argStk[i+4], temp3)
  388. X        else if (j - i >= 5) then
  389. X            CsCopy(evalStk, argStk[i+5], temp3)
  390. X        else
  391. X            temp3[1] := ENDSTR;
  392. X        PBStr(temp3)
  393. X    end {if}
  394. Xend {DoIf};
  395. /
  396. echo 'x - dolen.pascal'
  397. sed 's/^X//' > dolen.pascal << '/'
  398. X{
  399. X    Copyright (c) 1981
  400. X    By:    Bell Telephone Laboratories, Inc. and
  401. X        Whitesmiths, Ltd.,
  402. X
  403. X    This software is derived from the book
  404. X        "Software Tools In Pascal", by
  405. X        Brian W. Kernighan and P.J. Plauger
  406. X        Addison-Wesley, 1981
  407. X        ISBN 0-201-10342-7
  408. X
  409. X    Right is hereby granted to freely distribute or duplicate this
  410. X    software, providing distribution or duplication is not for profit
  411. X    or other commerical gain and that this copyright notice remains 
  412. X    intact.
  413. X}
  414. X{ DoLen -- Return length of argument }
  415. Xsegment DoLen;
  416. X%include swtools
  417. X%include macdefs
  418. X%include macproc
  419. Xprocedure DoLen;
  420. Xvar
  421. X    temp: StringType;
  422. Xbegin
  423. X    if (j - i > 1) then begin
  424. X        CsCopy(evalStk, argStk[i+2], temp);
  425. X        PBNum(StrLength(temp))
  426. X    end {then}
  427. X    else
  428. X        PBNum(0)
  429. Xend {DoLen};
  430. /
  431. echo 'x - dolprint.pascal'
  432. sed 's/^X//' > dolprint.pascal << '/'
  433. X{
  434. X    Copyright (c) 1982
  435. X    By:    Chris Lewis
  436. X
  437. X    Right is hereby granted to freely distribute or duplicate this
  438. X    software, providing distribution or duplication is not for profit
  439. X    or other commerical gain and that this copyright notice remains 
  440. X    intact.
  441. X}
  442. X{ DoLPrint -- print lines n1 thru n2 unambiguously }
  443. Xsegment DoLPrint;
  444. X%include swtools
  445. X%include editcons
  446. X%include edittype
  447. X%include editproc
  448. X%include editref
  449. X%include chardef
  450. Xfunction DoLPrint;
  451. Xvar
  452. X    lp: Integer;
  453. X    i: Integer;
  454. X    line: StringType;
  455. Xbegin
  456. X    if (n1 < 0) then
  457. X        DoLPrint := ERR
  458. X    else begin
  459. X        for i := n1 to n2 do begin
  460. X            GetTxt(i, line);
  461. X            if OptIsOn(numFlag) then begin
  462. X                PutDec(i, 5);
  463. X                PutC(BLANK)
  464. X            end;
  465. X            for lp := 1 to StrLength(line) do begin
  466. X                if CharClass(line[lp]) <> [] then
  467. X                    PutC(line[lp])
  468. X                else if line[lp] = NEWLINE then
  469. X                    PutC(NEWLINE)
  470. X                else begin
  471. X                    PutC(BACKSLASH);
  472. X                    PutDec(Ord(line[lp]), 3)
  473. X                end
  474. X           end
  475. X        end;
  476. X        curLn := n2;
  477. X        DoLPrint := OK
  478. X    end
  479. Xend;
  480. /
  481. echo 'x - doprint.pascal'
  482. sed 's/^X//' > doprint.pascal << '/'
  483. X{
  484. X    Copyright (c) 1981
  485. X    By:    Bell Telephone Laboratories, Inc. and
  486. X        Whitesmiths, Ltd.,
  487. X
  488. X    This software is derived from the book
  489. X        "Software Tools In Pascal", by
  490. X        Brian W. Kernighan and P.J. Plauger
  491. X        Addison-Wesley, 1981
  492. X        ISBN 0-201-10342-7
  493. X
  494. X    Right is hereby granted to freely distribute or duplicate this
  495. X    software, providing distribution or duplication is not for profit
  496. X    or other commerical gain and that this copyright notice remains 
  497. X    intact.
  498. X}
  499. X{ DoPrint -- print lines n1 thru n2 }
  500. Xsegment DoPrint;
  501. X%include swtools
  502. X%include editcons
  503. X%include edittype
  504. X%include editproc
  505. X%include editref
  506. Xfunction DoPrint;
  507. Xvar
  508. X    i: Integer;
  509. X    line: StringType;
  510. Xbegin
  511. X    if (n1 < 0) then
  512. X        DoPrint := ERR
  513. X    else begin
  514. X        for i := n1 to n2 do begin
  515. X            GetTxt(i, line);
  516. X            if OptIsOn(numFlag) then begin
  517. X                PutDec(i, 5);
  518. X                PutC(BLANK)
  519. X            end;
  520. X            PutStr(line, STDOUT)
  521. X        end;
  522. X        curLn := n2;
  523. X        DoPrint := OK
  524. X    end
  525. Xend;
  526. /
  527. echo 'x - dowrite.pascal'
  528. sed 's/^X//' > dowrite.pascal << '/'
  529. X{
  530. X    Copyright (c) 1981
  531. X    By:    Bell Telephone Laboratories, Inc. and
  532. X        Whitesmiths, Ltd.,
  533. X
  534. X    This software is derived from the book
  535. X        "Software Tools In Pascal", by
  536. X        Brian W. Kernighan and P.J. Plauger
  537. X        Addison-Wesley, 1981
  538. X        ISBN 0-201-10342-7
  539. X
  540. X    Right is hereby granted to freely distribute or duplicate this
  541. X    software, providing distribution or duplication is not for profit
  542. X    or other commerical gain and that this copyright notice remains 
  543. X    intact.
  544. X}
  545. X{ DoWrite -- write lines n1..n2 into file }
  546. Xsegment DoWrite;
  547. X%include swtools
  548. X%include editcons
  549. X%include edittype
  550. X%include editproc
  551. X%include editref
  552. Xfunction DoWrite;
  553. Xvar
  554. X    i: Integer;
  555. X    fd: FileDesc;
  556. X    line: StringType;
  557. Xbegin
  558. X    fd := FCreate(fil, IOWRITE);
  559. X    if (fd = IOERROR) then
  560. X        DoWrite := ERR
  561. X    else begin
  562. X        for i := n1 to n2 do begin
  563. X            GetTxt(i, line);
  564. X            PutStr(line,fd)
  565. X        end;
  566. X        FClose(fd);
  567. X        PutDec(n2-n1+1, 1);
  568. X        PutC(NEWLINE);
  569. X        DoWrite := OK
  570. X    end
  571. Xend;
  572. /
  573. echo 'x - esc.pascal'
  574. sed 's/^X//' > esc.pascal << '/'
  575. X{
  576. X    Copyright (c) 1981
  577. X    By:    Bell Telephone Laboratories, Inc. and
  578. X        Whitesmiths, Ltd.,
  579. X
  580. X    This software is derived from the book
  581. X        "Software Tools In Pascal", by
  582. X        Brian W. Kernighan and P.J. Plauger
  583. X        Addison-Wesley, 1981
  584. X        ISBN 0-201-10342-7
  585. X
  586. X    Right is hereby granted to freely distribute or duplicate this
  587. X    software, providing distribution or duplication is not for profit
  588. X    or other commerical gain and that this copyright notice remains 
  589. X    intact.
  590. X}
  591. X{ Esc -- map s(i) into escaped characters, increment i }
  592. Xsegment Esc;
  593. X%include swtools
  594. Xfunction Esc;
  595. Xbegin
  596. X    if (s[i] <> ESCAPE) then
  597. X        Esc := s[i]
  598. X    else if (s[i+1] = ENDSTR) then { @ not special at end }
  599. X        Esc := ESCAPE
  600. X    else begin
  601. X        i := i + 1;
  602. X        if (s[i] = LETN) or (s[i] = BIGN) then
  603. X            Esc := NEWLINE
  604. X        else if (s[i] = TAB) then
  605. X            Esc := TAB
  606. X        else
  607. X            Esc := s[i]
  608. X    end
  609. Xend;
  610. /
  611. echo 'x - expr.pascal'
  612. sed 's/^X//' > expr.pascal << '/'
  613. X{
  614. X    Copyright (c) 1981
  615. X    By:    Bell Telephone Laboratories, Inc. and
  616. X        Whitesmiths, Ltd.,
  617. X
  618. X    This software is derived from the book
  619. X        "Software Tools In Pascal", by
  620. X        Brian W. Kernighan and P.J. Plauger
  621. X        Addison-Wesley, 1981
  622. X        ISBN 0-201-10342-7
  623. X
  624. X    Right is hereby granted to freely distribute or duplicate this
  625. X    software, providing distribution or duplication is not for profit
  626. X    or other commerical gain and that this copyright notice remains 
  627. X    intact.
  628. X}
  629. X{ Expr -- Recursive expression evaluation }
  630. Xsegment Expr;
  631. X%include swtools
  632. X%include macdefs
  633. X%include macproc
  634. Xfunction Expr;
  635. Xvar
  636. X    v: Integer;
  637. X    t: CharType;
  638. Xbegin
  639. X    v := Term(s, i);
  640. X    t := GNBChar(s, i);
  641. X    while (t in [PLUS, MINUS]) do begin
  642. X        i := i + 1;
  643. X        if (t = PLUS) then
  644. X            v := v + Term(s, i)
  645. X        else
  646. X            v := v - Term(s, i);
  647. X        t := GNBChar(s, i)
  648. X    end {while};
  649. X    Expr := v
  650. Xend {Expr};
  651. /
  652. echo 'x - factor.pascal'
  653. sed 's/^X//' > factor.pascal << '/'
  654. X{
  655. X    Copyright (c) 1981
  656. X    By:    Bell Telephone Laboratories, Inc. and
  657. X        Whitesmiths, Ltd.,
  658. X
  659. X    This software is derived from the book
  660. X        "Software Tools In Pascal", by
  661. X        Brian W. Kernighan and P.J. Plauger
  662. X        Addison-Wesley, 1981
  663. X        ISBN 0-201-10342-7
  664. X
  665. X    Right is hereby granted to freely distribute or duplicate this
  666. X    software, providing distribution or duplication is not for profit
  667. X    or other commerical gain and that this copyright notice remains 
  668. X    intact.
  669. X}
  670. X{ Factor -- Evaluate factor of arithmetic expression }
  671. Xsegment Factor;
  672. X%include swtools
  673. X%include macdefs
  674. X%include macproc
  675. Xfunction Factor;
  676. Xbegin
  677. X    if (GNBChar(s, i) = LPAREN) then begin
  678. X        i := i + 1;
  679. X        Factor := Expr(s, i);
  680. X        if (GNBChar(s, i) = RPAREN) then
  681. X            i := i + 1
  682. X        else
  683. X            Message('Macro: missing paren in expr')
  684. X    end {then}
  685. X    else
  686. X        Factor := CToI(s, i)
  687. Xend {Factor};
  688. /
  689. echo 'x - getccl.pascal'
  690. sed 's/^X//' > getccl.pascal << '/'
  691. X{
  692. X    Copyright (c) 1981
  693. X    By:    Bell Telephone Laboratories, Inc. and
  694. X        Whitesmiths, Ltd.,
  695. X
  696. X    This software is derived from the book
  697. X        "Software Tools In Pascal", by
  698. X        Brian W. Kernighan and P.J. Plauger
  699. X        Addison-Wesley, 1981
  700. X        ISBN 0-201-10342-7
  701. X
  702. X    Right is hereby granted to freely distribute or duplicate this
  703. X    software, providing distribution or duplication is not for profit
  704. X    or other commerical gain and that this copyright notice remains 
  705. X    intact.
  706. X}
  707. X{ GetCCL -- expand char class at arg[i] into pat[j  }
  708. Xsegment GetCCL;
  709. X%include swtools
  710. X%include patdef
  711. Xfunction GetCCL;
  712. Xvar
  713. X    jStart: Integer;
  714. X    junk: Boolean;
  715. Xbegin
  716. X    i := i + 1; {skip over CCL}
  717. X    if (arg[i] = NEGATE) then begin
  718. X        junk := AddStr(NCCL, pat, j, MAXPAT);
  719. X        i := i + 1
  720. X    end
  721. X    else
  722. X        junk := AddStr(CCL, pat, j, MAXPAT);
  723. X    jStart := j;
  724. X    junk := AddStr(ENDSTR, pat, j, MAXPAT);  {make room for count}
  725. X    DoDash(CCLEND, arg, i, pat, j, MAXPAT);
  726. X    { putting an integer into a char only works if the number is les
  727. X         than 255}
  728. X    pat[jStart] := Chr(j - jStart - 1);
  729. X    GetCCL := (arg[i] = CCLEND)
  730. Xend;
  731. /
  732. echo 'x - getpbc.pascal'
  733. sed 's/^X//' > getpbc.pascal << '/'
  734. X{
  735. X    Copyright (c) 1981
  736. X    By:    Bell Telephone Laboratories, Inc. and
  737. X        Whitesmiths, Ltd.,
  738. X
  739. X    This software is derived from the book
  740. X        "Software Tools In Pascal", by
  741. X        Brian W. Kernighan and P.J. Plauger
  742. X        Addison-Wesley, 1981
  743. X        ISBN 0-201-10342-7
  744. X
  745. X    Right is hereby granted to freely distribute or duplicate this
  746. X    software, providing distribution or duplication is not for profit
  747. X    or other commerical gain and that this copyright notice remains 
  748. X    intact.
  749. X}
  750. X{ GetPBC -- get a (possibly pushed back) character }
  751. Xsegment GetPBC;
  752. X%include swtools
  753. X%include defdef
  754. X%include defref
  755. X%include defproc
  756. Xfunction GetPBC;
  757. Xbegin
  758. X    if (bp > 0) then
  759. X        c := buf[bp]
  760. X    else begin
  761. X        bp := 1;
  762. X        buf[bp] := GetC(c);
  763. X    end;
  764. X    if (c <> ENDFILE) then
  765. X        bp := bp - 1;
  766. X    GetPBC := c
  767. Xend;
  768. /
  769. echo 'x - getrhs.pascal'
  770. sed 's/^X//' > getrhs.pascal << '/'
  771. X{
  772. X    Copyright (c) 1981
  773. X    By:    Bell Telephone Laboratories, Inc. and
  774. X        Whitesmiths, Ltd.,
  775. X
  776. X    This software is derived from the book
  777. X        "Software Tools In Pascal", by
  778. X        Brian W. Kernighan and P.J. Plauger
  779. X        Addison-Wesley, 1981
  780. X        ISBN 0-201-10342-7
  781. X
  782. X    Right is hereby granted to freely distribute or duplicate this
  783. X    software, providing distribution or duplication is not for profit
  784. X    or other commerical gain and that this copyright notice remains 
  785. X    intact.
  786. X}
  787. X{ GetRHS -- get right hand side of "s" command }
  788. Xsegment GetRHS;
  789. X%include swtools
  790. X%include editcons
  791. X%include edittype
  792. X%include editproc
  793. X%include editref
  794. X%include subdef
  795. Xfunction GetRHS;
  796. Xbegin
  797. X    GetRHS := OK;
  798. X    if (lin[i] = ENDSTR) then
  799. X        GetRHS := ERR
  800. X    else if (lin[i+1] = ENDSTR) then
  801. X        GetRHS := ERR
  802. X    else begin
  803. X        i := MakeSub(lin, i+1, lin[i], sub);
  804. X        if (i = 0) then
  805. X            GetRHS := ERR
  806. X        else if (lin[i+1] = LETG) then begin
  807. X            i := i + 1;
  808. X            gFlag := true
  809. X        end
  810. X        else
  811. X            gFlag := false
  812. X    end
  813. Xend;
  814. /
  815. echo 'x - gettok.pascal'
  816. sed 's/^X//' > gettok.pascal << '/'
  817. X{
  818. X    Copyright (c) 1981
  819. X    By:    Bell Telephone Laboratories, Inc. and
  820. X        Whitesmiths, Ltd.,
  821. X
  822. X    This software is derived from the book
  823. X        "Software Tools In Pascal", by
  824. X        Brian W. Kernighan and P.J. Plauger
  825. X        Addison-Wesley, 1981
  826. X        ISBN 0-201-10342-7
  827. X
  828. X    Right is hereby granted to freely distribute or duplicate this
  829. X    software, providing distribution or duplication is not for profit
  830. X    or other commerical gain and that this copyright notice remains 
  831. X    intact.
  832. X}
  833. X{ GetTok -- get token for define }
  834. Xsegment GetTok;
  835. X%include swtools
  836. X%include defdef
  837. X%include defref
  838. X%include defproc
  839. Xfunction GetTok;
  840. Xvar
  841. X    i: Integer;
  842. X    done: Boolean;
  843. X    junk: CharType;
  844. Xbegin
  845. X    i := 1;
  846. X    done := false;
  847. X    while (not done) and (i < tokSize) do begin
  848. X        token[i] := GetPBC(junk);
  849. X        if (IsAlphaNum(token[i])) then
  850. X            i := i + 1
  851. X        else
  852. X            done := true
  853. X    end;
  854. X    if (i >= tokSize) then
  855. X        Error('define: token too long');
  856. X    if (i > 1) then begin    { some alpha was seen }
  857. X        PutBack(token[i]);
  858. X        i := i - 1
  859. X    end;
  860. X    { else single non-alphanumeric }
  861. X    token[i+1] := ENDSTR;
  862. X    GetTok := token[1]
  863. Xend;
  864. /
  865. echo 'x - getword.pascal'
  866. sed 's/^X//' > getword.pascal << '/'
  867. X{
  868. X    Copyright (c) 1981
  869. X    By:    Bell Telephone Laboratories, Inc. and
  870. X        Whitesmiths, Ltd.,
  871. X
  872. X    This software is derived from the book
  873. X        "Software Tools In Pascal", by
  874. X        Brian W. Kernighan and P.J. Plauger
  875. X        Addison-Wesley, 1981
  876. X        ISBN 0-201-10342-7
  877. X
  878. X    Right is hereby granted to freely distribute or duplicate this
  879. X    software, providing distribution or duplication is not for profit
  880. X    or other commerical gain and that this copyright notice remains 
  881. X    intact.
  882. X}
  883. X{ getword -- get word form s(i) into out }
  884. Xsegment GetWord;
  885. X%include swtools
  886. Xfunction GetWord;
  887. Xvar
  888. X    j: Integer;
  889. Xbegin
  890. X    while (s[i] in [BLANK,TAB,NEWLINE]) do
  891. X        i := i + 1;
  892. X    j := 1;
  893. X    while (not (s[i] in [ENDSTR,BLANK,TAB,NEWLINE])) do begin
  894. X        out[j] := s[i];
  895. X        i := i + 1;
  896. X        j := j + 1
  897. X    end;
  898. X    out[j] := ENDSTR;
  899. X    if (j = 1) then
  900. X        GetWord := 0
  901. X    else
  902. X        GetWord := i
  903. Xend;
  904. /
  905. echo 'x - grep.pascal'
  906. sed 's/^X//' > grep.pascal << '/'
  907. X{
  908. X    Copyright (c) 1981
  909. X    By:    Bell Telephone Laboratories, Inc. and
  910. X        Whitesmiths, Ltd.,
  911. X
  912. X    This software is derived from the book
  913. X        "Software Tools In Pascal", by
  914. X        Brian W. Kernighan and P.J. Plauger
  915. X        Addison-Wesley, 1981
  916. X        ISBN 0-201-10342-7
  917. X
  918. X    Right is hereby granted to freely distribute or duplicate this
  919. X    software, providing distribution or duplication is not for profit
  920. X    or other commerical gain and that this copyright notice remains 
  921. X    intact.
  922. X}
  923. X{ Grep -- Globally look for Regular Expressions and Print }
  924. Xprogram Grep;
  925. X%include swtools
  926. X%include patdef
  927. X%include matchdef
  928. Xvar
  929. X    arg, lin, pat: StringType;
  930. X    returnCode: Integer;
  931. Xbegin
  932. X    ToolInit;
  933. X    returnCode := 4;
  934. X    if (not GetArg(1, arg, MAXSTR)) then
  935. X        Error('Usage: Grep pattern');
  936. X    if (not GetPat(arg, pat)) then
  937. X        Error('Grep: illegal pattern');
  938. X    while (GetLine(lin, STDIN, MAXSTR)) do
  939. X        if (Match(lin, pat)) then begin
  940. X            returnCode := 0;
  941. X            PutStr(lin, STDOUT)
  942. X        end;
  943. X    ProgExit(returnCode)
  944. Xend.
  945. /
  946. echo 'x - includ.pascal'
  947. sed 's/^X//' > includ.pascal << '/'
  948. X{
  949. X    Copyright (c) 1981
  950. X    By:    Bell Telephone Laboratories, Inc. and
  951. X        Whitesmiths, Ltd.,
  952. X
  953. X    This software is derived from the book
  954. X        "Software Tools In Pascal", by
  955. X        Brian W. Kernighan and P.J. Plauger
  956. X        Addison-Wesley, 1981
  957. X        ISBN 0-201-10342-7
  958. X
  959. X    Right is hereby granted to freely distribute or duplicate this
  960. X    software, providing distribution or duplication is not for profit
  961. X    or other commerical gain and that this copyright notice remains 
  962. X    intact.
  963. X}
  964. X{ Includ -- replace include file by contents }
  965. XProgram Includ;
  966. X%include swtools
  967. Xvar incl: StringType;
  968. X{ FInclude -- include file desc f }
  969. Xprocedure FInclude(f: FileDesc);
  970. Xvar
  971. X    line,strg: StringType;
  972. X    loc, i:   Integer;
  973. X    f1: FileDesc;
  974. Xbegin
  975. X    while(GetLine(line,f,MAXSTR)) do begin
  976. X        loc := GetWord(line,1,strg);
  977. X        if (not Equal(strg,incl)) then
  978. X            PutStr(line,STDOUT)
  979. X        else begin
  980. X            if GetFid(line, loc, strg) then begin
  981. X                f1 := MustOpen(strg,IOREAD);
  982. X                FInclude(f1);
  983. X                FClose(f1);
  984. X            end
  985. X            else
  986. X                Error('Bad file name');
  987. X        end
  988. X    end
  989. Xend;
  990. Xbegin
  991. X    ToolInit;
  992. X    CvtSST('#include', incl);
  993. X    FInclude(STDIN)
  994. Xend.
  995. /
  996. echo 'x - initmacr.pascal'
  997. sed 's/^X//' > initmacr.pascal << '/'
  998. X{
  999. X    Copyright (c) 1981
  1000. X    By:    Bell Telephone Laboratories, Inc. and
  1001. X        Whitesmiths, Ltd.,
  1002. X
  1003. X    This software is derived from the book
  1004. X        "Software Tools In Pascal", by
  1005. X        Brian W. Kernighan and P.J. Plauger
  1006. X        Addison-Wesley, 1981
  1007. X        ISBN 0-201-10342-7
  1008. X
  1009. X    Right is hereby granted to freely distribute or duplicate this
  1010. X    software, providing distribution or duplication is not for profit
  1011. X    or other commerical gain and that this copyright notice remains 
  1012. X    intact.
  1013. X}
  1014. X{ InitMacro -- initialize variables for macro }
  1015. Xsegment InitMacro;
  1016. X%include swtools
  1017. X%include macdefs
  1018. X%include macproc
  1019. Xprocedure InitMacro;
  1020. Xbegin
  1021. X    null[1] := ENDSTR;
  1022. X    CvtSST('define', defName);
  1023. X    CvtSST('substr', subName);
  1024. X    CvtSST('expr', exprName);
  1025. X    CvtSST('ifelse', ifName);
  1026. X    CvtSST('len', lenName);
  1027. X    CvtSST('changeq', chqName);
  1028. X    bp := 0;  { push back buffer pointer }
  1029. X    traceing := false;
  1030. X    if NArgs > 0 then traceing := true;
  1031. X    InitHash;
  1032. X    lQuote := GRAVE;
  1033. X    rQuote := ACUTE;
  1034. Xend {InitMacro};
  1035. /
  1036. echo 'x - kwic.exec'
  1037. sed 's/^X//' > kwic.exec << '/'
  1038. X&CONTROL OFF
  1039. X&IF &1 EQ ? &GOTO -EXPLAIN
  1040. XSTATE &1 &2 *
  1041. X&IF &RETCODE NE 0 &GOTO -NOFILE
  1042. XKWIC < &1 &2 > KWIC TEMP1 A
  1043. X&IF &RETCODE NE 0 &GOTO -DIED
  1044. XBNRSORT KWIC TEMP1 KWIC TEMP2 AP 1 20
  1045. X&IF &RETCODE NE 0 &GOTO -DIED
  1046. XUNROTATE < KWIC TEMP2 > &1 KWIC A
  1047. X&IF &RETCODE NE 0 &GOTO -DIED
  1048. XERASE KWIC TEMP1
  1049. XERASE KWIC TEMP2
  1050. X&EXIT 0
  1051. X-NOFILE
  1052. X&TYPE FILE &1 &2 DOES NOT EXIST
  1053. X&EXIT 4
  1054. X-DIED
  1055. XERASE KWIC TEMP1
  1056. XERASE KWIC TEMP2
  1057. X&TYPE ONE OF THE KWIC PASSES DIED
  1058. X&EXIT 8
  1059. X-EXPLAIN
  1060. X&BEGTYPE
  1061. X    KWIC INNAME INTYPE
  1062. X
  1063. X       Kwic is an EXEC that produces a "Keyword in Context" Index.
  1064. X    Kwic takes the file specified by inFile inType and creates
  1065. X    the index in a file called "inFile KWIC"
  1066. X
  1067. X       The first "inName inFile" encountered in your search path is
  1068. X    used.  "inFile KWIC" is created on your A disk.
  1069. X
  1070. X       It is recommended that you never "KWIC" a "KWIC" file.
  1071. X&END
  1072. /
  1073. echo 'x - lndelete.pascal'
  1074. sed 's/^X//' > lndelete.pascal << '/'
  1075. X{
  1076. X    Copyright (c) 1981
  1077. X    By:    Bell Telephone Laboratories, Inc. and
  1078. X        Whitesmiths, Ltd.,
  1079. X
  1080. X    This software is derived from the book
  1081. X        "Software Tools In Pascal", by
  1082. X        Brian W. Kernighan and P.J. Plauger
  1083. X        Addison-Wesley, 1981
  1084. X        ISBN 0-201-10342-7
  1085. X
  1086. X    Right is hereby granted to freely distribute or duplicate this
  1087. X    software, providing distribution or duplication is not for profit
  1088. X    or other commerical gain and that this copyright notice remains 
  1089. X    intact.
  1090. X}
  1091. X{ LnDelete -- delete lines n1 thru n2 }
  1092. Xsegment LnDelete;
  1093. X%include swtools
  1094. X%include editcons
  1095. X%include edittype
  1096. X%include editproc
  1097. X%include editref
  1098. Xfunction LnDelete;
  1099. Xbegin
  1100. X    if (n1 <= 0) then
  1101. X        status := ERR
  1102. X    else begin
  1103. X        BlkMove(n1, n2, lastLn);
  1104. X        lastLn := lastLn - (n2 - n1 + 1);
  1105. X        curLn := PrevLn(n1);
  1106. X        status := OK
  1107. X    end;
  1108. X    LnDelete := status
  1109. Xend;
  1110. /
  1111. echo 'x - locate.pascal'
  1112. sed 's/^X//' > locate.pascal << '/'
  1113. X{
  1114. X    Copyright (c) 1981
  1115. X    By:    Bell Telephone Laboratories, Inc. and
  1116. X        Whitesmiths, Ltd.,
  1117. X
  1118. X    This software is derived from the book
  1119. X        "Software Tools In Pascal", by
  1120. X        Brian W. Kernighan and P.J. Plauger
  1121. X        Addison-Wesley, 1981
  1122. X        ISBN 0-201-10342-7
  1123. X
  1124. X    Right is hereby granted to freely distribute or duplicate this
  1125. X    software, providing distribution or duplication is not for profit
  1126. X    or other commerical gain and that this copyright notice remains 
  1127. X    intact.
  1128. X}
  1129. X{ Locate -- look for c in character class at pat[offset] }
  1130. Xsegment Locate;
  1131. X%include swtools
  1132. X%include matchdef
  1133. Xfunction Locate;
  1134. Xvar
  1135. X    i: Integer;
  1136. Xbegin
  1137. X    { size of class is at pat[offset], characters follow }
  1138. X    Locate := false;
  1139. X    i := offset + Ord(pat[offset]);   { last position }
  1140. X    while (i > offset) do
  1141. X        if (c = pat[i]) then begin
  1142. X            locate := true;
  1143. X            i := offset { force loop termination }
  1144. X        end
  1145. X        else
  1146. X            i := i - 1
  1147. Xend;
  1148. /
  1149. echo 'x - lookup.pascal'
  1150. sed 's/^X//' > lookup.pascal << '/'
  1151. X{
  1152. X    Copyright (c) 1981
  1153. X    By:    Bell Telephone Laboratories, Inc. and
  1154. X        Whitesmiths, Ltd.,
  1155. X
  1156. X    This software is derived from the book
  1157. X        "Software Tools In Pascal", by
  1158. X        Brian W. Kernighan and P.J. Plauger
  1159. X        Addison-Wesley, 1981
  1160. X        ISBN 0-201-10342-7
  1161. X
  1162. X    Right is hereby granted to freely distribute or duplicate this
  1163. X    software, providing distribution or duplication is not for profit
  1164. X    or other commerical gain and that this copyright notice remains 
  1165. X    intact.
  1166. X}
  1167. X{ Lookup -- locate name, get defn and type from table }
  1168. Xsegment Lookup;
  1169. X%include swtools
  1170. X%include defdef
  1171. X%include defref
  1172. X%include defproc
  1173. Xfunction Lookup;
  1174. Xvar
  1175. X    p: ndPtr;
  1176. Xbegin
  1177. X    p := HashFind(name);
  1178. X    if (p = nil) then
  1179. X        Lookup := false
  1180. X    else begin
  1181. X        Lookup := true;
  1182. X        CSCopy(NDTable, p->.defn, defn);
  1183. X        t := p->.kind
  1184. X    end
  1185. Xend;
  1186. /
  1187. echo 'x - match.pascal'
  1188. sed 's/^X//' > match.pascal << '/'
  1189. X{
  1190. X    Copyright (c) 1981
  1191. X    By:    Bell Telephone Laboratories, Inc. and
  1192. X        Whitesmiths, Ltd.,
  1193. X
  1194. X    This software is derived from the book
  1195. X        "Software Tools In Pascal", by
  1196. X        Brian W. Kernighan and P.J. Plauger
  1197. X        Addison-Wesley, 1981
  1198. X        ISBN 0-201-10342-7
  1199. X
  1200. X    Right is hereby granted to freely distribute or duplicate this
  1201. X    software, providing distribution or duplication is not for profit
  1202. X    or other commerical gain and that this copyright notice remains 
  1203. X    intact.
  1204. X}
  1205. X{ Match -- find match anywhere on line + support fcns }
  1206. Xsegment Match;
  1207. X%include swtools
  1208. X%include patdef
  1209. X%include matchdef
  1210. Xfunction Match;
  1211. Xvar
  1212. X    i, pos: Integer;
  1213. Xbegin
  1214. X    pos := 0;
  1215. X    i := 1;
  1216. X    while (lin[i] <> ENDSTR) and (pos = 0) do begin
  1217. X        pos := AMatch(lin, i, pat, 1);
  1218. X        i := i + 1;
  1219. X    end;
  1220. X    Match := (pos > 0)
  1221. Xend;
  1222. /
  1223. echo 'x - move.pascal'
  1224. sed 's/^X//' > move.pascal << '/'
  1225. X{
  1226. X    Copyright (c) 1981
  1227. X    By:    Bell Telephone Laboratories, Inc. and
  1228. X        Whitesmiths, Ltd.,
  1229. X
  1230. X    This software is derived from the book
  1231. X        "Software Tools In Pascal", by
  1232. X        Brian W. Kernighan and P.J. Plauger
  1233. X        Addison-Wesley, 1981
  1234. X        ISBN 0-201-10342-7
  1235. X
  1236. X    Right is hereby granted to freely distribute or duplicate this
  1237. X    software, providing distribution or duplication is not for profit
  1238. X    or other commerical gain and that this copyright notice remains 
  1239. X    intact.
  1240. X}
  1241. X{ Move -- move line1 thru line2 after line3 }
  1242. Xsegment Move;
  1243. X%include swtools
  1244. X%include editcons
  1245. X%include edittype
  1246. X%include editproc
  1247. X%include editref
  1248. Xfunction Move;
  1249. Xbegin
  1250. X    if (line1 <= 0) or ((line3 >= line1) and (line3 < line2)) then
  1251. X        Move := ERR
  1252. X    else begin
  1253. X        BlkMove(line1, line2, line3);
  1254. X       if (line3 > line1) then
  1255. X           curLn := line3
  1256. X       else
  1257. X           curLn := line3 + (line2 - line1 + 1);
  1258. X       Move := OK
  1259. X    end
  1260. Xend;
  1261. /
  1262. echo 'x - nextln.pascal'
  1263. sed 's/^X//' > nextln.pascal << '/'
  1264. X{
  1265. X    Copyright (c) 1981
  1266. X    By:    Bell Telephone Laboratories, Inc. and
  1267. X        Whitesmiths, Ltd.,
  1268. X
  1269. X    This software is derived from the book
  1270. X        "Software Tools In Pascal", by
  1271. X        Brian W. Kernighan and P.J. Plauger
  1272. X        Addison-Wesley, 1981
  1273. X        ISBN 0-201-10342-7
  1274. X
  1275. X    Right is hereby granted to freely distribute or duplicate this
  1276. X    software, providing distribution or duplication is not for profit
  1277. X    or other commerical gain and that this copyright notice remains 
  1278. X    intact.
  1279. X}
  1280. X{ NextLn/PrevLn -- get next/previous line number }
  1281. Xsegment NextLn;
  1282. X%include swtools
  1283. X%include editcons
  1284. X%include edittype
  1285. X%include editproc
  1286. X%include editref
  1287. Xfunction NextLn;
  1288. Xbegin
  1289. X    if (n >= lastLn) then
  1290. X        nextLn := 0
  1291. X    else
  1292. X        nextLn := n + 1
  1293. Xend;
  1294. Xfunction PrevLn;
  1295. Xbegin
  1296. X    if (n <= 0) then
  1297. X        PrevLn := lastLn
  1298. X    else
  1299. X        PrevLn := n - 1
  1300. Xend;
  1301. /
  1302. echo 'x - optpat.pascal'
  1303. sed 's/^X//' > optpat.pascal << '/'
  1304. X{
  1305. X    Copyright (c) 1981
  1306. X    By:    Bell Telephone Laboratories, Inc. and
  1307. X        Whitesmiths, Ltd.,
  1308. X
  1309. X    This software is derived from the book
  1310. X        "Software Tools In Pascal", by
  1311. X        Brian W. Kernighan and P.J. Plauger
  1312. X        Addison-Wesley, 1981
  1313. X        ISBN 0-201-10342-7
  1314. X
  1315. X    Right is hereby granted to freely distribute or duplicate this
  1316. X    software, providing distribution or duplication is not for profit
  1317. X    or other commerical gain and that this copyright notice remains 
  1318. X    intact.
  1319. X}
  1320. X{ OptPat -- get optional pattern from lin[i], increment i }
  1321. Xsegment OptPat;
  1322. X%include swtools
  1323. X%include editcons
  1324. X%include edittype
  1325. X%include editproc
  1326. X%include editref
  1327. X%include patdef
  1328. Xfunction OptPat;
  1329. Xbegin
  1330. X    if (lin[i] = ENDSTR) then
  1331. X        i := 0
  1332. X    else if (lin[i + 1] = ENDSTR) then
  1333. X        i := 0
  1334. X    else if (lin[I + 1] = lin[i]) then { leave existing pattern alone }
  1335. X        i := i + 1
  1336. X    else
  1337. X        i := MakePat(lin, i+1, lin[i], pat);
  1338. X    if (pat[1] = ENDSTR) then
  1339. X        i := 0;
  1340. X    if (i = 0) then begin
  1341. X        pat[1] := ENDSTR;
  1342. X        OptPat := ERR
  1343. X    end
  1344. X    else
  1345. X        OptPat := OK
  1346. Xend;
  1347. /
  1348. echo 'x - patscan.pascal'
  1349. sed 's/^X//' > patscan.pascal << '/'
  1350. X{
  1351. X    Copyright (c) 1981
  1352. X    By:    Bell Telephone Laboratories, Inc. and
  1353. X        Whitesmiths, Ltd.,
  1354. X
  1355. X    This software is derived from the book
  1356. X        "Software Tools In Pascal", by
  1357. X        Brian W. Kernighan and P.J. Plauger
  1358. X        Addison-Wesley, 1981
  1359. X        ISBN 0-201-10342-7
  1360. X
  1361. X    Right is hereby granted to freely distribute or duplicate this
  1362. X    software, providing distribution or duplication is not for profit
  1363. X    or other commerical gain and that this copyright notice remains 
  1364. X    intact.
  1365. X}
  1366. X{ PatScan -- find next occurance of pattern after line n }
  1367. Xsegment PatScan;
  1368. X%include swtools
  1369. X%include editcons
  1370. X%include edittype
  1371. X%include editproc
  1372. X%include editref
  1373. X%include matchdef
  1374. Xfunction PatScan;
  1375. Xvar
  1376. X    done: Boolean;
  1377. X    line: StringType;
  1378. Xbegin
  1379. X    n := curLn;
  1380. X    PatScan := ERR;
  1381. X    done := false;
  1382. X    repeat
  1383. X        if (way = SCAN) then
  1384. X            n := NextLn(n)
  1385. X        else
  1386. X            n := PrevLn(n);
  1387. X        GetTxt(n, line);
  1388. X        if (Match(line, pat)) then begin
  1389. X            PatScan := OK;
  1390. X            done := true
  1391. X        end
  1392. X    until (n = curLn) or (done)
  1393. Xend;
  1394. /
  1395. echo 'x - patsize.pascal'
  1396. sed 's/^X//' > patsize.pascal << '/'
  1397. X{
  1398. X    Copyright (c) 1981
  1399. X    By:    Bell Telephone Laboratories, Inc. and
  1400. X        Whitesmiths, Ltd.,
  1401. X
  1402. X    This software is derived from the book
  1403. X        "Software Tools In Pascal", by
  1404. X        Brian W. Kernighan and P.J. Plauger
  1405. X        Addison-Wesley, 1981
  1406. X        ISBN 0-201-10342-7
  1407. X
  1408. X    Right is hereby granted to freely distribute or duplicate this
  1409. X    software, providing distribution or duplication is not for profit
  1410. X    or other commerical gain and that this copyright notice remains 
  1411. X    intact.
  1412. X}
  1413. X{ PatSize -- returns size of pattern entry at pat[n] }
  1414. Xsegment PatSize;
  1415. X%include swtools
  1416. X%include patdef
  1417. X%include matchdef
  1418. X%include metadef
  1419. Xfunction PatSize;
  1420. Xbegin
  1421. X    case pat[n] of
  1422. X        LITCHAR:
  1423. X            PatSize := 2;
  1424. X        BOL, EOL, ANY, BOM, EOM:
  1425. X            PatSize := 1;
  1426. X        CCL, NCCL:
  1427. X            PatSize := Ord(pat[n+1]) + 2;
  1428. X        CLOSURE:
  1429. X            PatSize := CLOSIZE
  1430. X        otherwise
  1431. X            Error('in PatSize: Can''t happen');
  1432. X    end
  1433. Xend;
  1434. /
  1435. echo 'x - putchr.pascal'
  1436. sed 's/^X//' > putchr.pascal << '/'
  1437. X{
  1438. X    Copyright (c) 1981
  1439. X    By:    Bell Telephone Laboratories, Inc. and
  1440. X        Whitesmiths, Ltd.,
  1441. X
  1442. X    This software is derived from the book
  1443. X        "Software Tools In Pascal", by
  1444. X        Brian W. Kernighan and P.J. Plauger
  1445. X        Addison-Wesley, 1981
  1446. X        ISBN 0-201-10342-7
  1447. X
  1448. X    Right is hereby granted to freely distribute or duplicate this
  1449. X    software, providing distribution or duplication is not for profit
  1450. X    or other commerical gain and that this copyright notice remains 
  1451. X    intact.
  1452. X}
  1453. X{ PutChr -- put single char on output or eval stack }
  1454. Xsegment PutChr;
  1455. X%include swtools
  1456. X%include macdefs
  1457. X%include macproc
  1458. Xprocedure PutChr;
  1459. Xbegin
  1460. X    if (cp <= 0) then
  1461. X        PutC(c)
  1462. X    else begin
  1463. X        if (ep > EVALSIZE) then
  1464. X            Error('Macro: evaluation stack overflow');
  1465. X        evalStk[ep] := c;
  1466. X        ep := ep + 1
  1467. X    end {if}
  1468. Xend {PutChr};
  1469. /
  1470. echo 'x - putstr.pascal'
  1471. sed 's/^X//' > putstr.pascal << '/'
  1472. X{
  1473. X    Copyright (c) 1981
  1474. X    By:    Bell Telephone Laboratories, Inc. and
  1475. X        Whitesmiths, Ltd.,
  1476. X
  1477. X    This software is derived from the book
  1478. X        "Software Tools In Pascal", by
  1479. X        Brian W. Kernighan and P.J. Plauger
  1480. X        Addison-Wesley, 1981
  1481. X        ISBN 0-201-10342-7
  1482. X
  1483. X    Right is hereby granted to freely distribute or duplicate this
  1484. X    software, providing distribution or duplication is not for profit
  1485. X    or other commerical gain and that this copyright notice remains 
  1486. X    intact.
  1487. X}
  1488. X{ PutStr -- put string out on file }
  1489. Xsegment PutStr;
  1490. X%include swtools
  1491. X%include ioref
  1492. Xprocedure PutStr;
  1493. Xvar
  1494. X    i: Integer;
  1495. X    j: integer;
  1496. X    len: Integer;
  1497. X    outString: StringType;
  1498. Xbegin
  1499. X    i := 1;
  1500. X    j := 1;
  1501. X    len := StrLength(str);
  1502. X    while i <= len do begin
  1503. X        if str[i] = NEWLINE then begin
  1504. X            if j = 1 then WriteLn(openList[fd].fileVar)
  1505. X                     else WriteLn(openList[fd].fileVar, outString:j-1);
  1506. X            j := 1;
  1507. X        end {then}
  1508. X        else begin
  1509. X            outString[j] := str[i];
  1510. X            j := j + 1;
  1511. X        end; {if}
  1512. X        i := i + 1
  1513. X    end; {while}
  1514. X    if j <> 1 then write(openList[fd].fileVar, outString:j-1);
  1515. Xend; {PutStr}
  1516. /
  1517. echo 'x - putsub.pascal'
  1518. sed 's/^X//' > putsub.pascal << '/'
  1519. X{
  1520. X    Copyright (c) 1981
  1521. X    By:    Bell Telephone Laboratories, Inc. and
  1522. X        Whitesmiths, Ltd.,
  1523. X
  1524. X    This software is derived from the book
  1525. X        "Software Tools In Pascal", by
  1526. X        Brian W. Kernighan and P.J. Plauger
  1527. X        Addison-Wesley, 1981
  1528. X        ISBN 0-201-10342-7
  1529. X
  1530. X    Right is hereby granted to freely distribute or duplicate this
  1531. X    software, providing distribution or duplication is not for profit
  1532. X    or other commerical gain and that this copyright notice remains 
  1533. X    intact.
  1534. X}
  1535. X{ PutSub -- output substitution text }
  1536. Xsegment PutSub;
  1537. X%include swtools
  1538. X%include subdef
  1539. Xprocedure PutSub;
  1540. Xvar
  1541. X    i, j: Integer;
  1542. X    junk: Boolean;
  1543. Xbegin
  1544. X    i := 1;
  1545. X    while (sub[i] <> ENDSTR) do begin
  1546. X        if (sub[i] = DITTO) then
  1547. X            for j := s1 to s2-1 do
  1548. X                PutC(lin[j])
  1549. X        else
  1550. X            PutC(sub[i]);
  1551. X        i := i + 1
  1552. X    end
  1553. Xend;
  1554. /
  1555. echo 'x - sccopy.pascal'
  1556. sed 's/^X//' > sccopy.pascal << '/'
  1557. X{
  1558. X    Copyright (c) 1981
  1559. X    By:    Bell Telephone Laboratories, Inc. and
  1560. X        Whitesmiths, Ltd.,
  1561. X
  1562. X    This software is derived from the book
  1563. X        "Software Tools In Pascal", by
  1564. X        Brian W. Kernighan and P.J. Plauger
  1565. X        Addison-Wesley, 1981
  1566. X        ISBN 0-201-10342-7
  1567. X
  1568. X    Right is hereby granted to freely distribute or duplicate this
  1569. X    software, providing distribution or duplication is not for profit
  1570. X    or other commerical gain and that this copyright notice remains 
  1571. X    intact.
  1572. X}
  1573. X{ SCCopy -- copy string s to cb[i] }
  1574. Xsegment SCCopy;
  1575. X%include swtools
  1576. X%include defdef
  1577. X%include defref
  1578. X%include defproc
  1579. Xprocedure SCCopy;
  1580. Xvar
  1581. X    j: Integer;
  1582. Xbegin
  1583. X    j := 1;
  1584. X    while (s[j] <> ENDSTR) do begin
  1585. X        cb[i] := s[j];
  1586. X        j := j + 1;
  1587. X        i := i + 1
  1588. X    end;
  1589. X    cb[i] := ENDSTR
  1590. Xend;
  1591. /
  1592. echo 'x - screen.pascal'
  1593. sed 's/^X//' > screen.pascal << '/'
  1594. X{
  1595. X    Copyright (c) 1982
  1596. X    By:    Chris Lewis
  1597. X
  1598. X    Right is hereby granted to freely distribute or duplicate this
  1599. X    software, providing distribution or duplication is not for profit
  1600. X    or other commerical gain and that this copyright notice remains 
  1601. X    intact.
  1602. X}
  1603. X{ Screen -- line printer character test }
  1604. Xprogram Screen;
  1605. X%include swtools
  1606. X%include ioref
  1607. Xvar i: Integer;
  1608. X    first: Integer;
  1609. Xbegin
  1610. XToolInit;
  1611. XWriteLn(openList[STDOUT].fileVar, '     C H A R A C T E R  S E T');
  1612. XPutC(NEWLINE);
  1613. XWriteLn(openList[STDOUT].FileVar,
  1614. X     '     0 1 2 3 4 5 6 7 8 9 A B C D E F');
  1615. Xfor i := 0 to 255 do begin
  1616. X    if i mod 16 = 0 then begin
  1617. X        PutC(NEWLINE);
  1618. X        PutC(NEWLINE);
  1619. X        first := i div 16;
  1620. X        if first >= 10 then
  1621. X            PutC(Chr(first + Ord(BIGA) - 10))
  1622. X        else
  1623. X            PutC(Chr(i div 16 + Ord(DIG0)));
  1624. X        PutC(DIG0);
  1625. X        PutC(BLANK);
  1626. X        PutC(BLANK);
  1627. X    end;
  1628. X    Write(openList[STDOUT].fileVar, ' ', Chr(i))
  1629. Xend
  1630. Xend.
  1631. /
  1632. echo 'x - stclose.pascal'
  1633. sed 's/^X//' > stclose.pascal << '/'
  1634. X{
  1635. X    Copyright (c) 1981
  1636. X    By:    Bell Telephone Laboratories, Inc. and
  1637. X        Whitesmiths, Ltd.,
  1638. X
  1639. X    This software is derived from the book
  1640. X        "Software Tools In Pascal", by
  1641. X        Brian W. Kernighan and P.J. Plauger
  1642. X        Addison-Wesley, 1981
  1643. X        ISBN 0-201-10342-7
  1644. X
  1645. X    Right is hereby granted to freely distribute or duplicate this
  1646. X    software, providing distribution or duplication is not for profit
  1647. X    or other commerical gain and that this copyright notice remains 
  1648. X    intact.
  1649. X}
  1650. X{ StClose -- insert closure entry at pat[j] }
  1651. Xsegment STClose;
  1652. X%include swtools
  1653. X%include patdef
  1654. Xprocedure StClose;
  1655. Xvar
  1656. X    jp, jt: Integer;
  1657. X    junk: Boolean;
  1658. Xbegin
  1659. X    for jp := j-1 downto lastJ do begin
  1660. X        jt := jp + CLOSIZE;
  1661. X        junk := AddStr(pat[jp], pat, jt, MAXPAT)
  1662. X    end;
  1663. X    j := j + CLOSIZE;
  1664. X    pat[lastJ] := CLOSURE { where original pattern began }
  1665. Xend;
  1666. /
  1667. echo 'x - strindex.pascal'
  1668. sed 's/^X//' > strindex.pascal << '/'
  1669. X{
  1670. X    Copyright (c) 1981
  1671. X    By:    Bell Telephone Laboratories, Inc. and
  1672. X        Whitesmiths, Ltd.,
  1673. X
  1674. X    This software is derived from the book
  1675. X        "Software Tools In Pascal", by
  1676. X        Brian W. Kernighan and P.J. Plauger
  1677. X        Addison-Wesley, 1981
  1678. X        ISBN 0-201-10342-7
  1679. X
  1680. X    Right is hereby granted to freely distribute or duplicate this
  1681. X    software, providing distribution or duplication is not for profit
  1682. X    or other commerical gain and that this copyright notice remains 
  1683. X    intact.
  1684. X}
  1685. X{ StrIndex -- find position of character c in string s }
  1686. Xsegment StrIndex;
  1687. X%include swtools
  1688. Xfunction StrIndex;
  1689. Xvar
  1690. X    i: Integer;
  1691. Xbegin
  1692. X    i := 1;
  1693. X    while (s[i] <> c) and (s[i] <> ENDSTR) do
  1694. X        i := i + 1;
  1695. X    if (s[i] = ENDSTR) then
  1696. X        StrIndex := 0
  1697. X    else
  1698. X        StrIndex := i
  1699. Xend;
  1700. /
  1701. echo 'x - subline.pascal'
  1702. sed 's/^X//' > subline.pascal << '/'
  1703. X{
  1704. X    Copyright (c) 1981
  1705. X    By:    Bell Telephone Laboratories, Inc. and
  1706. X        Whitesmiths, Ltd.,
  1707. X
  1708. X    This software is derived from the book
  1709. X        "Software Tools In Pascal", by
  1710. X        Brian W. Kernighan and P.J. Plauger
  1711. X        Addison-Wesley, 1981
  1712. X        ISBN 0-201-10342-7
  1713. X
  1714. X    Right is hereby granted to freely distribute or duplicate this
  1715. X    software, providing distribution or duplication is not for profit
  1716. X    or other commerical gain and that this copyright notice remains 
  1717. X    intact.
  1718. X}
  1719. X{ SubLine -- substitute sub for pat in lin and print }
  1720. Xsegment SubLine;
  1721. X%include swtools
  1722. X%include patdef
  1723. X%include subdef
  1724. X%include matchdef
  1725. Xprocedure SubLine;
  1726. Xvar
  1727. X    i, lastm, m: Integer;
  1728. X    junk: Boolean;
  1729. Xbegin
  1730. X    lastm := 0;
  1731. X    i := 1;
  1732. X    while (lin[i] <> ENDSTR) do begin
  1733. X        m := AMatch(lin, i, pat, 1);
  1734. X        if (m > 0) and (lastm <> m) then begin
  1735. X            { replace substituted text }
  1736. X            PutSub(lin, i, m, sub);
  1737. X            lastm := m
  1738. X        end;
  1739. X        if (m = 0) or (m = i) then begin
  1740. X            { no match or null match }
  1741. X            PutC(lin[i]);
  1742. X            i := i + 1
  1743. X        end
  1744. X        else        { skip matched text }
  1745. X            i := m
  1746. X    end
  1747. Xend;
  1748. /
  1749. echo 'x - swch.pascal'
  1750. sed 's/^X//' > swch.pascal << '/'
  1751. X{
  1752. X    Copyright (c) 1981
  1753. X    By:    Bell Telephone Laboratories, Inc. and
  1754. X        Whitesmiths, Ltd.,
  1755. X
  1756. X    This software is derived from the book
  1757. X        "Software Tools In Pascal", by
  1758. X        Brian W. Kernighan and P.J. Plauger
  1759. X        Addison-Wesley, 1981
  1760. X        ISBN 0-201-10342-7
  1761. X
  1762. X    Right is hereby granted to freely distribute or duplicate this
  1763. X    software, providing distribution or duplication is not for profit
  1764. X    or other commerical gain and that this copyright notice remains 
  1765. X    intact.
  1766. X}
  1767. X{ Change -- change "from" into "to" on each line }
  1768. Xprogram swch;
  1769. X%include swtools
  1770. X%include patdef
  1771. X%include matchdef
  1772. X%include subdef
  1773. Xvar
  1774. X    lin, pat, sub, arg: StringType;
  1775. Xbegin
  1776. X    ToolInit;
  1777. X    if (not GetArg(1, arg, MAXSTR)) then
  1778. X        Error('usage: change from <to>');
  1779. X    if (not GetPat(arg, pat)) then
  1780. X        Error('change: illegal "from" pattern');
  1781. X    if (not GetArg(2, arg, MAXSTR)) then
  1782. X        arg[1] := ENDSTR;
  1783. X    if (not GetSub(arg, sub)) then
  1784. X        Error('change: illegal "to" string');
  1785. X    while (GetLine(lin, STDIN, MAXSTR)) do
  1786. X        SubLine(lin, pat, sub)
  1787. Xend;
  1788. /
  1789. echo 'x - swprint.exec'
  1790. sed 's/^X//' > swprint.exec << '/'
  1791. X&TRACE OFF
  1792. XCP SPOOL PRT CONT HOLD FORM LW1T
  1793. XERASE CMS EXEC A
  1794. XEXECUTIL WRITE CMS EXEC A  (&TRACE OFF)
  1795. XLISTFILE * PASCAL C (APPEND
  1796. XEXEC CMS EXEC SWPRIN1
  1797. XERASE CMS EXEC A
  1798. XERASE SWTOOLS LDATE C
  1799. XEXECUTIL WRITE SWTOOLS LDATE C (JUNK)
  1800. XERASE CMS EXEC
  1801. XCP SPOOL PRT CLOSE
  1802. /
  1803. echo 'x - term.pascal'
  1804. sed 's/^X//' > term.pascal << '/'
  1805. X{
  1806. X    Copyright (c) 1981
  1807. X    By:    Bell Telephone Laboratories, Inc. and
  1808. X        Whitesmiths, Ltd.,
  1809. X
  1810. X    This software is derived from the book
  1811. X        "Software Tools In Pascal", by
  1812. X        Brian W. Kernighan and P.J. Plauger
  1813. X        Addison-Wesley, 1981
  1814. X        ISBN 0-201-10342-7
  1815. X
  1816. X    Right is hereby granted to freely distribute or duplicate this
  1817. X    software, providing distribution or duplication is not for profit
  1818. X    or other commerical gain and that this copyright notice remains 
  1819. X    intact.
  1820. X}
  1821. X{ Term -- Evaluate term of arithmetic expression }
  1822. Xsegment Term;
  1823. X%include swtools
  1824. X%include macdefs
  1825. X%include macproc
  1826. Xfunction Term;
  1827. Xvar
  1828. X    v: Integer;
  1829. X    t: CharType;
  1830. Xbegin
  1831. X    v := Factor(s, i);
  1832. X    t := GNBChar(s, i);
  1833. X    while (t in [STAR, SLASH, PERCENT]) do begin
  1834. X        i := i + 1;
  1835. X        case t of
  1836. X            STAR:
  1837. X                v := v * Factor(s, i);
  1838. X            SLASH:
  1839. X                v := v div Factor(s, i);
  1840. X            PERCENT:
  1841. X                v := v mod Factor(s, i)
  1842. X        end {case};
  1843. X        t := GNBChar(s, i)
  1844. X    end {while};
  1845. X    Term  := v
  1846. Xend { Term };
  1847. /
  1848. echo 'x - wc.pascal'
  1849. sed 's/^X//' > wc.pascal << '/'
  1850. X{
  1851. X    Copyright (c) 1982
  1852. X    By:    Chris Lewis
  1853. X
  1854. X    Right is hereby granted to freely distribute or duplicate this
  1855. X    software, providing distribution or duplication is not for profit
  1856. X    or other commerical gain and that this copyright notice remains 
  1857. X    intact.
  1858. X}
  1859. X{ Wc -- Word Counting program }
  1860. Xprogram Wc;
  1861. X%include SWTOOLS
  1862. Xvar
  1863. X    buffer: StringType;
  1864. X    numChars: Integer;
  1865. X    numWords: Integer;
  1866. X    numLines: Integer;
  1867. X    i: Integer;
  1868. X    lineLength: Integer;
  1869. X    inWord: Boolean;
  1870. Xbegin
  1871. X    ToolInit;
  1872. X    numChars := 0;
  1873. X    numWords := 0;
  1874. X    numLines := 0;
  1875. X    while (GetLine(buffer, STDIN, MAXSTR)) do begin
  1876. X        inWord := false;
  1877. X        numLines := numLines + 1;
  1878. X        lineLength := StrLength (buffer);
  1879. X        numChars := numChars + lineLength;
  1880. X        for i := 1 to lineLength do
  1881. X            if (buffer[i] = BLANK) then
  1882. X                inWord := false
  1883. X            else if (not inWord) then begin
  1884. X                inWord := true;
  1885. X                numWords := numWords + 1;
  1886. X            end; {if}
  1887. X    end; {while}
  1888. X    PutDec(numChars, 7);
  1889. X    PutDec(numWords, 7);
  1890. X    PutDec(numLines, 7);
  1891. Xend; {Wc}
  1892. /
  1893. echo 'Part 05 of pack.out complete.'
  1894. exit
  1895.  
  1896.  
  1897.