home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume02 / sq < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  6.0 KB

  1. From mipos3!omepd!uoregon!hp-pcd!hplabs!hp-sdd!ucsdhub!sdcsvax!ucsd!ames!necntc!ncoast!allbery Tue Mar  8 19:24:37 PST 1988
  2. Article 323 of comp.sources.misc:
  3. Path: td2cad!mipos3!omepd!uoregon!hp-pcd!hplabs!hp-sdd!ucsdhub!sdcsvax!ucsd!ames!necntc!ncoast!allbery
  4. From: mikew@wyse1.wyse.com (Mike Wexler)
  5. Newsgroups: comp.sources.misc
  6. Subject: v02i070: sq - squeeze a dictionary
  7. Keywords: sq dictionary compress
  8. Message-ID: <7473@ncoast.UUCP>
  9. Date: 5 Mar 88 23:51:26 GMT
  10. Sender: allbery@ncoast.UUCP
  11. Reply-To: mikew@wyse1.wyse.com (Mike Wexler)
  12. Organization: Wyse Technology
  13. Lines: 206
  14. Approved: allbery@ncoast.UUCP
  15. Comp.sources.misc: Volume 2, Issue 70
  16. Submitted-By: "Mike Wexler" <mikew@wyse1.wyse.com>
  17. Archive-Name: sq
  18.  
  19. Comp.sources.misc: Volume 2, Issue 70
  20. Submitted-By: "Mike Wexler" <mikew@wyse1.wyse.com>
  21. Archive-Name: sq
  22.  
  23. [A couple programs that sat around until I had time to fix 'em up.  ++bsa]
  24.  
  25. The following program compresses dictionaries.  It works in combination
  26. with compress and sort.  You should have both of these for optimal use.
  27. I have included a simple demo.  Have fun...
  28. #--------------------------------CUT HERE-------------------------------------
  29. #! /bin/sh
  30. #
  31. # This is a shell archive.  Save this into a file, edit it
  32. # and delete all lines above this comment.  Then give this
  33. # file to sh by executing the command "sh file".  The files
  34. # will be extracted into the current directory owned by
  35. # you with default permissions.
  36. #
  37. # The files contained herein are:
  38. #
  39. # -rw-r--r--   1 allbery  System       449 Mar  5 18:43 Makefile
  40. # -rw-r--r--   1 allbery  System       451 Mar  5 18:43 Makefile.orig
  41. # -rw-r--r--   1 allbery  System       546 Mar  5 18:43 sq.c
  42. # -rw-r--r--   1 allbery  System       606 Mar  5 18:43 sq.l
  43. # -rw-r--r--   1 allbery  System       468 Mar  5 18:43 unsq.c
  44. #
  45. echo 'x - Makefile'
  46. if test -f Makefile; then echo 'shar: not overwriting Makefile'; else
  47. sed 's/^X//' << '________This_Is_The_END________' > Makefile
  48. XCFLAGS=-O
  49. XBINDIR=/usr/new
  50. XMANDIR=/usr/man/manl
  51. XDICT=/usr/dict/words
  52. Xall: sq unsq
  53. Xsq: sq.c
  54. X    $(CC) $(CFLAGS) -o sq sq.c
  55. Xunsq: unsq.c
  56. X    $(CC) $(CFLAGS) -o unsq unsq.c
  57. Xinstall:
  58. X    cp sq unsq $(BINDIR)
  59. X    cp sq.l $(MANDIR)
  60. Xshar:
  61. X    shar sq.l sq.c unsq.c Makefile > sq.shar
  62. Xdemo:
  63. X    sort $(DICT) | sq | compress > dict.sq.Z
  64. X    compress < $(DICT) > dict.Z
  65. X    ls -l $(DICT) dict.Z dict.sq.Z
  66. X    compress -d < dict.sq.Z | unsq | sort -df > dict.copy
  67. X    diff $(DICT) dict.copy
  68. ________This_Is_The_END________
  69. if test `wc -c < Makefile` -ne 449; then
  70.     echo 'shar: Makefile was damaged during transit (should have been 449 bytes)'
  71. fi
  72. fi        ; : end of overwriting check
  73. echo 'x - Makefile.orig'
  74. if test -f Makefile.orig; then echo 'shar: not overwriting Makefile.orig'; else
  75. sed 's/^X//' << '________This_Is_The_END________' > Makefile.orig
  76. XCFLAGS=-O
  77. XBINDIR=/usr/local/bin
  78. XMANDIR=/usr/man/manl
  79. XDICT=/usr/dict/words
  80. Xall: sq unsq
  81. Xsq: sq.c
  82. X    $(CC) $(CFLAGS) -o sq sq.c
  83. Xunsq: unsq.c
  84. X    $(CC) $(CFLAGS) -o unsq unsq.c
  85. Xinstall:
  86. X    cp sq unsq $BINDIR
  87. X    cp sq.l $MANDIR
  88. Xshar:
  89. X    shar sq.l sq.c unsq.c Makefile > sq.shar
  90. Xdemo:
  91. X    sort $(DICT) | sq | compress > dict.sq.Z
  92. X    compress < $(DICT) > dict.Z
  93. X    ls -l $(DICT) dict.Z dict.sq.Z
  94. X    compress -d < dict.sq.Z | unsq | sort -df > dict.copy
  95. X    diff $(DICT) dict.copy
  96. ________This_Is_The_END________
  97. if test `wc -c < Makefile.orig` -ne 451; then
  98.     echo 'shar: Makefile.orig was damaged during transit (should have been 451 bytes)'
  99. fi
  100. fi        ; : end of overwriting check
  101. echo 'x - sq.c'
  102. if test -f sq.c; then echo 'shar: not overwriting sq.c'; else
  103. sed 's/^X//' << '________This_Is_The_END________' > sq.c
  104. X#include <stdio.h>
  105. X
  106. Xmain()
  107. X{
  108. X  char word[257];
  109. X  static char prev[257]="";
  110. X  char outword[258];
  111. X
  112. X  while (gets(word)!=NULL) {
  113. X    trunc(word,prev);
  114. X  }
  115. Xexit(0);
  116. X}
  117. X
  118. Xtrunc(word,prev) 
  119. Xchar *word;
  120. Xchar *prev;
  121. X{
  122. X  unsigned char same_count;
  123. X  char *wordp;
  124. X  char *prevp;
  125. X
  126. X  wordp=word;
  127. X  prevp=prev;
  128. X  for (same_count=0;*wordp==*prevp++;++wordp,++same_count);
  129. X  if (same_count>255) {
  130. X    fprintf(stderr,"same count exceeded 255 characters, aborted");
  131. X    exit(1);
  132. X  }
  133. X  fwrite(&same_count,1,1,stdout);
  134. X  puts(wordp);
  135. X  strcpy(prev,word);
  136. X  return;
  137. X}
  138. X
  139. ________This_Is_The_END________
  140. if test `wc -c < sq.c` -ne 546; then
  141.     echo 'shar: sq.c was damaged during transit (should have been 546 bytes)'
  142. fi
  143. fi        ; : end of overwriting check
  144. echo 'x - sq.l'
  145. if test -f sq.l; then echo 'shar: not overwriting sq.l'; else
  146. sed 's/^X//' << '________This_Is_The_END________' > sq.l
  147. X.TH SQ 1 LOCAL
  148. X.\" $Header: unshar.man,v 1.1 87/02/27 13:45:34 rs Exp $
  149. X.SH NAME
  150. Xsq \- squeeze a sorted word list
  151. Xunsq \- unsqueeze a sorted word list
  152. X.SH SYNOPSIS
  153. X.B sq
  154. X< infile > outfile
  155. X.PP
  156. X.B unsq
  157. X< infile > outfile
  158. X.SH DESCRIPTION
  159. X.I sq
  160. Xcompresses a sorted list of words(a dictionary). 
  161. XFor example:
  162. X.RS
  163. Xsort /usr/dict/words | sq | compress > words.sq.Z
  164. X.RE
  165. Xwill compress dict by about a factor of 4.
  166. X.PP
  167. X.I unsq
  168. Xuncompress the output of
  169. X.I sq.
  170. XFor example:
  171. X.RS
  172. Xcompress -d < words.sq.Z | unsq | sort -f -o words
  173. X.RE
  174. Xwill uncompress a dictionary compressed with
  175. X.I sq.
  176. X.SH SEE ALSO
  177. Xcompress(1), sort.
  178. ________This_Is_The_END________
  179. if test `wc -c < sq.l` -ne 606; then
  180.     echo 'shar: sq.l was damaged during transit (should have been 606 bytes)'
  181. fi
  182. fi        ; : end of overwriting check
  183. echo 'x - unsq.c'
  184. if test -f unsq.c; then echo 'shar: not overwriting unsq.c'; else
  185. sed 's/^X//' << '________This_Is_The_END________' > unsq.c
  186. X#include <stdio.h>
  187. X
  188. Xmain()
  189. X{
  190. X  char word[257];
  191. X  static char prev[257]="";
  192. X  unsigned char count;
  193. X  char outword[258];
  194. X
  195. X  while (!expand(word,prev)) {
  196. X    puts(word);
  197. X  }
  198. Xexit(0);
  199. X}
  200. X
  201. Xexpand(word,prev) 
  202. Xchar *word;
  203. Xchar *prev;
  204. X{
  205. X  unsigned char same_count;
  206. X  char *wordp;
  207. X  char *prevp;
  208. X
  209. X  fread(&same_count,1,1,stdin);
  210. X  prevp=prev;
  211. X  wordp=word;
  212. X  while (same_count--)
  213. X    *wordp++=(*prevp++);
  214. X  if (gets(wordp)==NULL) return(1);
  215. X  strcpy(prev,word);
  216. X  return(0);
  217. X}
  218. X
  219. ________This_Is_The_END________
  220. if test `wc -c < unsq.c` -ne 468; then
  221.     echo 'shar: unsq.c was damaged during transit (should have been 468 bytes)'
  222. fi
  223. fi        ; : end of overwriting check
  224. exit 0
  225.  
  226.  
  227.