home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / strings / part1 next >
Encoding:
Internet Message Format  |  1986-11-30  |  55.0 KB

  1. Subject: strings (1 of 3)
  2. Newsgroups: mod.sources
  3. Approved: jpn@panda.UUCP
  4.  
  5. Mod.sources:  Volume 4, Issue 110
  6. Submitted by: <talcott!wjh12!maynard!campbell>
  7.  
  8. This is a public domain strings package written by Richard O'Keefe
  9. (whose net address I've lost) that was originally posted to
  10. net.sources about two years ago.  Just about every Unix-oid strings
  11. function you've ever heard of is here.
  12.  
  13. I haven't touched any of this code; I'm just reposting it.  I have used
  14. many of the routines and all the ones I've used work.  The package is
  15. very well put together and coded -- hats off to Richard.
  16. --
  17. Larry Campbell                                 The Boston Software Works, Inc.
  18. ARPA: maynard.UUCP:campbell@harvard.ARPA       120 Fulton Street
  19. UUCP: {harvard,cbosgd}!wjh12!maynard!campbell  Boston MA 02109
  20.  
  21.  
  22. #!/bin/sh
  23. # shar:    Shell Archiver
  24. #    Run the following text with /bin/sh to create:
  25. #    Makefile
  26. #    READ-ME
  27. #    _c2type.c
  28. #    _str2map.c
  29. #    _str2map.h
  30. #    _str2pat.c
  31. #    _str2pat.h
  32. #    _str2set.c
  33. #    _str2set.h
  34. #    ascii.h
  35. #    bcmp.c
  36. #    bcopy.c
  37. #    bfill.c
  38. #    bmove.c
  39. #    bzero.c
  40. #    ctypes.dem
  41. #    ctypes.h
  42. #    ffs.c
  43. #    getopt.3
  44. #    getopt.c
  45. #    int2str.c
  46. #    memccpy.c
  47. #    memchr.c
  48. #    memcmp.c
  49. #    memcpy.c
  50. #    memmov.c
  51. #    memory.h
  52. #    memrchr.c
  53. #    memrev.c
  54. #    memset.c
  55. #    memtrans.c
  56. sed 's/^X//' << 'SHAR_EOF' > Makefile
  57. X#   File   : strings.d/Makefile
  58. X#   Author : Richard A. O'Keefe.
  59. X#   Updated: 2 June 1984.
  60. X#   Purpose: UNIX make(1)file for the strings library.
  61. X
  62. X#   If you are not using a Vax, or if your strings might be 2^16
  63. X#   characters long or longer, use
  64. X#   CFLAGS=-O
  65. X#   On the Vax we can use the string instructions some but not all the time.
  66. XCFLAGS=-O -DVaxAsm
  67. X
  68. X#   The SIII functions are the ones described in the System III
  69. X#   string(3) manual page, and also in ctype(3), atoi(3).
  70. X
  71. XSIII=strcat.o strncat.o strcmp.o strncmp.o strcpy.o strncpy.o strlen.o\
  72. X    strchr.o strrchr.o strpbrk.o strspn.o strcspn.o strtok.o\
  73. X    _c2type.o str2int.o getopt.o
  74. X
  75. X#   The Sys5 functions are the ones described in the System V
  76. X#   memory(3C) manual page.  mem{mov,rchr,rev} are in "mine".
  77. X
  78. XSys5=memccpy.o memchr.o memcmp.o memcpy.o memmov.o memrchr.o memset.o
  79. X
  80. X#   The BSD2 functions are the ones described in the 4.2bsd
  81. X#   bstring(3) manual page, plus a couple of my additions.
  82. X#   All except ffs have VAX-specific machine code versions.
  83. X
  84. XBSD2=bcmp.o bcopy.o bfill.o bmove.o bzero.o ffs.o
  85. X
  86. X#   The "xstr" functions are Tony Hansen's "xstring(3c)" package with
  87. X#   some additions of mine.  All the code is mine, the names are his.
  88. X#   It is not clear whether his strxncpy pads with NULs as strncpy does.
  89. X#   In this package str[x]n{cpy,mov} all pad to exactly len chars with NUL.
  90. X
  91. Xxstr=strxcat.o strxcpy.o strxmov.o strxncat.o strxncpy.o strxnmov.o
  92. X
  93. X#   The "mine" functions are the ones which are entirely my own
  94. X#   invention, though they are supposed to fit into the SIII conventions.
  95. X
  96. Xmine=strmov.o strnmov.o strrpt.o strnrpt.o strend.o strnlen.o strcpbrk.o\
  97. X    strpack.o strcpack.o strtrans.o strntrans.o strpref.o strsuff.o\
  98. X    strtrim.o strctrim.o strfield.o strkey.o int2str.o substr.o\
  99. X    strnend.o strconc.o strrev.o strnrev.o _str2map.o _str2set.o\
  100. X    memmov.o memrchr.o memrev.o
  101. X
  102. X#   The "find" functions are my code, but they are based on published
  103. X#   work by Boyer, Moore, and Hospool.  (See _str2pat.c.)
  104. X
  105. Xfind=strfind.o strrepl.o
  106. X
  107. Xstrings.a: ${SIII} ${Sys5} ${BSD2} ${xstr} ${mine} ${find}
  108. X    rm strings.a; ar rc strings.a *.o; ranlib strings.a
  109. X
  110. Xscan=strpbrk.o strcprbk.o strspn.o strcspn.o strpack.o strcpack.o \
  111. X    strtrim.o strctrim.o strtok.o
  112. X
  113. X${scan} _str2set.o: _str2set.h
  114. X
  115. Xtran=strtrans.o strntrans.o
  116. X
  117. X${tran} _str2map.o: _str2map.h
  118. X
  119. X${find}: _str2pat.h
  120. X
  121. Xstr2int.o: ctypes.h
  122. X
  123. X${SIII} ${Sys5} ${BSD2} ${mine} ${xstr} ${find}: strings.h
  124. X
  125. Xclean:
  126. X    -rm *.o
  127. X
  128. X#   The compilations should be done with the sources and headers in the
  129. X#   same directory.  However, users should find everything in the proper
  130. X#   places: /usr/include/{strings,memory}.h and /usr/lib/strings.a
  131. X#   /usr/local/lib would be ok.  Why is there no /usr/local/include?
  132. X
  133. Xinstall:
  134. X    cp memory.h strings.h /usr/include
  135. X    mv strings.a /usr/lib
  136. SHAR_EOF
  137. sed 's/^X//' << 'SHAR_EOF' > READ-ME
  138. XFile   : READ-ME
  139. XAuthor : Richard A. O'Keefe.
  140. XUpdated: 1 June 1984.
  141. XPurpose: Explain the new strings package.
  142. X
  143. X    The UNIX string libraries (described in the string(3) manual page)
  144. Xdiffer from UNIX to UNIX (e.g. strtok is not in V7 or 4.1bsd).  Worse,
  145. Xthe sources are not in the public domain, so that if there is a string
  146. Xroutine which is nearly what you want but not quite you can't  take  a
  147. Xcopy  and  modify it.  And of course C programmers on non-UNIX systems
  148. Xare at the mercy of their supplier.
  149. X
  150. X    This package was designed to let me do reasonable things with  C's
  151. Xstrings  whatever UNIX (V7, PaNiX, UX63, 4.1bsd) I happen to be using.
  152. XEverything in the System III manual is here and does just what the  S3
  153. Xmanual  says  it does.  There are also lots of new goodies.  I'm sorry
  154. Xabout the names, but the routines do have to work  on  asphyxiated-at-
  155. Xbirth  systems  which  truncate identifiers.  The convention is that a
  156. Xroutine is called
  157. X    str [n] [c] <operation>
  158. XIf there is an "n", it means that the function takes an (int) "length"
  159. Xargument, which bounds the number of characters to be moved or  looked
  160. Xat.  If the function has a "set" argument, a "c" in the name indicates
  161. Xthat  the complement of the set is used.  Functions or variables whose
  162. Xnames start with _ are support routines which aren't really meant  for
  163. Xgeneral  use.  I don't know what the "p" is doing in "strpbrk", but it
  164. Xis there in the S3 manual so it's here too.  "istrtok" does not follow
  165. Xthis rule, but with 7 letters what can you do?
  166. X
  167. X    I have included new versions of atoi(3) and atol(3) as well.  They
  168. Xuse a new primitive str2int, which takes a pair of bounds and a radix,
  169. Xand does much more thorough checking than the normal atoi and atol do.
  170. XThe result returned by atoi & atol is valid if and only if errno == 0.
  171. XThere is also an output conversion routine int2str, with itoa and ltoa
  172. Xas interface macros.  Only after writing int2str did I notice that the
  173. Xstr2int routine has no provision for unsigned numbers.  On reflection,
  174. XI don't greatly care.   I'm afraid that int2str may depend on your "C"
  175. Xcompiler in unexpected ways.  Do check the code with -S.
  176. X
  177. X    Several of these routines have "asm" inclusions conditional on the
  178. XVaxAsm option.  These insertions can make the routines which have them
  179. Xquite a bit faster, but there is a snag.  The VAX architects, for some
  180. Xreason best known to themselves and their therapists, decided that all
  181. X"strings" were shorter than 2^16 bytes.  Even when the length operands
  182. Xare in 32-bit registers, only 16 bits count.  So the "asm" versions do
  183. Xnot work for long strings.  If you can guarantee that all your strings
  184. Xwill be short, define VaxAsm in the makefile, but in general, and when
  185. Xusing other machines, do not define it.
  186. X
  187. X    Thanks to someone on the net who saw the first posting of strings,
  188. Xand sent me a formatted copy of the System V memory(3C) manual page, I
  189. Xhave been able to include versions of these routines.   The convention
  190. Xis that they are called
  191. X    mem{operation}([dst,] ... , len)
  192. Xwhere operation is cpy, cmp, chr, and so on, and len is how many bytes
  193. Xto move or test.  Note that this is different from the strn functions,
  194. X    str{operation}    -- stop when you find a NUL character
  195. X    strn{operation}    -- stop when len is exhausted or you find NUL
  196. X    mem{operation}    -- stop when len is exhausted
  197. X    b{operation}    -- stop when len is exhausted
  198. Xbut the b family has different argument orders or different results or
  199. Xboth.  In particular, note that my implementation of bcmp does conform
  200. Xto the letter of the 4.2bsd manual page, but I decided to make it give
  201. Xa value I have often wanted, which is not like the value of strcmp. As
  202. Xthe System V manual page is more explicit about the return code memcmp
  203. XDOES return a value like strcmp, so you may prefer to use it.  BEWARE:
  204. Xthe "c" in the name mem-c-cpy doesn't mean what it does in the System3
  205. Xnames, it's more like mem-chr-cpy.
  206. X
  207. X    To use this library, you need the "strings.a" library file and the
  208. X"strings.h" header file.  The other header files are for compiling the
  209. Xlibrary itself, though if you are hacking extensions you may find them
  210. Xuseful.  General users really shouldn't see them.  I've defined a  few
  211. Xmacros  I find useful in "strings.h"; if you have no need for "index",
  212. X"rindex", "streql", and "beql", just edit them  out.   On  the  4.1bsd
  213. Xsystem  I  am using, having all these functions 'extern' does not mean
  214. Xthat they will all be loaded; only the ones you call are.  When  using
  215. Xlesser  systems you may find it necessary to break strings.h up or you
  216. Xcould get by with just adding "extern" declarations for  functions  as
  217. Xyou  need  them.   Note  that  as  many  of these functions have names
  218. Xmatching "standard C library" names (by design, this is  after  all  a
  219. Xreplacement/reimplementation  of part of that library) you may have to
  220. Xtalk the loader into loading this library first.  Again, I've found no
  221. Xproblems on 4.1bsd.
  222. X
  223. X    A note on character comparison.  The various UNIX manuals come out
  224. Xand say explicitly that the *cmp and *chr routines use the computer's
  225. X"native" character comparison.  That is, on a PDP-11, VAX-11, and some
  226. Xother machines, signed character comparison is used, and the byte 0377
  227. Xwill never be located (use -1).   On IBM 370s and many other machines,
  228. Xunsigned character comparison is used, and the byte -1 can't be found.
  229. X(Use 0377.)  If you have occasion to use 8-bit byte values in calls to
  230. X*chr functions, it would be nice if the package looked after making it
  231. Xwork portably.  I thought about that, and decided not to do it, as you
  232. Xmight *want* to write VAX code that didn't find 128, and might rely on
  233. Xthe current effect. However, you should be able to use 8-bit values in
  234. Xa portable fashion if you ask, and that the package DOES do for you.
  235. XThere is a macro
  236. X    int2char(c)
  237. Xwhich takes the bottom 8 bits of c on a machine with unsigned character
  238. Xcomparison or sign-extends them on a machine with signed comparison. It
  239. Xis up to you to use this macro in appropriate places.  It is up to who-
  240. Xever installs the package to make sure that the right definition is put
  241. Xin and the wrong one commented out.
  242. X
  243. X    You may wonder at my failure to provide manual pages for this  code.
  244. XFor  the things in V7, 4.?, or SIII, you should be able to use whichever
  245. Xmanual page came with that system, and anything I might write  would  be
  246. Xso  like it as to raise suspicions of violating AT&T copyrights.  In the
  247. Xsources you will find comments which provide far more documentation  for
  248. Xthese  routines  than AT&T ever provided for their strings stuff, I just
  249. Xdon't happen to have put it in nroff -man form.   Had I done so, the *.3
  250. Xfiles would have outbulked the .c files!
  251. X
  252. X    There is a manual page for the strx family of routines.   It was the
  253. Xwork of Tony Hansen, of AT&T Information Systems Lincroft NJ.  It is not
  254. Xclear whether I should distribute this manual page or not,  but as these
  255. Xfunctions are not likely to documented anywhere else I decided to risk
  256. Xit.  There is no risk in the *code* however.  His posting to net.sources
  257. Xarrived at Edinburgh with just the reason for reposting, and the manual
  258. Xpage.  The code is my own work based on his manual page.  Indeed, I had
  259. Xalready written strx[n]mov, using different names.
  260. X
  261. X    These files are in the public domain.  This includes getopt.c, which
  262. Xis the work of Henry Spencer, University of Toronto Zoology, who says of
  263. Xit "None of this software is derived from Bell software. I had no access
  264. Xto the source for Bell's versions at the time I wrote it.  This software
  265. Xis hereby explicitly placed in the public domain.  It may  be  used  for
  266. Xany purpose on any machine by anyone." I would greatly prefer it if *my*
  267. Xmaterial received no military use.
  268. X
  269. SHAR_EOF
  270. sed 's/^X//' << 'SHAR_EOF' > _c2type.c
  271. X/*  File   : _c2type.c
  272. X    Author : Richard A. O'Keefe.
  273. X    Updated: 23 April 1984
  274. X    Purpose: Map character codes to types
  275. X
  276. X    The mapping used here is such that we can use it for converting
  277. X    numbers expressed in a variety of radices to binary as well as for
  278. X    classifying characters.
  279. X*/
  280. X
  281. Xchar _c2type[129] =
  282. X    {    37,            /* EOF == -1 */
  283. X    37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 39, 39, 39, 39, 37, 37,
  284. X    37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
  285. X    38, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
  286. X    00, 01, 02, 03, 04, 05, 06, 07,  8,  9, 36, 36, 36, 36, 36, 36,
  287. X    36, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  288. X    25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 36, 36, 36, 36,
  289. X    36, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  290. X    25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 36, 36, 36, 36
  291. X    };
  292. X
  293. SHAR_EOF
  294. sed 's/^X//' << 'SHAR_EOF' > _str2map.c
  295. X/*  File   : _str2map.c
  296. X    Author : Richard A. O'Keefe.
  297. X    Updated: 20 April 1984
  298. X    Defines: _map_vec[], _str2map().
  299. X
  300. X    _str2map(option, from, to) constructs a translation table.  If  from
  301. X    or to is NullS, the same string is used as last time, so if you want
  302. X    to translate a whole lot of strings using the same mapping you don't
  303. X    have to reconstruct it each time.  The options are
  304. X
  305. X    0: initialise the map to the identity function,
  306. X       then map each from[i] to the corresponding to[i].
  307. X       If to[] is shorter than from[], its last character is
  308. X       repeated as often as needed.
  309. X
  310. X    1: as 0, but don't initialise the map.
  311. X
  312. X    2: initialise the map to send every character to to[0],
  313. X       then map each from[i] to itself.
  314. X
  315. X    For example, to build a map which forces letters to lower case but
  316. X    sends everything else to blank, call
  317. X
  318. X    _str2map(2, "abcdefghijklmnopqrstuvwxyz", " ");
  319. X    _str2map(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz");
  320. X
  321. X    Only strtrans() and strntrans() in this package  call  _str2map;  if
  322. X    you  want  to  build your own maps this way you can "fool" them into
  323. X    using it, as when the two strings are NullS they  don't  change  the
  324. X    map.   As an extra-special dubious *hack*, _map_vec has an extra NUL
  325. X    character at the end, so after calling _str2map(0, "", ""), you  can
  326. X    use  _map_vec+1 as a string of the 127 non-NUL characters (or if the
  327. X    _AlphabetSize is 256, of the 255 non-NUL characters).
  328. X*/
  329. X
  330. X#include "strings.h"
  331. X#include "_str2map.h"
  332. X
  333. Xstatic    _char_    *oldFrom = "?";
  334. Xstatic    char    *oldTo   = "?";
  335. X
  336. Xchar    _map_vec[_AlphabetSize+1];
  337. X
  338. Xvoid _str2map(option, from, to)
  339. X    int option;
  340. X    register _char_ *from;
  341. X    register char *to;
  342. X    {
  343. X    register int i, c;
  344. X
  345. X    if (from == NullS && to == NullS) return;
  346. X    if (from == NullS) from = oldFrom; else oldFrom = from;
  347. X    if (to   == NullS) to   = oldTo;   else oldTo   = to;
  348. X    switch (option) {
  349. X        case 0:
  350. X        for (i = _AlphabetSize; --i >= 0; _map_vec[i] = i) ;
  351. X        case 1:
  352. X        while (i = *from++) {
  353. X            _map_vec[i] = *to++;
  354. X            if (!*to) {
  355. X            c = *--to;
  356. X            while (i = *from++) _map_vec[i] = c;
  357. X            return;
  358. X            }
  359. X        }
  360. X        return;
  361. X        case 2:
  362. X        c = *to;
  363. X        for (i = _AlphabetSize; --i >= 0; _map_vec[i] = c) ;
  364. X        while (c = *from++) _map_vec[c] = c;
  365. X        return;
  366. X    }
  367. X    }
  368. X
  369. SHAR_EOF
  370. sed 's/^X//' << 'SHAR_EOF' > _str2map.h
  371. X/*  File   : _str2map.h
  372. X    Author : Richard A. O'Keefe.
  373. X    Updated: 11 April 1984
  374. X    Purpose: Definitions from _str2map.c
  375. X*/
  376. X
  377. Xextern    char    _map_vec[_AlphabetSize+1];
  378. Xextern    void    _str2map(/*int,_char_^,char^*/);
  379. X
  380. SHAR_EOF
  381. sed 's/^X//' << 'SHAR_EOF' > _str2pat.c
  382. X/*  File   : _str2pat.c
  383. X    Author : Richard A. O'Keefe.
  384. X    Updated: 2 June 1984
  385. X    Defines: _pat_lim, _pat_vec[], _str2pat()
  386. X
  387. X    Searching in this package is done by an algorithm due  to  R.  Nigel
  388. X    Hospool,  described  in  Software  Practice & Experience 1980, p505.
  389. X    Elsewhere I have a version of it which does  exact  case  or  either
  390. X    case  match,  word  more or literal mode, forwards or backwards, and
  391. X    will look for the Nth instance.  For most applications that  is  too
  392. X    much  and  a  simple  exact  case forward search will do.  Hospool's
  393. X    algorithm is a simplification of  the  Boyer-Moore  algorithm  which
  394. X    doesn't  guarantee linear time, but in practice is very good indeed.
  395. X
  396. X    _str2pat(pat) builds a search table for the string pat.  As usual in
  397. X    this pacakge, if pat == NullS, the table is not changed and the last
  398. X    search string is re-used.  To support  this,  _str2pat  returns  the
  399. X    actual search string.
  400. X*/
  401. X
  402. X#include "strings.h"
  403. X#include "_str2pat.h"
  404. X
  405. Xint    _pat_lim;
  406. Xint    _pat_vec[_AlphabetSize];
  407. Xstatic    _char_    *oldPat = "";
  408. X
  409. X
  410. X_char_ *_str2pat(pat)
  411. X    register _char_ *pat;
  412. X    {
  413. X    register int L, i;
  414. X
  415. X    if (pat == NullS) pat = oldPat; else oldPat = pat;
  416. X    for (L = 0; *pat++; L++) ;
  417. X    for (i = _AlphabetSize; --i >= 0; _pat_vec[i] = L) ;
  418. X    for (pat = oldPat, i = L; --i > 0; _pat_vec[*pat++] = i) ;
  419. X    _pat_lim = --L;
  420. X    return oldPat;
  421. X    }
  422. X
  423. SHAR_EOF
  424. sed 's/^X//' << 'SHAR_EOF' > _str2pat.h
  425. X/*  File   : _str2pat.h
  426. X    Author : Richard A. O'Keefe.
  427. X    Updated: 20 April 1984
  428. X    Purpose: Definitions from _str2pat.c
  429. X*/
  430. X
  431. Xextern    int    _pat_lim;
  432. Xextern    int    _pat_vec[];
  433. Xextern    _char_    *_str2pat(/*_char_^*/);
  434. X
  435. SHAR_EOF
  436. sed 's/^X//' << 'SHAR_EOF' > _str2set.c
  437. X/*  File   : _str2set.c
  438. X    Author : Richard A. O'Keefe.
  439. X    Updated: 20 April 1984
  440. X    Defines: _set_ctr, _set_vec[], _str2set().
  441. X    Purpose: Convert a character string to a set.
  442. X*/
  443. X
  444. X/*  The obvious way of representing a set of characters  is  as  a
  445. X    vector  of 0s and 1s.  The snag with that is that to convert a
  446. X    string to such a vector, we have to clear all the elements  to
  447. X    0,  and  then  set the elements corresponding to characters in
  448. X    the string to 1, so the cost is  O(|alphabet|+|string|).  This
  449. X    package  uses another method, where there is a vector of small
  450. X    numbers and a counter.  A character is in the current  set  if
  451. X    and  only  if the corresponding element of the vector is equal
  452. X    to the current value of  the  counter.   Every  so  often  the
  453. X    vector  elements  would  overflow  and  we  have  to clear the
  454. X    vector, but the cost is reduced to O(|string|+1).
  455. X
  456. X    Note that NUL ('\0') will never be in any set built by str2set.
  457. X
  458. X    While this method reduces the cost of building a set, it would
  459. X    be useful to avoid it entirely.  So when the "set" argument is
  460. X    NullS the set is not changed.  Use NullS to mean "the same set
  461. X    as before."  MaxPosChar is the largest integer value which can
  462. X    be stored in a "char".  Although we might get a slightly wider
  463. X    range by using "unsigned char", "char" may be cheaper (as on a
  464. X    PDP-11).  By all means change the number from 127 if your C is
  465. X    one of those that treats char as unsigned, but don't change it
  466. X    just because _AlphabetSize is 256, the two are unrelated.  And
  467. X    don't dare change it on a VAX: it is built into the asm code!
  468. X*/
  469. X
  470. X#include "strings.h"
  471. X#include "_str2set.h"
  472. X
  473. X#if    CharsAreSigned
  474. X#define    MaxPosChar    127
  475. X#else  ~CharsAreSigned
  476. X#define MaxPosChar    255
  477. X#endif    CharsAreSigned
  478. X
  479. Xint  _set_ctr = MaxPosChar;
  480. Xchar _set_vec[_AlphabetSize];
  481. X
  482. X
  483. Xvoid _str2set(set)
  484. X    register char *set;
  485. X    {
  486. X    if (set == NullS) return;
  487. X    if (++_set_ctr == MaxPosChar+1) {
  488. X#if    VaxAsm
  489. X        asm("movc5 $0,4(ap),$0,$128,__set_vec");
  490. X#else  ~VaxAsm
  491. X        register char *w = &_set_vec[_AlphabetSize];
  492. X        do *--w = NUL; while (w != &_set_vec[0]);
  493. X#endif    VaxAsm
  494. X        _set_ctr = 1;
  495. X    }
  496. X    while (*set) _set_vec[*set++] = _set_ctr;
  497. X    }
  498. X
  499. SHAR_EOF
  500. sed 's/^X//' << 'SHAR_EOF' > _str2set.h
  501. X/*  File   : _str2set.h
  502. X    Updated: 10 April 1984
  503. X    Purpose: External declarations for strprbk, strspn, strcspn &c
  504. X    Copyright (C) 1984 Richard A. O'Keefe.
  505. X*/
  506. X
  507. Xextern    int    _set_ctr;
  508. Xextern    char    _set_vec[];
  509. Xextern    void    _str2set(/*char^*/);
  510. X
  511. SHAR_EOF
  512. sed 's/^X//' << 'SHAR_EOF' > ascii.h
  513. X/*  File   : strings.d/ascii.h
  514. X    Author : Richard A. O'Keefe
  515. X    Updated: 28 April 1984
  516. X    Purpose: Define Ascii mnemonics.
  517. X
  518. X    This file defines the ASCII control characters.  Note that these
  519. X    names refer to their use in communication; it is an ERROR to use
  520. X    these names to talk about keyboard commands.  For example, DO NOT
  521. X    use EOT when you mean "end of file", as many people prefer ^Z (if
  522. X    the Ascii code were taken seriously, EOT would log you off and
  523. X    hang up the line as well).  Similarly, DO NOT use DEL when you
  524. X    mean "interrupt", many people prefer ^C.  When writing a screen
  525. X    editor, you should speak of tocntrl('C') rather than ETX (see the
  526. X    header file "ctypes.h").
  527. X*/
  528. X
  529. X#define NUL    '\000'    /* null character */
  530. X#define SOH    '\001'    /* Start Of Heading, start of message */
  531. X#define STX    '\002'    /* Start Of Text, end of address */
  532. X#define    ETX    '\003'    /* End of TeXt, end of message */
  533. X#define EOT    '\004'    /* End Of Transmission */
  534. X#define    ENQ    '\005'    /* ENQuiry "who are you" */
  535. X#define ACK    '\006'    /* (positive) ACKnowledge */
  536. X#define    BEL    '\007'    /* ring the BELl */
  537. X#define    BS    '\010'    /* BackSpace */
  538. X#define    HT    '\011'    /* Horizontal Tab */
  539. X#define    TAB    '\011'    /* an unofficial name for HT */
  540. X#define    LF    '\012'    /* Line Feed (does not imply cr) */
  541. X#define    NL    '\012'    /* unix unofficial name for LF: new line */
  542. X#define    VT    '\013'    /* Vertical Tab */
  543. X#define    FF    '\014'    /* Form Feed (new page starts AFTER this) */
  544. X#define    CR    '\015'    /* Carriage Return */
  545. X#define    SO    '\016'    /* Shift Out; select alternate character set */
  546. X#define    SI    '\017'    /* Shift In; select ASCII again */
  547. X#define    DLE    '\020'    /* Data Link Escape */
  548. X#define    DC1    '\021'    /* Device Control 1 */
  549. X#define XON    '\021'    /* transmitter on, resume output */
  550. X#define    DC2    '\022'    /* Device Control 2 (auxiliary on) */
  551. X#define    DC3    '\023'    /* Device Control 3 */
  552. X#define    XOFF    '\023'    /* transmitter off, suspend output */
  553. X#define    DC4    '\024'    /* Device Control 4 (auxiliary off) */
  554. X#define    NAK    '\025'    /* Negative AcKnowledge (signal error) */
  555. X#define    SYN    '\026'    /* SYNchronous idle */
  556. X#define    ETB    '\027'    /* End of Transmission Block, logical end of medium */
  557. X#define    CAN    '\030'    /* CANcel */
  558. X#define    EM    '\031'    /* End of Medium */
  559. X#define    SUB    '\032'    /* SUBstitute */
  560. X#define    ESC    '\033'    /* ESCape */
  561. X#define    FS    '\034'    /* File Separator */
  562. X#define    GS    '\035'    /* Group Separator */
  563. X#define    RS    '\036'    /* Record Separator */
  564. X#define    US    '\037'    /* Unit Separator */
  565. X#define    SP    '\040'    /* SPace */
  566. X#define    DEL    '\177'    /* DELete, rubout */
  567. X
  568. SHAR_EOF
  569. sed 's/^X//' << 'SHAR_EOF' > bcmp.c
  570. X/*  File   : bcmp.c
  571. X    Author : Richard A. O'Keefe.
  572. X    Updated: 23 April 1984
  573. X    Defines: bcmp()
  574. X
  575. X    bcmp(s1, s2, len) returns 0 if the "len" bytes starting at "s1" are
  576. X    identical to the "len" bytes starting at "s2", non-zero if they are
  577. X    different.   The 4.2bsd manual page doesn't say what non-zero value
  578. X    is returned, though the BUGS note says that it takes its parameters
  579. X    backwards from strcmp.  This suggests that it is something like
  580. X    for (; --len >= 0; s1++, s2++)
  581. X        if (*s1 != *s2) return *s2-*s1;
  582. X    return 0;
  583. X    There, I've told you how to do it.  As the manual page doesn't come
  584. X    out and *say* that this is the result, I tried to figure out what a
  585. X    useful result might be.   (I'd forgotten than strncmp stops when it
  586. X    hits a NUL, which the above does not do.)  What I came up with was:
  587. X    the result is the number of bytes in the differing tails.  That is,
  588. X    after you've skipped the equal parts, how many characters are left?
  589. X    To put it another way, N-bcmp(s1,s2,N) is the number of equal bytes
  590. X    (the size of the common prefix).  After deciding on this definition
  591. X    I discovered that the CMPC3 instruction does exactly what I wanted.
  592. X    The code assumes that N is non-negative.
  593. X
  594. X    Note: the "b" routines are there to exploit certain VAX order codes,
  595. X    but the CMPC3 instruction will only test 65535 characters.   The asm
  596. X    code is presented for your interest and amusement.
  597. X*/
  598. X
  599. X#include "strings.h"
  600. X
  601. X#if    VaxAsm
  602. X
  603. Xint bcmp(s1, s2, len)
  604. X    char *s1, *s2;
  605. X    int len;
  606. X    {
  607. X    asm("cmpc3 12(ap),*4(ap),*8(ap)");
  608. X    }
  609. X
  610. X#else  ~VaxAsm
  611. X
  612. Xint bcmp(s1, s2, len)
  613. X    register char *s1, *s2;
  614. X    register int len;
  615. X    {
  616. X    while (--len >= 0 && *s1++ == *s2++) ;
  617. X    return len+1;
  618. X    }
  619. X
  620. X#endif    VaxAsm
  621. X
  622. SHAR_EOF
  623. sed 's/^X//' << 'SHAR_EOF' > bcopy.c
  624. X/*  File   : bcopy.c
  625. X    Author : Richard A. O'Keefe.
  626. X    Updated: 23 April 1984
  627. X    Defines: bcopy()
  628. X
  629. X    bcopy(src, dst, len) moves exactly "len" bytes from the source "src"
  630. X    to the destination "dst".  It does not check for NUL characters as
  631. X    strncpy() and strnmov() do.  Thus if your C compiler doesn't support
  632. X    structure assignment, you can simulate it with
  633. X    bcopy(&from, &to, sizeof from);
  634. X    BEWARE: the first two arguments are the other way around from almost
  635. X    everything else.   I'm sorry about that, but that's the way it is in
  636. X    the 4.2bsd manual, though they list it as a bug.  For a version with
  637. X    the arguments the right way around, use bmove().
  638. X    No value is returned.
  639. X
  640. X    Note: the "b" routines are there to exploit certain VAX order codes,
  641. X    but the MOVC3 instruction will only move 65535 characters.   The asm
  642. X    code is presented for your interest and amusement.
  643. X*/
  644. X
  645. X#include "strings.h"
  646. X
  647. X#if    VaxAsm
  648. X
  649. Xvoid bcopy(src, dst, len)
  650. X    char *src, *dst;
  651. X    int len;
  652. X    {
  653. X    asm("movc3 12(ap),*4(ap),*8(ap)");
  654. X    }
  655. X
  656. X#else  ~VaxAsm
  657. X
  658. Xvoid bcopy(src, dst, len)
  659. X    register char *src, *dst;
  660. X    register int len;
  661. X    {
  662. X    while (--len >= 0) *dst++ = *src++;
  663. X    }
  664. X
  665. X#endif    VaxAsm
  666. X
  667. SHAR_EOF
  668. sed 's/^X//' << 'SHAR_EOF' > bfill.c
  669. X/*  File   : bfill.c
  670. X    Author : Richard A. O'Keefe.
  671. X    Updated: 23 April 1984
  672. X    Defines: bfill()
  673. X
  674. X    bfill(dst, len, fill) moves "len" fill characters to "dst".
  675. X    Thus to set a buffer to 80 spaces, do bfill(buff, 80, ' ').
  676. X
  677. X    Note: the "b" routines are there to exploit certain VAX order codes,
  678. X    but the MOVC5 instruction will only move 65535 characters.   The asm
  679. X    code is presented for your interest and amusement.
  680. X*/
  681. X
  682. X#include "strings.h"
  683. X
  684. X#if    VaxAsm
  685. X
  686. Xvoid bfill(dst, len, fill)
  687. X    char *dst;
  688. X    int len;
  689. X    int fill;    /* actually char */
  690. X    {
  691. X    asm("movc5 $0,*4(ap),12(ap),8(ap),*4(ap)");
  692. X    }
  693. X
  694. X#else  ~VaxAsm
  695. X
  696. Xvoid bfill(dst, len, fill)
  697. X    register char *dst;
  698. X    register int len;
  699. X    register int fill;    /* char */
  700. X    {
  701. X    while (--len >= 0) *dst++ = fill;
  702. X
  703. X    }
  704. X
  705. X#endif    VaxAsm
  706. X
  707. SHAR_EOF
  708. sed 's/^X//' << 'SHAR_EOF' > bmove.c
  709. X/*  File   : bmove.c
  710. X    Author : Richard A. O'Keefe.
  711. X    Updated: 23 April 1984
  712. X    Defines: bmove()
  713. X
  714. X    bmove(dst, src, len) moves exactly "len" bytes from the source "src"
  715. X    to the destination "dst".  It does not check for NUL characters as
  716. X    strncpy() and strnmov() do.  Thus if your C compiler doesn't support
  717. X    structure assignment, you can simulate it with
  718. X    bmove(&to, &from, sizeof from);
  719. X    The standard 4.2bsd routine for this purpose is bcopy.  But as bcopy
  720. X    has its first two arguments the other way around you may find this a
  721. X    bit easier to get right.
  722. X    No value is returned.
  723. X
  724. X    Note: the "b" routines are there to exploit certain VAX order codes,
  725. X    but the MOVC3 instruction will only move 65535 characters.   The asm
  726. X    code is presented for your interest and amusement.
  727. X*/
  728. X
  729. X#include "strings.h"
  730. X
  731. X#if    VaxAsm
  732. X
  733. Xvoid bmove(dst, src, len)
  734. X    char *dst, *src;
  735. X    int len;
  736. X    {
  737. X    asm("movc3 12(ap),*8(ap),*4(ap)");
  738. X    }
  739. X
  740. X#else  ~VaxAsm
  741. X
  742. Xvoid bmove(dst, src, len)
  743. X    register char *dst, *src;
  744. X    register int len;
  745. X    {
  746. X    while (--len >= 0) *dst++ = *src++;
  747. X    }
  748. X
  749. X#endif    VaxAsm
  750. X
  751. SHAR_EOF
  752. sed 's/^X//' << 'SHAR_EOF' > bzero.c
  753. X/*  File   : bzero.c
  754. X    Author : Richard A. O'Keefe.
  755. X    Updated: 23 April 1984
  756. X    Defines: bzero()
  757. X
  758. X    bzero(dst, len) moves "len" 0 bytes to "dst".
  759. X    Thus to clear a disc buffer to 0s do bzero(buffer, BUFSIZ).
  760. X
  761. X    Note: the "b" routines are there to exploit certain VAX order codes,
  762. X    but the MOVC5 instruction will only move 65535 characters.   The asm
  763. X    code is presented for your interest and amusement.
  764. X*/
  765. X
  766. X#include "strings.h"
  767. X
  768. X#if    VaxAsm
  769. X
  770. Xvoid bzero(dst, len)
  771. X    char *dst;
  772. X    int len;
  773. X    {
  774. X    asm("movc5 $0,*4(ap),$0,8(ap),*4(ap)");
  775. X    }
  776. X
  777. X#else  ~VaxAsm
  778. X
  779. Xvoid bzero(dst, len)
  780. X    register char *dst;
  781. X    register int len;
  782. X    {
  783. X    while (--len >= 0) *dst++ = 0;
  784. X    }
  785. X
  786. X#endif    VaxAsm
  787. X
  788. SHAR_EOF
  789. sed 's/^X//' << 'SHAR_EOF' > ctypes.dem
  790. XEOF .   .   .   .   .   .   .   .   .   #   .   .
  791. X
  792. Xch  DD? OD? XD? AN? AF? LC? UC? PT? PR? CT? SP? EL?
  793. X^@  .   .   .   .   .   .   .   .   .   #   .   .
  794. X^A  .   .   .   .   .   .   .   .   .   #   .   .
  795. X^B  .   .   .   .   .   .   .   .   .   #   .   .
  796. X^C  .   .   .   .   .   .   .   .   .   #   .   .
  797. X^D  .   .   .   .   .   .   .   .   .   #   .   .
  798. X^E  .   .   .   .   .   .   .   .   .   #   .   .
  799. X^F  .   .   .   .   .   .   .   .   .   #   .   .
  800. X^G  .   .   .   .   .   .   .   .   .   #   .   .
  801. X^H  .   .   .   .   .   .   .   .   .   #   .   .
  802. X^I  .   .   .   .   .   .   .   .   .   #   #   .
  803. X^J  .   .   .   .   .   .   .   .   .   #   #   #
  804. X^K  .   .   .   .   .   .   .   .   .   #   #   #
  805. X^L  .   .   .   .   .   .   .   .   .   #   #   #
  806. X^M  .   .   .   .   .   .   .   .   .   #   #   #
  807. X^N  .   .   .   .   .   .   .   .   .   #   .   .
  808. X^O  .   .   .   .   .   .   .   .   .   #   .   .
  809. X
  810. Xch  DD? OD? XD? AN? AF? LC? UC? PT? PR? CT? SP? EL?
  811. X^P  .   .   .   .   .   .   .   .   .   #   .   .
  812. X^Q  .   .   .   .   .   .   .   .   .   #   .   .
  813. X^R  .   .   .   .   .   .   .   .   .   #   .   .
  814. X^S  .   .   .   .   .   .   .   .   .   #   .   .
  815. X^T  .   .   .   .   .   .   .   .   .   #   .   .
  816. X^U  .   .   .   .   .   .   .   .   .   #   .   .
  817. X^V  .   .   .   .   .   .   .   .   .   #   .   .
  818. X^W  .   .   .   .   .   .   .   .   .   #   .   .
  819. X^X  .   .   .   .   .   .   .   .   .   #   .   .
  820. X^Y  .   .   .   .   .   .   .   .   .   #   .   .
  821. X^Z  .   .   .   .   .   .   .   .   .   #   .   .
  822. X^[  .   .   .   .   .   .   .   .   .   #   .   .
  823. X^\  .   .   .   .   .   .   .   .   .   #   .   .
  824. X^]  .   .   .   .   .   .   .   .   .   #   .   .
  825. X^^  .   .   .   .   .   .   .   .   .   #   .   .
  826. X^_  .   .   .   .   .   .   .   .   .   #   .   .
  827. X
  828. Xch  DD? OD? XD? AN? AF? LC? UC? PT? PR? CT? SP? EL?
  829. X    .   .   .   .   .   .   .   .   #   .   #   .
  830. X!   .   .   .   .   .   .   .   #   #   .   .   .
  831. X"   .   .   .   .   .   .   .   #   #   .   .   .
  832. X#   .   .   .   .   .   .   .   #   #   .   .   .
  833. X$   .   .   .   .   .   .   .   #   #   .   .   .
  834. X%   .   .   .   .   .   .   .   #   #   .   .   .
  835. X&   .   .   .   .   .   .   .   #   #   .   .   .
  836. X'   .   .   .   .   .   .   .   #   #   .   .   .
  837. X(   .   .   .   .   .   .   .   #   #   .   .   .
  838. X)   .   .   .   .   .   .   .   #   #   .   .   .
  839. X*   .   .   .   .   .   .   .   #   #   .   .   .
  840. X+   .   .   .   .   .   .   .   #   #   .   .   .
  841. X,   .   .   .   .   .   .   .   #   #   .   .   .
  842. X-   .   .   .   .   .   .   .   #   #   .   .   .
  843. X.   .   .   .   .   .   .   .   #   #   .   .   .
  844. X/   .   .   .   .   .   .   .   #   #   .   .   .
  845. X
  846. Xch  DD? OD? XD? AN? AF? LC? UC? PT? PR? CT? SP? EL?
  847. X0   #   #   #   #   .   .   .   .   #   .   .   .
  848. X1   #   #   #   #   .   .   .   .   #   .   .   .
  849. X2   #   #   #   #   .   .   .   .   #   .   .   .
  850. X3   #   #   #   #   .   .   .   .   #   .   .   .
  851. X4   #   #   #   #   .   .   .   .   #   .   .   .
  852. X5   #   #   #   #   .   .   .   .   #   .   .   .
  853. X6   #   #   #   #   .   .   .   .   #   .   .   .
  854. X7   #   #   #   #   .   .   .   .   #   .   .   .
  855. X8   #   .   #   #   .   .   .   .   #   .   .   .
  856. X9   #   .   #   #   .   .   .   .   #   .   .   .
  857. X:   .   .   .   .   .   .   .   #   #   .   .   .
  858. X;   .   .   .   .   .   .   .   #   #   .   .   .
  859. X<   .   .   .   .   .   .   .   #   #   .   .   .
  860. X=   .   .   .   .   .   .   .   #   #   .   .   .
  861. X>   .   .   .   .   .   .   .   #   #   .   .   .
  862. X?   .   .   .   .   .   .   .   #   #   .   .   .
  863. X
  864. Xch  DD? OD? XD? AN? AF? LC? UC? PT? PR? CT? SP? EL?
  865. X@   .   .   .   .   .   .   .   #   #   .   .   .
  866. XA   .   .   #   #   #   .   #   .   #   .   .   .
  867. XB   .   .   #   #   #   .   #   .   #   .   .   .
  868. XC   .   .   #   #   #   .   #   .   #   .   .   .
  869. XD   .   .   #   #   #   .   #   .   #   .   .   .
  870. XE   .   .   #   #   #   .   #   .   #   .   .   .
  871. XF   .   .   #   #   #   .   #   .   #   .   .   .
  872. XG   .   .   .   #   #   .   #   .   #   .   .   .
  873. XH   .   .   .   #   #   .   #   .   #   .   .   .
  874. XI   .   .   .   #   #   .   #   .   #   .   .   .
  875. XJ   .   .   .   #   #   .   #   .   #   .   .   .
  876. XK   .   .   .   #   #   .   #   .   #   .   .   .
  877. XL   .   .   .   #   #   .   #   .   #   .   .   .
  878. XM   .   .   .   #   #   .   #   .   #   .   .   .
  879. XN   .   .   .   #   #   .   #   .   #   .   .   .
  880. XO   .   .   .   #   #   .   #   .   #   .   .   .
  881. X
  882. Xch  DD? OD? XD? AN? AF? LC? UC? PT? PR? CT? SP? EL?
  883. XP   .   .   .   #   #   .   #   .   #   .   .   .
  884. XQ   .   .   .   #   #   .   #   .   #   .   .   .
  885. XR   .   .   .   #   #   .   #   .   #   .   .   .
  886. XS   .   .   .   #   #   .   #   .   #   .   .   .
  887. XT   .   .   .   #   #   .   #   .   #   .   .   .
  888. XU   .   .   .   #   #   .   #   .   #   .   .   .
  889. XV   .   .   .   #   #   .   #   .   #   .   .   .
  890. XW   .   .   .   #   #   .   #   .   #   .   .   .
  891. XX   .   .   .   #   #   .   #   .   #   .   .   .
  892. XY   .   .   .   #   #   .   #   .   #   .   .   .
  893. XZ   .   .   .   #   #   .   #   .   #   .   .   .
  894. X[   .   .   .   .   .   .   .   #   #   .   .   .
  895. X\   .   .   .   .   .   .   .   #   #   .   .   .
  896. X]   .   .   .   .   .   .   .   #   #   .   .   .
  897. X^   .   .   .   .   .   .   .   #   #   .   .   .
  898. X_   .   .   .   .   .   .   .   #   #   .   .   .
  899. X
  900. Xch  DD? OD? XD? AN? AF? LC? UC? PT? PR? CT? SP? EL?
  901. X`   .   .   .   .   .   .   .   #   #   .   .   .
  902. Xa   .   .   #   #   #   #   .   .   #   .   .   .
  903. Xb   .   .   #   #   #   #   .   .   #   .   .   .
  904. Xc   .   .   #   #   #   #   .   .   #   .   .   .
  905. Xd   .   .   #   #   #   #   .   .   #   .   .   .
  906. Xe   .   .   #   #   #   #   .   .   #   .   .   .
  907. Xf   .   .   #   #   #   #   .   .   #   .   .   .
  908. Xg   .   .   .   #   #   #   .   .   #   .   .   .
  909. Xh   .   .   .   #   #   #   .   .   #   .   .   .
  910. Xi   .   .   .   #   #   #   .   .   #   .   .   .
  911. Xj   .   .   .   #   #   #   .   .   #   .   .   .
  912. Xk   .   .   .   #   #   #   .   .   #   .   .   .
  913. Xl   .   .   .   #   #   #   .   .   #   .   .   .
  914. Xm   .   .   .   #   #   #   .   .   #   .   .   .
  915. Xn   .   .   .   #   #   #   .   .   #   .   .   .
  916. Xo   .   .   .   #   #   #   .   .   #   .   .   .
  917. X
  918. Xch  DD? OD? XD? AN? AF? LC? UC? PT? PR? CT? SP? EL?
  919. Xp   .   .   .   #   #   #   .   .   #   .   .   .
  920. Xq   .   .   .   #   #   #   .   .   #   .   .   .
  921. Xr   .   .   .   #   #   #   .   .   #   .   .   .
  922. Xs   .   .   .   #   #   #   .   .   #   .   .   .
  923. Xt   .   .   .   #   #   #   .   .   #   .   .   .
  924. Xu   .   .   .   #   #   #   .   .   #   .   .   .
  925. Xv   .   .   .   #   #   #   .   .   #   .   .   .
  926. Xw   .   .   .   #   #   #   .   .   #   .   .   .
  927. Xx   .   .   .   #   #   #   .   .   #   .   .   .
  928. Xy   .   .   .   #   #   #   .   .   #   .   .   .
  929. Xz   .   .   .   #   #   #   .   .   #   .   .   .
  930. X{   .   .   .   .   .   .   .   #   #   .   .   .
  931. X|   .   .   .   .   .   .   .   #   #   .   .   .
  932. X}   .   .   .   .   .   .   .   #   #   .   .   .
  933. X~   .   .   .   .   .   .   .   #   #   .   .   .
  934. XDEL .   .   .   .   .   .   .   #   .   #   .   .
  935. SHAR_EOF
  936. sed 's/^X//' << 'SHAR_EOF' > ctypes.h
  937. X/*  File   : ctypes.h
  938. X    Author : Richard A. O'Keefe.
  939. X    Updated: 26 April 1984
  940. X    Purpose: Reimplement the UNIX ctype(3) library.
  941. X
  942. X    isaneol(c) means that c is a line terminating character.
  943. X    isalnum, ispunct, isspace, and isaneol are defined on the
  944. X    range -1..127, i.e. on ASCII U {EOF}, while all the other
  945. X    macros are defined for any integer.
  946. X
  947. X    isodigit(c) checks for Octal digits.
  948. X    isxdigit(c) checkx for heXadecimal digits.
  949. X*/
  950. X
  951. X#define isdigit(c)    ((unsigned)((c)-'0') < 10)
  952. X#define islower(c)    ((unsigned)((c)-'a') < 26)
  953. X#define isupper(c)    ((unsigned)((c)-'A') < 26)
  954. X#define isprint(c)    ((unsigned)((c)-' ') < 95)
  955. X#define iscntrl(c)    ((unsigned)((c)-' ') >= 95)
  956. X#define isascii(c)    ((unsigned)(c) < 128)
  957. X#define isalpha(c)    ((unsigned)(((c)|32)-'a') < 26)
  958. X
  959. Xextern    char    _c2type[];
  960. X
  961. X#define isalnum(c)    (_c2type[(c)+1] < 36)
  962. X#define ispunct(c)    (_c2type[(c)+1] == 36)
  963. X#define isspace(c)    (_c2type[(c)+1] > 37)
  964. X#define isaneol(c)    (_c2type[(c)+1] > 38)
  965. X
  966. X#define    isxdigit(c)    (_c2type[(c)+1] < 16)
  967. X#define isodigit(c)    ((unsigned)((c)-'0') < 8)
  968. X
  969. X/*  The following "conversion" macros have been in some versions of UNIX
  970. X    but are not in all.  tocntrl is new.  The original motivation for ^?
  971. X    being a name for DEL was that (x)^64 mapped A..Z to ^A..^Z and also
  972. X    ? to DEL.  The trouble is that this trick doesn't work for lower case
  973. X    letters.  The version given here is not mine.  I wish it was.  It has
  974. X    the nice property that DEL is mapped to itself (so does EOF).
  975. X    tolower(c) and toupper(c) are only defined when isalpha(c).
  976. X*/
  977. X#define    tolower(c)    ((c)|32)
  978. X#define toupper(c)    ((c)&~32)
  979. X#define tocntrl(c)    (((((c)+1)&~96)-1)&127)
  980. X#define    toascii(c)    ((c)&127)
  981. X
  982. SHAR_EOF
  983. sed 's/^X//' << 'SHAR_EOF' > ffs.c
  984. X/*  File   : ffs.c
  985. X    Author : Richard A. O'Keefe.
  986. X    Updated: 20 April 1984
  987. X    Defines: ffs(), ffc()
  988. X
  989. X    ffs(i) returns the index of the least significant 1 bit in i,
  990. X       where 1 means the least significant bit and 32 means the
  991. X       most significant bit, or returns -1 if i is 0.
  992. X
  993. X    ffc(i) returns the index of the least significant 0 bit in i,
  994. X       where 1 means the least significant bit and 32 means the
  995. X       most significant bit, or returns -1 if i is ~0.
  996. X
  997. X    These functions mimic the VAX FFS and FFC instructions, except that
  998. X    the latter return much more sensible values.  This file only exists
  999. X    to make it easier to move 4.2bsd programs to System III (which is
  1000. X    rather like moving up from a Rolls Royce to a model T Ford), and so
  1001. X    I haven't bother with assembly code versions.
  1002. X*/
  1003. X
  1004. X#include "strings.h"
  1005. X
  1006. Xint ffs(i)
  1007. X    register int i;
  1008. X    {
  1009. X    register int N;
  1010. X
  1011. X    for (N = 8*sizeof(int); --N >= 0; i >>= 1)
  1012. X        if (i&1) return 8*sizeof(int)-N;
  1013. X    return -1;
  1014. X    }
  1015. X
  1016. Xint ffc(i)
  1017. X    register int i;
  1018. X    {
  1019. X    register int N;
  1020. X
  1021. X    for (N = 8*sizeof(int); --N >= 0; i >>= 1)
  1022. X        if (!(i&1)) return 8*sizeof(int)-N;
  1023. X    return -1;
  1024. X    }
  1025. X
  1026. X
  1027. SHAR_EOF
  1028. sed 's/^X//' << 'SHAR_EOF' > getopt.3
  1029. X.TH GETOPT 3 local
  1030. X.DA 25 March 1982
  1031. X.SH NAME
  1032. Xgetopt \- get option letter from argv
  1033. X.SH SYNOPSIS
  1034. X.ft B
  1035. Xint getopt(argc, argv, optstring)
  1036. X.br
  1037. Xint argc;
  1038. X.br
  1039. Xchar **argv;
  1040. X.br
  1041. Xchar *optstring;
  1042. X.sp
  1043. Xextern char *optarg;
  1044. X.br
  1045. Xextern int optind;
  1046. X.ft
  1047. X.SH DESCRIPTION
  1048. X.I Getopt
  1049. Xreturns the next option letter in
  1050. X.I argv
  1051. Xthat matches a letter in
  1052. X.IR optstring .
  1053. X.I Optstring
  1054. Xis a string of recognized option letters;
  1055. Xif a letter is followed by a colon, the option is expected to have
  1056. Xan argument that may or may not be separated from it by white space.
  1057. X.I Optarg
  1058. Xis set to point to the start of the option argument on return from
  1059. X.IR getopt .
  1060. X.PP
  1061. X.I Getopt
  1062. Xplaces in
  1063. X.I optind
  1064. Xthe
  1065. X.I argv
  1066. Xindex of the next argument to be processed.
  1067. XBecause
  1068. X.I optind
  1069. Xis external, it is normally initialized to zero automatically
  1070. Xbefore the first call to
  1071. X.IR getopt .
  1072. X.PP
  1073. XWhen all options have been processed (i.e., up to the first
  1074. Xnon-option argument),
  1075. X.I getopt
  1076. Xreturns
  1077. X.BR EOF .
  1078. XThe special option
  1079. X.B \-\-
  1080. Xmay be used to delimit the end of the options;
  1081. X.B EOF
  1082. Xwill be returned, and
  1083. X.B \-\-
  1084. Xwill be skipped.
  1085. X.SH SEE ALSO
  1086. Xgetopt(1)
  1087. X.SH DIAGNOSTICS
  1088. X.I Getopt
  1089. Xprints an error message on
  1090. X.I stderr
  1091. Xand returns a question mark
  1092. X.RB ( ? )
  1093. Xwhen it encounters an option letter not included in
  1094. X.IR optstring .
  1095. X.SH EXAMPLE
  1096. XThe following code fragment shows how one might process the arguments
  1097. Xfor a command that can take the mutually exclusive options
  1098. X.B a
  1099. Xand
  1100. X.BR b ,
  1101. Xand the options
  1102. X.B f
  1103. Xand
  1104. X.BR o ,
  1105. Xboth of which require arguments:
  1106. X.PP
  1107. X.RS
  1108. X.nf
  1109. Xmain(argc, argv)
  1110. X    int argc;
  1111. X    char **argv;
  1112. X    {
  1113. X        int c;
  1114. X        extern int optind;
  1115. X        extern char *optarg;
  1116. X        \&.
  1117. X        \&.
  1118. X        \&.
  1119. X        while ((c = getopt(argc, argv, "abf:o:")) != EOF) {
  1120. X            switch (c) {
  1121. X                case 'a':
  1122. X                    if (bflg) errflg++; else aflg++;
  1123. X                    break;
  1124. X                case 'b':
  1125. X                    if (aflg) errflg++; else bflg++;
  1126. X                    break;
  1127. X                case 'f':
  1128. X                    ifile = optarg;
  1129. X                    break;
  1130. X                case 'o':
  1131. X                    ofile = optarg;
  1132. X                    break;
  1133. X                case '?':
  1134. X                default:
  1135. X                    errflg++;
  1136. X                    break;
  1137. X            }
  1138. X        }
  1139. X        if (errflg) {
  1140. X            fprintf(stderr, "Usage: ...");
  1141. X            exit(2);
  1142. X        }
  1143. X        for (; optind < argc; optind++) {
  1144. X            \&.
  1145. X            \&.
  1146. X            \&.
  1147. X        }
  1148. X        \&.
  1149. X        \&.
  1150. X        \&.
  1151. X    }
  1152. X.RE
  1153. X.PP
  1154. XA template similar to this can be found in
  1155. X.IR /usr/pub/template.c .
  1156. X.SH HISTORY
  1157. XWritten by Henry Spencer, working from a Bell Labs manual page.
  1158. XBehavior believed identical to the Bell version.
  1159. X.SH BUGS
  1160. XIt is not obvious how
  1161. X`\-'
  1162. Xstanding alone should be treated; this version treats it as
  1163. Xa non-option argument, which is not always right.
  1164. X.PP
  1165. XOption arguments are allowed to begin with `\-';
  1166. Xthis is reasonable but reduces the amount of error checking possible.
  1167. X.PP
  1168. X.I Getopt
  1169. Xis quite flexible but the obvious price must be paid: there is much
  1170. Xit could do that it doesn't, like
  1171. Xchecking mutually exclusive options, checking type of
  1172. Xoption arguments, etc.
  1173. SHAR_EOF
  1174. sed 's/^X//' << 'SHAR_EOF' > getopt.c
  1175. X/*  File   : getopt.c
  1176. X    Author : Henry Spencer, University of Toronto
  1177. X    Updated: 28 April 1984
  1178. X    Purpose: get option letter from argv.
  1179. X*/
  1180. X
  1181. X#include <stdio.h>
  1182. X#include "strings.h"
  1183. X
  1184. Xchar    *optarg;    /* Global argument pointer. */
  1185. Xint    optind = 0;    /* Global argv index. */
  1186. X
  1187. Xint getopt(argc, argv, optstring)
  1188. X    int argc;
  1189. X    char *argv[];
  1190. X    char *optstring;
  1191. X    {
  1192. X    register int c;
  1193. X    register char *place;
  1194. X    static char *scan = NullS;    /* Private scan pointer. */
  1195. X
  1196. X    optarg = NullS;
  1197. X
  1198. X    if (scan == NullS || *scan == '\0') {
  1199. X        if (optind == 0) optind++;
  1200. X        if (optind >= argc) return EOF;
  1201. X        place = argv[optind];
  1202. X        if (place[0] != '-' || place[1] == '\0') return EOF;
  1203. X        optind++;
  1204. X        if (place[1] == '-' && place[2] == '\0') return EOF;
  1205. X        scan = place+1;
  1206. X    }
  1207. X
  1208. X    c = *scan++;
  1209. X    place = index(optstring, c);
  1210. X    if (place == NullS || c == ':') {
  1211. X        fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
  1212. X        return '?';
  1213. X    }
  1214. X    if (*++place == ':') {
  1215. X        if (*scan != '\0') {
  1216. X        optarg = scan, scan = NullS;
  1217. X        } else {
  1218. X        optarg = argv[optind], optind++;
  1219. X        }
  1220. X    }
  1221. X    return c;
  1222. X    }
  1223. X
  1224. SHAR_EOF
  1225. sed 's/^X//' << 'SHAR_EOF' > int2str.c
  1226. X/*  File   : int2str.c
  1227. X    Author : Richard A. O'Keefe
  1228. X    Updated: 30 April 1984
  1229. X    Defines: int2str(), itoa(), ltoa()
  1230. X
  1231. X    int2str(dst, radix, val)
  1232. X    converts the (long) integer "val" to character form and moves it to
  1233. X    the destination string "dst" followed by a terminating NUL.  The
  1234. X    result is normally a pointer to this NUL character, but if the radix
  1235. X    is dud the result will be NullS and nothing will be changed.
  1236. X
  1237. X    If radix is -2..-36, val is taken to be SIGNED.
  1238. X    If radix is  2.. 36, val is taken to be UNSIGNED.
  1239. X    That is, val is signed if and only if radix is.  You will normally
  1240. X    use radix -10 only through itoa and ltoa, for radix 2, 8, or 16
  1241. X    unsigned is what you generally want.
  1242. X
  1243. X    _dig_vec is public just in case someone has a use for it.
  1244. X    The definitions of itoa and ltoa are actually macros in strings.h,
  1245. X    but this is where the code is.
  1246. X*/
  1247. X
  1248. X#include "strings.h"
  1249. X
  1250. Xchar _dig_vec[] =
  1251. X    "0123456789abcdefghijklmnopqrstuvwxyz";
  1252. X
  1253. X
  1254. Xchar *int2str(dst, radix, val)
  1255. X    register char *dst;
  1256. X    register int radix;
  1257. X    register long val;
  1258. X    {
  1259. X    char buffer[33];
  1260. X    register char *p;
  1261. X
  1262. X    if (radix < 0) {
  1263. X        if (radix < -36 || radix > -2) return NullS;
  1264. X        if (val < 0) {
  1265. X        *dst++ = '-';
  1266. X        val = -val;
  1267. X        }
  1268. X        radix = -radix;
  1269. X    } else {
  1270. X        if (radix > 36 || radix < 2) return NullS;
  1271. X    }
  1272. X    /*  The slightly contorted code which follows is due to the
  1273. X        fact that few machines directly support unsigned long / and %.
  1274. X        Certainly the VAX C compiler generates a subroutine call.  In
  1275. X        the interests of efficiency (hollow laugh) I let this happen
  1276. X        for the first digit only; after that "val" will be in range so
  1277. X        that signed integer division will do.  Sorry 'bout that.
  1278. X        CHECK THE CODE PRODUCED BY YOUR C COMPILER.  The first % and /
  1279. X        should be unsigned, the second % and / signed, but C compilers
  1280. X        tend to be extraordinarily sensitive to minor details of style.
  1281. X        This works on a VAX, that's all I claim for it.
  1282. X    */
  1283. X    p = &buffer[32];
  1284. X    *p = '\0';
  1285. X    *--p = _dig_vec[(unsigned long)val%(unsigned long)radix];
  1286. X    val = (unsigned long)val/(unsigned long)radix;
  1287. X    while (val != 0) *--p = _dig_vec[val%radix], val /= radix;
  1288. X    while (*dst++ = *p++) ;
  1289. X    return dst-1;
  1290. X    }
  1291. X
  1292. SHAR_EOF
  1293. sed 's/^X//' << 'SHAR_EOF' > memccpy.c
  1294. X/*  File   : memccpy.c
  1295. X    Author : Richard A. O'Keefe.
  1296. X    Updated: 25 May 1984
  1297. X    Defines: memccpy()
  1298. X
  1299. X    memccpy(dst, src, chr, len)
  1300. X    copies bytes from src to dst until either len bytes have been moved
  1301. X    or a byte equal to chr has been moved.  In the former case it gives
  1302. X    NullS as the value, in the latter a pointer to just after the place
  1303. X    where "chr" was moved to in dst.  Note that copying stops after the
  1304. X    first instance of "chr", and that remaining characters in "dst" are
  1305. X    not changed in any way, no NUL being inserted or anything.
  1306. X
  1307. X    See the "Character Comparison" section in the READ-ME file.
  1308. X*/
  1309. X
  1310. X#include "strings.h"
  1311. X
  1312. Xchar *memccpy(dst, src, chr, len)
  1313. X    register char *dst, *src;
  1314. X    register int chr;        /* should be char */
  1315. X    register int len;
  1316. X    {
  1317. X    while (--len >= 0)
  1318. X        if ((*dst++ = *src++) == chr) return dst;
  1319. X    return NullS;
  1320. X    }
  1321. X
  1322. SHAR_EOF
  1323. sed 's/^X//' << 'SHAR_EOF' > memchr.c
  1324. X/*  File   : memchr.c
  1325. X    Author : Richard A. O'Keefe.
  1326. X    Updated: 25 May 1984
  1327. X    Defines: memchr()
  1328. X
  1329. X    memchr(src, chr, len)
  1330. X    searches the memory area pointed to by src extending for len bytes,
  1331. X    looking for an occurrence of the byte value chr.  It returns NullS
  1332. X    if there is no such occurrence.  Otherwise it returns a pointer to
  1333. X    the FIRST such occurrence.
  1334. X
  1335. X    See the "Character Comparison" section in the READ-ME file.
  1336. X*/
  1337. X
  1338. X#include "strings.h"
  1339. X
  1340. X#if    VaxAsm
  1341. X
  1342. Xchar *memchr(src, chr, len)
  1343. X    char *src;
  1344. X    char chr;
  1345. X    int len;
  1346. X    {
  1347. X    asm("locc 8(ap),12(ap),*4(ap)");
  1348. X    asm("bneq L1");
  1349. X    asm("movl r1,r0");
  1350. X    asm("L1: ret");
  1351. X    }
  1352. X
  1353. X#else  ~VaxAsm
  1354. X
  1355. Xchar *memchr(src, chr, len)
  1356. X    register char *src;
  1357. X    register int chr;        /* should be char */
  1358. X    register int len;
  1359. X    {
  1360. X    while (--len >= 0)
  1361. X        if (*src++ == chr) return src-1;
  1362. X    return NullS;
  1363. X    }
  1364. X
  1365. X#endif    VaxAsm
  1366. X
  1367. SHAR_EOF
  1368. sed 's/^X//' << 'SHAR_EOF' > memcmp.c
  1369. X/*  File   : memcmp.c
  1370. X    Author : Richard A. O'Keefe.
  1371. X    Updated: 25 May 1984
  1372. X    Defines: memcmp()
  1373. X
  1374. X    memcmp(lhs, rhs, len)
  1375. X    compares the two memory areas lhs[0..len-1]  ??  rhs[0..len-1].   It
  1376. X    returns  an integer less than, equal to, or greater than 0 according
  1377. X    as lhs[-] is lexicographically less than, equal to, or greater  than
  1378. X    rhs[-].  Note  that this is not at all the same as bcmp, which tells
  1379. X    you *where* the difference is but not what.
  1380. X
  1381. X    Note:  suppose we have int x, y;  then memcmp(&x, &y, sizeof x) need
  1382. X    not bear any relation to x-y.  This is because byte order is machine
  1383. X    dependent, and also, some machines have integer representations that
  1384. X    are shorter than a machine word and two equal  integers  might  have
  1385. X    different  values  in the spare bits.  On a ones complement machine,
  1386. X    -0 == 0, but the bit patterns are different.
  1387. X
  1388. X    This could have a Vax assembly code version, but as the return value
  1389. X    is not the value left behind by  the  cmpc3  instruction  I  haven't
  1390. X    bothered.
  1391. X*/
  1392. X
  1393. Xint memcmp(lhs, rhs, len)
  1394. X    register char *lhs, *rhs;
  1395. X    register int len;
  1396. X    {
  1397. X    while (--len >= 0)
  1398. X        if (*lhs++ != *rhs++) return lhs[-1]-rhs[-1];
  1399. X    return 0;
  1400. X    }
  1401. X
  1402. SHAR_EOF
  1403. sed 's/^X//' << 'SHAR_EOF' > memcpy.c
  1404. X/*  File   : memcpy.c
  1405. X    Author : Richard A. O'Keefe.
  1406. X    Updated: 25 May 1984
  1407. X    Defines: memcpy()
  1408. X
  1409. X    memcpy(dst, src, len)
  1410. X    moves len bytes from src to dst.  The result is dst.  This is not
  1411. X    the same as strncpy or strnmov, while move a maximum of len bytes
  1412. X    and stop early if they hit a NUL character.  This moves len bytes
  1413. X    exactly, no more, no less.  See also bcopy() and bmove() which do
  1414. X    not return a value but otherwise do the same job.
  1415. X
  1416. X    Note: the VAX assembly code version can only handle 0 <= len < 2^16.
  1417. X    It is presented for your interest and amusement.
  1418. X*/
  1419. X
  1420. X#include "strings.h"
  1421. X
  1422. X#if    VaxAsm
  1423. X
  1424. Xchar *memcpy(dst, src, len)
  1425. X    char *dst, *src;
  1426. X    int len;
  1427. X    {
  1428. X    asm("movc3 12(ap),*8(ap),*4(ap)");
  1429. X    return dst;
  1430. X    }
  1431. X
  1432. X#else  ~VaxAsm
  1433. X
  1434. Xchar *memcpy(dst, src, len)
  1435. X    char *dst;
  1436. X    register char *src;
  1437. X    register int len;
  1438. X    {
  1439. X    register char *d;
  1440. X
  1441. X    for (d = dst; --len >= 0; *d++ = *src++) ;
  1442. X    return dst;
  1443. X    }
  1444. X
  1445. X#endif    VaxAsm
  1446. X
  1447. SHAR_EOF
  1448. sed 's/^X//' << 'SHAR_EOF' > memmov.c
  1449. X/*  File   : memmov.c
  1450. X    Author : Richard A. O'Keefe.
  1451. X    Updated: 25 May 1984
  1452. X    Defines: memmov()
  1453. X
  1454. X    memmov(dst, src, len)
  1455. X    moves len bytes from src to dst.  The result is dst+len.
  1456. X    This is to memcpy as str[n]mov is to str[n]cpy, that is, it moves
  1457. X    exactly the same bytes but returns a pointer to just after the
  1458. X    the last changed byte.  You can concatenate blocks pa for la,
  1459. X    pb for lb, pc for lc into area pd by doing
  1460. X    memmov(memmov(memmov(pd, pa, la), pb, lb), pc, lc);
  1461. X    Unlike strnmov, memmov does not stop when it hits a NUL byte.
  1462. X
  1463. X    Note: the VAX assembly code version can only handle 0 <= len < 2^16.
  1464. X    It is presented for your interest and amusement.
  1465. X*/
  1466. X
  1467. X#include "strings.h"
  1468. X
  1469. X#if    VaxAsm
  1470. X
  1471. Xchar *memmov(dst, src, len)
  1472. X    char *dst, *src;
  1473. X    int len;
  1474. X    {
  1475. X    asm("movc3 12(ap),*8(ap),*4(ap)");
  1476. X    return dst+len;
  1477. X    }
  1478. X
  1479. X#else  ~VaxAsm
  1480. X
  1481. Xchar *memmov(dst, src, len)
  1482. X    register char *dst, *src;
  1483. X    register int len;
  1484. X    {
  1485. X    while (--len >= 0) *dst++ = *src++;
  1486. X    return dst;
  1487. X    }
  1488. X
  1489. X#endif    VaxAsm
  1490. X
  1491. SHAR_EOF
  1492. sed 's/^X//' << 'SHAR_EOF' > memory.h
  1493. X/*  File   : memory.h
  1494. X    Author : Richard A. O'Keefe.
  1495. X    Updated: 1 June 1984
  1496. X    Purpose: Header file for the System V "memory(3C)" package.
  1497. X
  1498. X    All the functions in this package are the original work  of  Richard
  1499. X    A. O'Keefe.   Any resemblance between them and any functions in AT&T
  1500. X    or other licensed software is due entirely to my use of the System V
  1501. X    memory(3C) manual page as a specification.  See the READ-ME to  find
  1502. X    the conditions under which this material may be used and copied.
  1503. X
  1504. X    The System V manual says that the mem* functions are declared in the
  1505. X    <memory.h> file.  This file is also included in the <strings.h> file,
  1506. X    but it does no harm to #include both in either order.
  1507. X*/
  1508. X
  1509. X#ifndef    memeql
  1510. X
  1511. X#define memeql    !memcmp
  1512. Xextern    int    memcmp(/*char^,char^,int*/);
  1513. Xextern    char    *memcpy(/*char^,char^,int*/);
  1514. Xextern    char    *memccpy(/*char^,char^,char,int*/);
  1515. Xextern    char    *memset(/*char^,char,int*/);
  1516. Xextern    char    *memchr(/*char^,char,int*/);
  1517. Xextern    char    *memrchr(/*char^,char,int*/);
  1518. Xextern    char    *memmov(/*char^,char^,int*/);
  1519. Xextern    void    memrev(/*char^,char^,int*/);
  1520. X
  1521. X#endif    memeql
  1522. X
  1523. SHAR_EOF
  1524. sed 's/^X//' << 'SHAR_EOF' > memrchr.c
  1525. X/*  File   : memrchr.c
  1526. X    Author : Richard A. O'Keefe.
  1527. X    Updated: 25 May 1984
  1528. X    Defines: memrchr()
  1529. X
  1530. X    memrchr(src, chr, len)
  1531. X    searches the memory area pointed to by src extending for len bytes,
  1532. X    looking for an occurrence of the byte value chr.  It returns NullS
  1533. X    if there is no such occurrence.  Otherwise it returns a pointer to
  1534. X    the LAST such occurrence.
  1535. X
  1536. X    See the "Character Comparison" section in the READ-ME file.
  1537. X*/
  1538. X
  1539. X#include "strings.h"
  1540. X
  1541. Xchar *memrchr(src, chr, len)
  1542. X    register char *src;
  1543. X    register int chr;        /* should be char */
  1544. X    register int len;
  1545. X    {
  1546. X    register char *ans;
  1547. X    for (ans = NullS; --len >= 0; src++)
  1548. X        if (*src == chr) ans = src;
  1549. X    return ans;
  1550. X    }
  1551. X
  1552. SHAR_EOF
  1553. sed 's/^X//' << 'SHAR_EOF' > memrev.c
  1554. X/*  File   : memrev.c
  1555. X    Author : Richard A. O'Keefe.
  1556. X    Updated: 1 June 1984
  1557. X    Defines: memrev()
  1558. X
  1559. X    memrev(dst, src, len)
  1560. X    moves len bytes from src to dst, in REVERSE order.  NUL characters
  1561. X    receive no special treatment, they are moved like the rest.  It is
  1562. X    to strrev as memcpy is to strcpy.
  1563. X
  1564. X    Note: this function is perfectly happy to reverse a block into the
  1565. X    same place, memrev(x, x, L) will work.
  1566. X    It will not work for partially overlapping source and destination.
  1567. X*/
  1568. X
  1569. X#include "strings.h"
  1570. X
  1571. Xvoid memrev(dsta, srca, len)
  1572. X    register char *dsta, *srca;
  1573. X    int len;
  1574. X    {
  1575. X    register char *dstz, *srcz;
  1576. X    register int t;
  1577. X
  1578. X    if (len <= 0) return;
  1579. X    srcz = srca+len;
  1580. X    dstz = dsta+len;
  1581. X    while (srcz > srca) {
  1582. X        t = *--srcz;
  1583. X        *--dstz = *srca++;
  1584. X        *dsta++ = t;
  1585. X    }
  1586. X    }
  1587. X
  1588. SHAR_EOF
  1589. sed 's/^X//' << 'SHAR_EOF' > memset.c
  1590. X/*  File   : memset.c
  1591. X    Author : Richard A. O'Keefe.
  1592. X    Updated: 25 May 1984
  1593. X    Defines: memset()
  1594. X
  1595. X    memset(dst, chr, len)
  1596. X    fills the memory area dst[0..len-1] with len bytes all equal to chr.
  1597. X    The result is dst.  See also bfill(), which has no return value and
  1598. X    puts the last two arguments the other way around.
  1599. X
  1600. X    Note: the VAX assembly code version can only handle 0 <= len < 2^16.
  1601. X    It is presented for your interest and amusement.
  1602. X*/
  1603. X
  1604. X#include "strings.h"
  1605. X
  1606. X#if    VaxAsm
  1607. X
  1608. Xchar *memset(dst, chr, len)
  1609. X    char *dst;
  1610. X    int chr;            /* should be char */
  1611. X    int len;
  1612. X    {
  1613. X    asm("movc5 $0,*4(ap),8(ap),12(ap),*4(ap)");
  1614. X    return dst;
  1615. X    }
  1616. X
  1617. X#else  ~VaxAsm
  1618. X
  1619. Xchar *memset(dst, chr, len)
  1620. X    char *dst;
  1621. X    register int chr;        /* should be char */
  1622. X    register int len;
  1623. X    {
  1624. X    register char *d;
  1625. X
  1626. X    for (d = dst; --len >= 0; *d++ = chr) ;
  1627. X    return dst;
  1628. X    }
  1629. X
  1630. X#endif    VaxAsm
  1631. X
  1632. SHAR_EOF
  1633. sed 's/^X//' << 'SHAR_EOF' > memtrans.c
  1634. X/*  File   : memtrans.c
  1635. X    Author : Richard A. O'Keefe.
  1636. X    Updated: 2 June 1984
  1637. X    Defines: memtrans()
  1638. X
  1639. X    memtrans(dst, src, from, to, len)
  1640. X    copies exactly len characters from src[] to dst[], translating chars
  1641. X    in from[] to corresponding characters in to[].   From[] and to[] are
  1642. X    handled by _str2map. BEWARE: _str2map normally expects characters in
  1643. X    the range 0..127.  The Vax MOVTC instruction thinks its table is 256
  1644. X    bytes long; if you want to translate arbitrary bytes you'd better be
  1645. X    sure that the _map_vec array is 256 bytes long.  As distributed, the
  1646. X    memtrans function is only for translating ASCII (to 8-bit codes).
  1647. X
  1648. X    The VaxAsm code can only handle 0 <= len < 2^16, and is presented as
  1649. X    usual for your interest and amusement.  Why *do* designers of 32-bit
  1650. X    machines put 16-bit limits on strings?  (Dec aren't the only ones.)
  1651. X*/
  1652. X
  1653. X#include "strings.h"
  1654. X#include "_str2map.h"
  1655. X
  1656. X#if    VaxAsm
  1657. X
  1658. Xvoid memtrans(dst, src, from, to, len)
  1659. X    _char_ *dst, *src, *from, *to;
  1660. X    int len;
  1661. X    {
  1662. X    _str2map(0, from, to);
  1663. X    asm("movtc 20(ap),*8(ap),$0,__map_vec,20(ap),*4(ap)");
  1664. X    }
  1665. X
  1666. X#else  ~VaxAsm
  1667. X
  1668. Xvoid memtrans(dst, src, from, to, len)
  1669. X    register _char_ *dst, *src;
  1670. X    _char_ *from, *to;
  1671. X    register int len;
  1672. X    {
  1673. X    _str2map(0, from, to);
  1674. X    while (--len >= 0) *dst++ = _map_vec[*src++];
  1675. X    }
  1676. X
  1677. X#endif    VaxAsm
  1678. X
  1679. SHAR_EOF
  1680. exit
  1681.  
  1682.  
  1683.