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

  1. Subject: Software Tools in Pascal (Part 6 of 6)
  2. From: ihnp4!mnetor!clewis (Chris Lewis)
  3. Newsgroups: mod.sources
  4. Approved: john@genrad.UUCP
  5.  
  6. Mod.sources:  Volume 2, Issue 12
  7. Submitted by: ihnp4!mnetor!clewis (Chris Lewis)
  8.  
  9. #!/bin/sh
  10. echo 'Start of pack.out, part 06 of 06:'
  11. echo 'x - addstr.pascal'
  12. sed 's/^X//' > addstr.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{ AddStr -- put c in outSet[j] if it fits, increment j }
  30. Xsegment AddStr;
  31. X%include swtools
  32. Xfunction Addstr;
  33. Xbegin
  34. X    if (j > maxSet) then
  35. X        AddStr := false
  36. X    else begin
  37. X        outSet[j] := c;
  38. X        j := j + 1;
  39. X        AddStr := true
  40. X    end
  41. Xend;
  42. /
  43. echo 'x - cvtsst.pascal'
  44. sed 's/^X//' > cvtsst.pascal << '/'
  45. X{
  46. X    Copyright (c) 1982
  47. X    By:    Chris Lewis
  48. X
  49. X    Right is hereby granted to freely distribute or duplicate this
  50. X    software, providing distribution or duplication is not for profit
  51. X    or other commerical gain and that this copyright notice remains 
  52. X    intact.
  53. X}
  54. X{ CvtSST -- assign pascalvs string to StringType }
  55. Xsegment CvtSST;
  56. X%include swtools
  57. Xprocedure CvtSST;
  58. Xvar
  59. X    i: 1..MAXSTR;
  60. Xbegin
  61. X    for i := 1 to Length(src) do
  62. X        dest[i] := src[i];
  63. X    dest[Length(src) + 1] := ENDSTR;
  64. Xend;
  65. /
  66. echo 'x - cvtsts.pascal'
  67. sed 's/^X//' > cvtsts.pascal << '/'
  68. X{
  69. X    Copyright (c) 1982
  70. X    By:    Chris Lewis
  71. X
  72. X    Right is hereby granted to freely distribute or duplicate this
  73. X    software, providing distribution or duplication is not for profit
  74. X    or other commerical gain and that this copyright notice remains 
  75. X    intact.
  76. X}
  77. X{ CvtStS -- convert swtools StringType to Pascalvs String }
  78. Xsegment cvtsts;
  79. X%include swtools
  80. Xprocedure cvtsts;
  81. Xbegin
  82. X    WriteStr(dest, src:StrLength(src));
  83. Xend;
  84. /
  85. echo 'x - doexpr.pascal'
  86. sed 's/^X//' > doexpr.pascal << '/'
  87. X{
  88. X    Copyright (c) 1981
  89. X    By:    Bell Telephone Laboratories, Inc. and
  90. X        Whitesmiths, Ltd.,
  91. X
  92. X    This software is derived from the book
  93. X        "Software Tools In Pascal", by
  94. X        Brian W. Kernighan and P.J. Plauger
  95. X        Addison-Wesley, 1981
  96. X        ISBN 0-201-10342-7
  97. X
  98. X    Right is hereby granted to freely distribute or duplicate this
  99. X    software, providing distribution or duplication is not for profit
  100. X    or other commerical gain and that this copyright notice remains 
  101. X    intact.
  102. X}
  103. X{ DoExpr -- Evaluate arithmetic expression }
  104. Xsegment DoExpr;
  105. X%include swtools
  106. X%include macdefs
  107. X%include macproc
  108. Xprocedure DoExpr;
  109. Xvar
  110. X    temp: StringType;
  111. X    junk: Integer;
  112. Xbegin
  113. X    CsCopy(evalStk, argStk[i+2], temp);
  114. X    junk := 1;
  115. X    PBNum(Expr(temp, junk))
  116. Xend {DoExpr};
  117. /
  118. echo 'x - echo.pascal'
  119. sed 's/^X//' > echo.pascal << '/'
  120. X{
  121. X    Copyright (c) 1982
  122. X    By:    Chris Lewis
  123. X
  124. X    Right is hereby granted to freely distribute or duplicate this
  125. X    software, providing distribution or duplication is not for profit
  126. X    or other commerical gain and that this copyright notice remains 
  127. X    intact.
  128. X}
  129. X{ Echo -- echo arguments }
  130. Xprogram Echo;
  131. X%include swtools
  132. Xvar
  133. X    lin: StringType;
  134. X    i: Integer;
  135. X    junk: Boolean;
  136. Xbegin
  137. X    ToolInit;
  138. X    for i := 1 to Nargs do begin
  139. X        junk := GetArg(i, lin, MAXSTR);
  140. X        PutStr(lin, STDOUT);
  141. X        if i < Nargs then PutCF(BLANK, STDOUT)
  142. X    end;
  143. X    PutCF(NEWLINE, STDOUT)
  144. Xend.
  145. /
  146. echo 'x - equal.pascal'
  147. sed 's/^X//' > equal.pascal << '/'
  148. X{
  149. X    Copyright (c) 1981
  150. X    By:    Bell Telephone Laboratories, Inc. and
  151. X        Whitesmiths, Ltd.,
  152. X
  153. X    This software is derived from the book
  154. X        "Software Tools In Pascal", by
  155. X        Brian W. Kernighan and P.J. Plauger
  156. X        Addison-Wesley, 1981
  157. X        ISBN 0-201-10342-7
  158. X
  159. X    Right is hereby granted to freely distribute or duplicate this
  160. X    software, providing distribution or duplication is not for profit
  161. X    or other commerical gain and that this copyright notice remains 
  162. X    intact.
  163. X}
  164. X{ Equal -- test two strings for equality }
  165. Xsegment Equal;
  166. X%include swtools
  167. Xfunction Equal;{str1, str2: StringType): Boolean}
  168. Xvar
  169. X    i: Integer;
  170. Xbegin
  171. X    i := 1;
  172. X    while (str1[i] = str2[i]) and (str1[i] <> ENDSTR) do
  173. X        i := i + 1;
  174. X    Equal := (str1[i] = str2[i])
  175. Xend;
  176. /
  177. echo 'x - error.pascal'
  178. sed 's/^X//' > error.pascal << '/'
  179. X{
  180. X    Copyright (c) 1981
  181. X    By:    Bell Telephone Laboratories, Inc. and
  182. X        Whitesmiths, Ltd.,
  183. X
  184. X    This software is derived from the book
  185. X        "Software Tools In Pascal", by
  186. X        Brian W. Kernighan and P.J. Plauger
  187. X        Addison-Wesley, 1981
  188. X        ISBN 0-201-10342-7
  189. X
  190. X    Right is hereby granted to freely distribute or duplicate this
  191. X    software, providing distribution or duplication is not for profit
  192. X    or other commerical gain and that this copyright notice remains 
  193. X    intact.
  194. X}
  195. Xsegment Error;
  196. X%include swtools
  197. Xprocedure Error;
  198. Xvar
  199. X    i: 1..MAXSTR;
  200. Xbegin
  201. X    for i := 1 to Length(s) do
  202. X         PutCF(s[i], STDERR);
  203. X    PutCF(NEWLINE,STDERR);
  204. X    RetCode(1000);
  205. X    HALT;
  206. Xend;
  207. /
  208. echo 'x - fclose.pascal'
  209. sed 's/^X//' > fclose.pascal << '/'
  210. X{
  211. X    Copyright (c) 1982
  212. X    By:    Chris Lewis
  213. X
  214. X    Right is hereby granted to freely distribute or duplicate this
  215. X    software, providing distribution or duplication is not for profit
  216. X    or other commerical gain and that this copyright notice remains 
  217. X    intact.
  218. X}
  219. X{ FClose -- close a file }
  220. Xsegment FClose;
  221. X%include swtools
  222. X%include ioref
  223. Xprocedure FClose;
  224. Xbegin
  225. X    if (fd > STDERR) and (fd <= MAXOPEN) and
  226. X      (openList[fd].mode <> IOAVAIL) then begin
  227. X        Close(openList[fd].fileVar);
  228. X        openList[fd].mode := IOAVAIL;
  229. X        ERRORIO := false;
  230. X    end;
  231. Xend;
  232. /
  233. echo 'x - fcopy.pascal'
  234. sed 's/^X//' > fcopy.pascal << '/'
  235. X{
  236. X    Copyright (c) 1981
  237. X    By:    Bell Telephone Laboratories, Inc. and
  238. X        Whitesmiths, Ltd.,
  239. X
  240. X    This software is derived from the book
  241. X        "Software Tools In Pascal", by
  242. X        Brian W. Kernighan and P.J. Plauger
  243. X        Addison-Wesley, 1981
  244. X        ISBN 0-201-10342-7
  245. X
  246. X    Right is hereby granted to freely distribute or duplicate this
  247. X    software, providing distribution or duplication is not for profit
  248. X    or other commerical gain and that this copyright notice remains 
  249. X    intact.
  250. X}
  251. X{ FCopy -- Copy file fin to file fout }
  252. Xsegment FCopy;
  253. X%include SWTOOLS
  254. X%include IODEF
  255. Xprocedure FCopy;
  256. Xvar
  257. X    temp: StringType;
  258. Xbegin
  259. X    while (GetLine(temp, fin, MAXSTR)) do
  260. X        PutStr(temp, fout);
  261. Xend; {FCopy}
  262. /
  263. echo 'x - fcreate.pascal'
  264. sed 's/^X//' > fcreate.pascal << '/'
  265. X{
  266. X    Copyright (c) 1982
  267. X    By:    Chris Lewis
  268. X
  269. X    Right is hereby granted to freely distribute or duplicate this
  270. X    software, providing distribution or duplication is not for profit
  271. X    or other commerical gain and that this copyright notice remains 
  272. X    intact.
  273. X}
  274. X{ FCreate -- create a file (temporary version) }
  275. Xsegment FCreate;
  276. X%include swtools
  277. Xfunction FCreate;
  278. Xbegin
  279. X    FCreate := FOpen(name, mode)
  280. Xend;
  281. /
  282. echo 'x - fdalloc.pascal'
  283. sed 's/^X//' > fdalloc.pascal << '/'
  284. X{
  285. X    Copyright (c) 1982
  286. X    By:    Chris Lewis
  287. X
  288. X    Right is hereby granted to freely distribute or duplicate this
  289. X    software, providing distribution or duplication is not for profit
  290. X    or other commerical gain and that this copyright notice remains 
  291. X    intact.
  292. X}
  293. X{ FDAlloc - find a free file descriptor }
  294. Xsegment FDAlloc;
  295. X%include swtools
  296. X%include ioref
  297. Xfunction FDAlloc;
  298. Xvar
  299. X    fd: FileDesc;
  300. X    done: Boolean;
  301. Xbegin
  302. X    done := false;
  303. X    fd := Succ(STDERR);
  304. X    repeat
  305. X        done := (openList[fd].mode = IOAVAIL) or (fd = MAXOPEN);
  306. X        if (not done) then
  307. X            fd := Succ(fd)
  308. X    until (done);
  309. X    if openList[fd].mode = IOAVAIL then
  310. X        FDAlloc := fd
  311. X    else
  312. X        FDAlloc := IOERROR
  313. Xend;
  314. /
  315. echo 'x - getarg.pascal'
  316. sed 's/^X//' > getarg.pascal << '/'
  317. X{
  318. X    Copyright (c) 1982
  319. X    By:    Chris Lewis
  320. X
  321. X    Right is hereby granted to freely distribute or duplicate this
  322. X    software, providing distribution or duplication is not for profit
  323. X    or other commerical gain and that this copyright notice remains 
  324. X    intact.
  325. X}
  326. X{ GetArg (CMS) -- get n-th command line parameter }
  327. Xsegment GetArg;
  328. X%include swtools
  329. X%include ioref
  330. Xfunction GetArg;
  331. Xbegin
  332. X    if ((n < 1) or (cmdArgs < n)) then
  333. X        GetArg := false
  334. X    else begin
  335. X        SCopy(cmdLin,cmdIdx[n], str, 1);
  336. X        GetArg := true
  337. X    end
  338. Xend;
  339. /
  340. echo 'x - getcf.pascal'
  341. sed 's/^X//' > getcf.pascal << '/'
  342. X{
  343. X    Copyright (c) 1982
  344. X    By:    Chris Lewis
  345. X
  346. X    Right is hereby granted to freely distribute or duplicate this
  347. X    software, providing distribution or duplication is not for profit
  348. X    or other commerical gain and that this copyright notice remains 
  349. X    intact.
  350. X}
  351. X{ GetCF -- get character from file }
  352. Xsegment GetCF;
  353. X%include swtools
  354. X%include ioref
  355. Xfunction GetCF;
  356. Xbegin
  357. X    if Eof(openList[fd].fileVar) then begin
  358. X        c := ENDFILE;
  359. X        GetCF := ENDFILE
  360. X    end
  361. X    else if Eoln(openList[fd].fileVar) then begin
  362. X        GetCF := NEWLINE;
  363. X        c := NEWLINE;
  364. X        ReadLn(openList[fd].fileVar);
  365. X    end
  366. X    else begin
  367. X        Read(openList[fd].fileVar,c);
  368. X        GetCF := c;
  369. X    end
  370. Xend;
  371. Xfunction GetC;
  372. Xbegin
  373. X    c := GetCF(c, STDIN);
  374. X    GetC := c;
  375. Xend;
  376. /
  377. echo 'x - getsub.pascal'
  378. sed 's/^X//' > getsub.pascal << '/'
  379. X{
  380. X    Copyright (c) 1981
  381. X    By:    Bell Telephone Laboratories, Inc. and
  382. X        Whitesmiths, Ltd.,
  383. X
  384. X    This software is derived from the book
  385. X        "Software Tools In Pascal", by
  386. X        Brian W. Kernighan and P.J. Plauger
  387. X        Addison-Wesley, 1981
  388. X        ISBN 0-201-10342-7
  389. X
  390. X    Right is hereby granted to freely distribute or duplicate this
  391. X    software, providing distribution or duplication is not for profit
  392. X    or other commerical gain and that this copyright notice remains 
  393. X    intact.
  394. X}
  395. X{ GetSub -- Get substitution pattern and support fcns }
  396. Xsegment GetSub;
  397. X%include swtools
  398. X%include patdef
  399. X%include subdef
  400. X{ GetSub -- Get substitution  pattern and support fcns }
  401. Xfunction GetSub;
  402. Xbegin
  403. X    GetSub := (MakeSub(arg, 1, ENDSTR, sub) > 0)
  404. Xend;
  405. /
  406. echo 'x - gnbchar.pascal'
  407. sed 's/^X//' > gnbchar.pascal << '/'
  408. X{
  409. X    Copyright (c) 1981
  410. X    By:    Bell Telephone Laboratories, Inc. and
  411. X        Whitesmiths, Ltd.,
  412. X
  413. X    This software is derived from the book
  414. X        "Software Tools In Pascal", by
  415. X        Brian W. Kernighan and P.J. Plauger
  416. X        Addison-Wesley, 1981
  417. X        ISBN 0-201-10342-7
  418. X
  419. X    Right is hereby granted to freely distribute or duplicate this
  420. X    software, providing distribution or duplication is not for profit
  421. X    or other commerical gain and that this copyright notice remains 
  422. X    intact.
  423. X}
  424. X{ GNBChar -- Get next non-blank character }
  425. Xsegment GNBChar;
  426. X%include swtools
  427. X%include macdefs
  428. X%include macproc
  429. Xfunction GNBChar;
  430. Xbegin
  431. X    while (s[i] in [BLANK, TAB, NEWLINE]) do
  432. X        i := i + 1;
  433. X    GNBChar := s[i]
  434. Xend {GNBChar};
  435. /
  436. echo 'x - hash.pascal'
  437. sed 's/^X//' > hash.pascal << '/'
  438. X{
  439. X    Copyright (c) 1981
  440. X    By:    Bell Telephone Laboratories, Inc. and
  441. X        Whitesmiths, Ltd.,
  442. X
  443. X    This software is derived from the book
  444. X        "Software Tools In Pascal", by
  445. X        Brian W. Kernighan and P.J. Plauger
  446. X        Addison-Wesley, 1981
  447. X        ISBN 0-201-10342-7
  448. X
  449. X    Right is hereby granted to freely distribute or duplicate this
  450. X    software, providing distribution or duplication is not for profit
  451. X    or other commerical gain and that this copyright notice remains 
  452. X    intact.
  453. X}
  454. X{ Hash -- compute hash function of a name }
  455. Xsegment Hash;
  456. X%include swtools
  457. X%include defdef
  458. X%include defref
  459. X%include defproc
  460. Xfunction Hash;
  461. Xvar
  462. X    i, h: Integer;
  463. Xbegin
  464. X    h := 0;
  465. X    for i := 1 to StrLength(name) do
  466. X        h := (3 * h + Ord(name[i])) mod HASHSIZE;
  467. X    Hash := h + 1
  468. Xend;
  469. /
  470. echo 'x - inithash.pascal'
  471. sed 's/^X//' > inithash.pascal << '/'
  472. X{
  473. X    Copyright (c) 1981
  474. X    By:    Bell Telephone Laboratories, Inc. and
  475. X        Whitesmiths, Ltd.,
  476. X
  477. X    This software is derived from the book
  478. X        "Software Tools In Pascal", by
  479. X        Brian W. Kernighan and P.J. Plauger
  480. X        Addison-Wesley, 1981
  481. X        ISBN 0-201-10342-7
  482. X
  483. X    Right is hereby granted to freely distribute or duplicate this
  484. X    software, providing distribution or duplication is not for profit
  485. X    or other commerical gain and that this copyright notice remains 
  486. X    intact.
  487. X}
  488. X{ InitHash -- initialize hash table to nil }
  489. Xsegment InitHash;
  490. X%include swtools
  491. X%include defdef
  492. X%include defref
  493. X%include defproc
  494. Xprocedure InitHash;
  495. Xvar
  496. X    i: 1..HASHSIZE;
  497. Xbegin
  498. X    nextTab := 1;   { first free slot in table }
  499. X    for i := 1 to HASHSIZE do
  500. X        hashTab[i] := nil
  501. Xend;
  502. /
  503. echo 'x - isalphan.pascal'
  504. sed 's/^X//' > isalphan.pascal << '/'
  505. X{
  506. X    Copyright (c) 1982
  507. X    By:    Chris Lewis
  508. X
  509. X    Right is hereby granted to freely distribute or duplicate this
  510. X    software, providing distribution or duplication is not for profit
  511. X    or other commerical gain and that this copyright notice remains 
  512. X    intact.
  513. X}
  514. X{ IsAlphaNum -- true if c is letter or digit }
  515. Xsegment IsAlphaNum;
  516. X%include swtools
  517. Xfunction IsAlphaNum;
  518. Xbegin
  519. X    IsAlphaNum := ((c >= LETA) and (c <= LETI)) or
  520. X                  ((c >= LETJ) and (c <= LETR)) or
  521. X                  ((c >= LETS) and (c <= LETZ)) or
  522. X                  ((c >= BIGA) and (c <= BIGI)) or
  523. X                  ((c >= BIGJ) and (c <= BIGR)) or
  524. X                  ((c >= BIGS) and (c <= BIGZ)) or
  525. X                  ((c >= DIG0) and (c <= DIG9))
  526. Xend;
  527. /
  528. echo 'x - isdigit.pascal'
  529. sed 's/^X//' > isdigit.pascal << '/'
  530. X{
  531. X    Copyright (c) 1982
  532. X    By:    Chris Lewis
  533. X
  534. X    Right is hereby granted to freely distribute or duplicate this
  535. X    software, providing distribution or duplication is not for profit
  536. X    or other commerical gain and that this copyright notice remains 
  537. X    intact.
  538. X}
  539. X{ IsDigit -- true if c is a digit }
  540. Xsegment IsDigit;
  541. X%include swtools
  542. Xfunction IsDigit;
  543. Xbegin
  544. X    IsDigit := c in [DIG0..DIG9];
  545. Xend;
  546. /
  547. echo 'x - isletter.pascal'
  548. sed 's/^X//' > isletter.pascal << '/'
  549. X{
  550. X    Copyright (c) 1982
  551. X    By:    Chris Lewis
  552. X
  553. X    Right is hereby granted to freely distribute or duplicate this
  554. X    software, providing distribution or duplication is not for profit
  555. X    or other commerical gain and that this copyright notice remains 
  556. X    intact.
  557. X}
  558. X{ IsLetter -- true if c is a letter of either case }
  559. Xsegment IsLetter;
  560. X%include swtools
  561. X%include chardef
  562. Xfunction IsLetter;
  563. Xbegin
  564. X    IsLetter := ChLetter in CharClass(c)
  565. Xend;
  566. /
  567. echo 'x - itoc.pascal'
  568. sed 's/^X//' > itoc.pascal << '/'
  569. X{
  570. X    Copyright (c) 1982
  571. X    By:    Chris Lewis
  572. X
  573. X    Right is hereby granted to freely distribute or duplicate this
  574. X    software, providing distribution or duplication is not for profit
  575. X    or other commerical gain and that this copyright notice remains 
  576. X    intact.
  577. X}
  578. X{ IToC -- convert integer n to char string in s[i] ... }
  579. Xsegment IToC;
  580. X%include swtools
  581. Xfunction IToC;
  582. Xbegin
  583. X    if (n < 0) then begin
  584. X        s[i] := MINUS;
  585. X        IToC := IToC(-n, s, i+1);
  586. X    end
  587. X    else begin
  588. X        if (n >= 10) then
  589. X            i := IToC(n div 10, s, i);
  590. X        s[i] := Chr(n mod 10 + Ord(DIG0));
  591. X        s[i+1] := ENDSTR;
  592. X        IToC := i + 1;
  593. X    end
  594. Xend;
  595. /
  596. echo 'x - makeset.pascal'
  597. sed 's/^X//' > makeset.pascal << '/'
  598. X{
  599. X    Copyright (c) 1981
  600. X    By:    Bell Telephone Laboratories, Inc. and
  601. X        Whitesmiths, Ltd.,
  602. X
  603. X    This software is derived from the book
  604. X        "Software Tools In Pascal", by
  605. X        Brian W. Kernighan and P.J. Plauger
  606. X        Addison-Wesley, 1981
  607. X        ISBN 0-201-10342-7
  608. X
  609. X    Right is hereby granted to freely distribute or duplicate this
  610. X    software, providing distribution or duplication is not for profit
  611. X    or other commerical gain and that this copyright notice remains 
  612. X    intact.
  613. X}
  614. X{ MakeSet -- make set from inset(k) in outset }
  615. Xsegment MakeSet;
  616. X%include swtools
  617. X%include patdef
  618. Xfunction MakeSet;
  619. Xvar
  620. X    j: Integer;
  621. Xbegin
  622. X    j := 1;
  623. X    DoDash(ENDSTR, inSet, k, outSet, j, maxSet);
  624. X    makeSet := AddStr(ENDSTR, outSet, j, maxSet)
  625. Xend;
  626. /
  627. echo 'x - message.pascal'
  628. sed 's/^X//' > message.pascal << '/'
  629. X{
  630. X    Copyright (c) 1982
  631. X    By:    Chris Lewis
  632. X
  633. X    Right is hereby granted to freely distribute or duplicate this
  634. X    software, providing distribution or duplication is not for profit
  635. X    or other commerical gain and that this copyright notice remains 
  636. X    intact.
  637. X}
  638. X{ Message -- print a PASCALVS string on STDERR }
  639. Xsegment Message;
  640. X%include swtools
  641. Xprocedure Message;
  642. Xvar
  643. X    i: 1..MAXSTR;
  644. Xbegin
  645. X    for i := 1 to Length(s) do
  646. X         PutCF(s[i], STDERR);
  647. X    PutCF(NEWLINE,STDERR);
  648. Xend;
  649. /
  650. echo 'x - mustopen.pascal'
  651. sed 's/^X//' > mustopen.pascal << '/'
  652. X{
  653. X    Copyright (c) 1982
  654. X    By:    Chris Lewis
  655. X
  656. X    Right is hereby granted to freely distribute or duplicate this
  657. X    software, providing distribution or duplication is not for profit
  658. X    or other commerical gain and that this copyright notice remains 
  659. X    intact.
  660. X}
  661. X{ MustOpen -- same as FOpen except for no allowance of failure }
  662. Xsegment MustOpen;
  663. X{ mustopen -- open file or die }
  664. X%include swtools
  665. Xfunction MustOpen;
  666. Xvar
  667. X    fd: FileDesc;
  668. Xbegin
  669. X    fd := FOpen(fname, fMode);
  670. X    if (fd = IOERROR) then begin
  671. X        PutStr(fname, STDERR);
  672. X        Error(': can''t open file')
  673. X    end;
  674. X    MustOpen := fd
  675. Xend;
  676. /
  677. echo 'x - nargs.pascal'
  678. sed 's/^X//' > nargs.pascal << '/'
  679. X{
  680. X    Copyright (c) 1982
  681. X    By:    Chris Lewis
  682. X
  683. X    Right is hereby granted to freely distribute or duplicate this
  684. X    software, providing distribution or duplication is not for profit
  685. X    or other commerical gain and that this copyright notice remains 
  686. X    intact.
  687. X}
  688. X{ Nargs (CMS) -- return number of arguments }
  689. Xsegment Nargs;
  690. X%include swtools
  691. X%include ioref
  692. Xfunction NArgs;
  693. Xbegin
  694. X    NArgs := cmdArgs
  695. Xend;
  696. /
  697. echo 'x - pbnum.pascal'
  698. sed 's/^X//' > pbnum.pascal << '/'
  699. X{
  700. X    Copyright (c) 1981
  701. X    By:    Bell Telephone Laboratories, Inc. and
  702. X        Whitesmiths, Ltd.,
  703. X
  704. X    This software is derived from the book
  705. X        "Software Tools In Pascal", by
  706. X        Brian W. Kernighan and P.J. Plauger
  707. X        Addison-Wesley, 1981
  708. X        ISBN 0-201-10342-7
  709. X
  710. X    Right is hereby granted to freely distribute or duplicate this
  711. X    software, providing distribution or duplication is not for profit
  712. X    or other commerical gain and that this copyright notice remains 
  713. X    intact.
  714. X}
  715. X{ PBNum -- Convert number to string, push back on input }
  716. Xsegment PBNum;
  717. X%include swtools
  718. X%include macdefs
  719. X%include macproc
  720. Xprocedure PBNum;
  721. Xvar
  722. X    temp: StringType;
  723. X    junk: Integer;
  724. Xbegin
  725. X    junk := IToC(n, temp, 1);
  726. X    PBStr(temp)
  727. Xend {PBNum};
  728. /
  729. echo 'x - pbstr.pascal'
  730. sed 's/^X//' > pbstr.pascal << '/'
  731. X{
  732. X    Copyright (c) 1981
  733. X    By:    Bell Telephone Laboratories, Inc. and
  734. X        Whitesmiths, Ltd.,
  735. X
  736. X    This software is derived from the book
  737. X        "Software Tools In Pascal", by
  738. X        Brian W. Kernighan and P.J. Plauger
  739. X        Addison-Wesley, 1981
  740. X        ISBN 0-201-10342-7
  741. X
  742. X    Right is hereby granted to freely distribute or duplicate this
  743. X    software, providing distribution or duplication is not for profit
  744. X    or other commerical gain and that this copyright notice remains 
  745. X    intact.
  746. X}
  747. X{ PBStr -- push string back onto input }
  748. Xsegment PBStr;
  749. X%include swtools
  750. X%include defdef
  751. X%include defproc
  752. Xprocedure PBStr;
  753. Xvar
  754. X    i: Integer;
  755. Xbegin
  756. X    for i := StrLength(s) downto 1 do
  757. X        PutBack(s[i])
  758. Xend;
  759. /
  760. echo 'x - progexit.pascal'
  761. sed 's/^X//' > progexit.pascal << '/'
  762. X{
  763. X    Copyright (c) 1982
  764. X    By:    Chris Lewis
  765. X
  766. X    Right is hereby granted to freely distribute or duplicate this
  767. X    software, providing distribution or duplication is not for profit
  768. X    or other commerical gain and that this copyright notice remains 
  769. X    intact.
  770. X}
  771. X{ ProgExit -- Returns a return code and quits }
  772. Xsegment ProgExit;
  773. X%include swtools
  774. Xprocedure ProgExit;
  775. Xbegin
  776. X    RetCode(returnCode);
  777. X    HALT
  778. Xend; {ProgExit}
  779. /
  780. echo 'x - push.pascal'
  781. sed 's/^X//' > push.pascal << '/'
  782. X{
  783. X    Copyright (c) 1981
  784. X    By:    Bell Telephone Laboratories, Inc. and
  785. X        Whitesmiths, Ltd.,
  786. X
  787. X    This software is derived from the book
  788. X        "Software Tools In Pascal", by
  789. X        Brian W. Kernighan and P.J. Plauger
  790. X        Addison-Wesley, 1981
  791. X        ISBN 0-201-10342-7
  792. X
  793. X    Right is hereby granted to freely distribute or duplicate this
  794. X    software, providing distribution or duplication is not for profit
  795. X    or other commerical gain and that this copyright notice remains 
  796. X    intact.
  797. X}
  798. X{ Push -- push ep onto argStk, return new position ap }
  799. Xsegment Push;
  800. X%include swtools
  801. X%include macdefs
  802. X%include macproc
  803. Xfunction Push;
  804. Xbegin
  805. X    if (ap > ARGSIZE) then
  806. X        Error('Macro: argument stack overflow');
  807. X    argStk[ap] := ep;
  808. X    Push := ap + 1
  809. Xend {Push};
  810. /
  811. echo 'x - putback.pascal'
  812. sed 's/^X//' > putback.pascal << '/'
  813. X{
  814. X    Copyright (c) 1981
  815. X    By:    Bell Telephone Laboratories, Inc. and
  816. X        Whitesmiths, Ltd.,
  817. X
  818. X    This software is derived from the book
  819. X        "Software Tools In Pascal", by
  820. X        Brian W. Kernighan and P.J. Plauger
  821. X        Addison-Wesley, 1981
  822. X        ISBN 0-201-10342-7
  823. X
  824. X    Right is hereby granted to freely distribute or duplicate this
  825. X    software, providing distribution or duplication is not for profit
  826. X    or other commerical gain and that this copyright notice remains 
  827. X    intact.
  828. X}
  829. X{ PutBack -- push character back onto input }
  830. Xsegment PutBack;
  831. X%include swtools
  832. X%include defdef
  833. X%include defref
  834. X%include defproc
  835. Xprocedure PutBack;
  836. Xbegin
  837. X    if (bp >= BUFSIZE) then
  838. X        Error('Too many characters pushed back');
  839. X    bp := bp + 1;
  840. X    buf[bp] := c
  841. Xend;
  842. /
  843. echo 'x - putc.pascal'
  844. sed 's/^X//' > putc.pascal << '/'
  845. X{
  846. X    Copyright (c) 1982
  847. X    By:    Chris Lewis
  848. X
  849. X    Right is hereby granted to freely distribute or duplicate this
  850. X    software, providing distribution or duplication is not for profit
  851. X    or other commerical gain and that this copyright notice remains 
  852. X    intact.
  853. X}
  854. X{ PutC -- print character to STDOUT }
  855. Xsegment PutC;
  856. X%include swtools
  857. Xprocedure PutC;
  858. Xbegin
  859. X    PutCF(c, STDOUT)
  860. Xend;
  861. /
  862. echo 'x - putcf.pascal'
  863. sed 's/^X//' > putcf.pascal << '/'
  864. X{
  865. X    Copyright (c) 1982
  866. X    By:    Chris Lewis
  867. X
  868. X    Right is hereby granted to freely distribute or duplicate this
  869. X    software, providing distribution or duplication is not for profit
  870. X    or other commerical gain and that this copyright notice remains 
  871. X    intact.
  872. X}
  873. X{ PutCF -- put string out on file }
  874. Xsegment PutCF;
  875. X%include swtools
  876. X%include ioref
  877. Xprocedure PutCF;
  878. Xbegin
  879. X    if openList[fd].mode = IOAVAIL then
  880. X        Error('putcf on unopen file');
  881. X    if c = NEWLINE then
  882. X        writeln(openList[fd].fileVar)
  883. X    else
  884. X        write(openList[fd].fileVar, c)
  885. Xend;
  886. /
  887. echo 'x - putdec.pascal'
  888. sed 's/^X//' > putdec.pascal << '/'
  889. X{
  890. X    Copyright (c) 1981
  891. X    By:    Bell Telephone Laboratories, Inc. and
  892. X        Whitesmiths, Ltd.,
  893. X
  894. X    This software is derived from the book
  895. X        "Software Tools In Pascal", by
  896. X        Brian W. Kernighan and P.J. Plauger
  897. X        Addison-Wesley, 1981
  898. X        ISBN 0-201-10342-7
  899. X
  900. X    Right is hereby granted to freely distribute or duplicate this
  901. X    software, providing distribution or duplication is not for profit
  902. X    or other commerical gain and that this copyright notice remains 
  903. X    intact.
  904. X}
  905. X{ PutDec -- put decimal integer n in field width >= w }
  906. Xsegment PutDec;
  907. X%include swtools
  908. Xprocedure PutDec;
  909. Xvar
  910. X    i, nd: Integer;
  911. X    s: StringType;
  912. Xbegin
  913. X    nd := itoc(n, s, 1);
  914. X    for i := nd to w do
  915. X        PutC(BLANK);
  916. X    for i := 1 to nd-1 do
  917. X        PutC(s[i])
  918. Xend;
  919. /
  920. echo 'x - puttok.pascal'
  921. sed 's/^X//' > puttok.pascal << '/'
  922. X{
  923. X    Copyright (c) 1981
  924. X    By:    Bell Telephone Laboratories, Inc. and
  925. X        Whitesmiths, Ltd.,
  926. X
  927. X    This software is derived from the book
  928. X        "Software Tools In Pascal", by
  929. X        Brian W. Kernighan and P.J. Plauger
  930. X        Addison-Wesley, 1981
  931. X        ISBN 0-201-10342-7
  932. X
  933. X    Right is hereby granted to freely distribute or duplicate this
  934. X    software, providing distribution or duplication is not for profit
  935. X    or other commerical gain and that this copyright notice remains 
  936. X    intact.
  937. X}
  938. X{ PutTok -- put token on output or evaluation stack }
  939. Xsegment PutTok;
  940. X%include swtools
  941. X%include macdefs
  942. X%include macproc
  943. Xprocedure PutTok;
  944. Xvar
  945. X    i: Integer;
  946. Xbegin
  947. X    i := 1;
  948. X    while s[i] <> ENDSTR do begin
  949. X        PutChr(s[i]);
  950. X        i := i + 1
  951. X    end {while};
  952. Xend {PutTok};
  953. /
  954. echo 'x - remove.pascal'
  955. sed 's/^X//' > remove.pascal << '/'
  956. X{
  957. X    Copyright (c) 1982
  958. X    By:    Chris Lewis
  959. X
  960. X    Right is hereby granted to freely distribute or duplicate this
  961. X    software, providing distribution or duplication is not for profit
  962. X    or other commerical gain and that this copyright notice remains 
  963. X    intact.
  964. X}
  965. X{ Remove -- remove a file - very tricky }
  966. Xsegment Remove;
  967. X%include swtools
  968. X%include cms
  969. Xprocedure Remove;
  970. Xvar
  971. X    cmsString: String(MAXSTR);
  972. X    returnCode: Integer;
  973. X    i: 1..MAXSTR;
  974. Xbegin
  975. X    cmsString := 'ERASE ';
  976. X    for i := 1 TO StrLength(name) do
  977. X        if name[i] in [NEWLINE, PERIOD] then
  978. X            cmsString := cmsString || Str(' ')
  979. X        else
  980. X            cmsString := cmsString || Str(name[i]);
  981. X    Cms(cmsString, returnCode);
  982. Xend;
  983. /
  984. echo 'x - scopy.pascal'
  985. sed 's/^X//' > scopy.pascal << '/'
  986. X{
  987. X    Copyright (c) 1981
  988. X    By:    Bell Telephone Laboratories, Inc. and
  989. X        Whitesmiths, Ltd.,
  990. X
  991. X    This software is derived from the book
  992. X        "Software Tools In Pascal", by
  993. X        Brian W. Kernighan and P.J. Plauger
  994. X        Addison-Wesley, 1981
  995. X        ISBN 0-201-10342-7
  996. X
  997. X    Right is hereby granted to freely distribute or duplicate this
  998. X    software, providing distribution or duplication is not for profit
  999. X    or other commerical gain and that this copyright notice remains 
  1000. X    intact.
  1001. X}
  1002. X{ SCopy (CMS) -- copy strings }
  1003. Xsegment SCopy;
  1004. X%include swtools
  1005. Xprocedure SCopy;
  1006. Xbegin
  1007. X    while(src[i] <> ENDSTR) do begin
  1008. X        dest[j] := src[i];
  1009. X        i := i + 1;
  1010. X        j := j + 1;
  1011. X    end;
  1012. X    dest[j] := ENDSTR;
  1013. Xend;
  1014. /
  1015. echo 'x - skipbl.pascal'
  1016. sed 's/^X//' > skipbl.pascal << '/'
  1017. X{
  1018. X    Copyright (c) 1981
  1019. X    By:    Bell Telephone Laboratories, Inc. and
  1020. X        Whitesmiths, Ltd.,
  1021. X
  1022. X    This software is derived from the book
  1023. X        "Software Tools In Pascal", by
  1024. X        Brian W. Kernighan and P.J. Plauger
  1025. X        Addison-Wesley, 1981
  1026. X        ISBN 0-201-10342-7
  1027. X
  1028. X    Right is hereby granted to freely distribute or duplicate this
  1029. X    software, providing distribution or duplication is not for profit
  1030. X    or other commerical gain and that this copyright notice remains 
  1031. X    intact.
  1032. X}
  1033. X{ SkipBl -- skip blanks and tabs s[i] ... }
  1034. Xsegment SkipBl;
  1035. X%include swtools
  1036. X%include editcons
  1037. X%include edittype
  1038. X%include editproc
  1039. Xprocedure SkipBl;
  1040. Xbegin
  1041. X    while (s[i] = BLANK) or (s[i] = TAB) do
  1042. X        i := i + 1
  1043. Xend;
  1044. /
  1045. echo 'x - strlengt.pascal'
  1046. sed 's/^X//' > strlengt.pascal << '/'
  1047. X{
  1048. X    Copyright (c) 1981
  1049. X    By:    Bell Telephone Laboratories, Inc. and
  1050. X        Whitesmiths, Ltd.,
  1051. X
  1052. X    This software is derived from the book
  1053. X        "Software Tools In Pascal", by
  1054. X        Brian W. Kernighan and P.J. Plauger
  1055. X        Addison-Wesley, 1981
  1056. X        ISBN 0-201-10342-7
  1057. X
  1058. X    Right is hereby granted to freely distribute or duplicate this
  1059. X    software, providing distribution or duplication is not for profit
  1060. X    or other commerical gain and that this copyright notice remains 
  1061. X    intact.
  1062. X}
  1063. X{ StrLength -- determine length of swtools string }
  1064. Xsegment StrLength;
  1065. X%include swtools
  1066. Xfunction StrLength;
  1067. Xvar
  1068. X    i: Integer;
  1069. Xbegin
  1070. X    i := LBound(s);
  1071. X    while (s[i] <> ENDSTR) and (i < MAXSTR) do
  1072. X        i := i + 1;
  1073. X    StrLength := i - LBound(s)
  1074. Xend;
  1075. /
  1076. echo 'x - swprin1.exec'
  1077. sed 's/^X//' > swprin1.exec << '/'
  1078. X&TRACE OFF
  1079. XEXEC TIMEFOR SWTOOLS LDATE C &1 &2 &3 PRINT &1 &2 &3
  1080. /
  1081. echo 'x - swtpc.exec'
  1082. sed 's/^X//' > swtpc.exec << '/'
  1083. X&CONTROL ERROR
  1084. XSTATE &1 PASCAL *
  1085. X&IF &RETCODE NE 0 &EXIT
  1086. XEXEC PASCALVS &1 (LIB(SWTOOLS) NOPRINT NOGOS NOCHECK NODEBUG &2 &3 &4 &5 &6
  1087. X&IF &RETCODE > 4 &EXIT &RETCODE
  1088. XTXTLIB DEL SWTOOLS &1
  1089. XTXTLIB ADD SWTOOLS &1
  1090. /
  1091. echo 'Part 06 of pack.out complete.'
  1092. exit
  1093.  
  1094.  
  1095.