home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1007 < prev    next >
Internet Message Format  |  1990-12-28  |  5KB

  1. From: jeff@quark.WV.TEK.COM (Jeff Beadles)
  2. Newsgroups: alt.sources
  3. Subject: Casefix - "Fix" all upper/lower case messages
  4. Message-ID: <6392@orca.wv.tek.com>
  5. Date: 10 Mar 90 23:35:52 GMT
  6.  
  7. HAVE YOU BEEN SHOUTED AT ONCE TOO OFTEN IN ALL UPPER CASE?
  8.  
  9. or, do you hate it when you get messages that are in all lower case?
  10.  
  11. If so, then casefix might be the next best thing to user education.
  12.  
  13. I tossed this together one morning, when I had received yet another file that
  14. was in all upper case.  It works as a filter, so you can do things like
  15. (from rn)
  16.  
  17.   End of article 123 (of 123)--what next? [npq] | ~/.bin/casefix | more
  18.  
  19.  
  20. Have fun!   I'll send it to comp.sources.misc in a few weeks.  (Time to get any
  21. remaining kinks out.)
  22.  
  23.     -Jeff
  24.  
  25. -- 
  26. Jeff Beadles    jeff@orca.WV.TEK.COM    uunet!tektronix!orca.wv!jeff
  27.  
  28.  
  29.  
  30. #--------------------------------CUT HERE-------------------------------------
  31. #! /bin/sh
  32. #
  33. # This is a shell archive.  Save this into a file, edit it
  34. # and delete all lines above this comment.  Then give this
  35. # file to sh by executing the command "sh file".  The files
  36. # will be extracted into the current directory owned by
  37. # you with default permissions.
  38. #
  39. # The files contained herein are:
  40. #
  41. # -rw-r--r--  1 jeff          607 Mar 10 15:25 README
  42. # -rw-r--r--  1 jeff         2226 Mar 10 15:28 casefix.c
  43. #
  44. echo 'x - README'
  45. if test -f README; then echo 'shar: not overwriting README'; else
  46. sed 's/^X//' << '________This_Is_The_END________' > README
  47. Xcasefix.c - Copyright 1990, Jeff Beadles.  All rights reserved.
  48. X
  49. XPermission is granted to copy this at NO charge, as long as the copyright
  50. Xmessage remains intact.
  51. X
  52. XThis program will take all all upper/lower case text, and attempt to convert it
  53. Xto mixed case.  It is not 100% accurate.  It doesn't know about things
  54. Xlike proper nouns.  (But what do you expect for free? :-)
  55. X
  56. XTo compile:  cc -o casefix casefix.c  (Simple enough.)
  57. X
  58. XTo use:  casefix < ifile > ofile
  59. X
  60. XHave fun!  Feel free to send constructive comments or patches.
  61. X
  62. X    -Jeff
  63. X-- 
  64. XJeff Beadles    jeff@orca.WV.TEK.COM (or) uunet!tektronix!orca.wv!jeff
  65. ________This_Is_The_END________
  66. if test `wc -c < README` -ne 607; then
  67.     echo 'shar: README was damaged during transit (should have been 607 bytes)'
  68. fi
  69. fi        ; : end of overwriting check
  70. echo 'x - casefix.c'
  71. if test -f casefix.c; then echo 'shar: not overwriting casefix.c'; else
  72. sed 's/^X//' << '________This_Is_The_END________' > casefix.c
  73. X/*
  74. X * Submittor: Jeff Beadles    jeff@orca.WV.TEK.COM
  75. X * Date: Sat Mar 10 15:12:46 PST 1990
  76. X * Name: casefix
  77. X * Version: 1.0
  78. X * Machine: Unix
  79. X * Synopsis: Fixes all upper/lower case text into mixed case.
  80. X * Category: utils
  81. X */
  82. X
  83. X/* casefix.c - Copyright 1990, Jeff Beadles.  All rights reserved.
  84. X * Permission is granted to copy this at NO charge, as long as the copyright
  85. X * message remains intact.
  86. X *
  87. X * This is not 100% accurate.  It doesn't know about things like proper nouns.
  88. X * (But what do you expect for free? :-)
  89. X *
  90. X * To compile:  cc -o casefix casefix.c  (Simple enough.)
  91. X *
  92. X * To use:  casefix < ifile > ofile
  93. X *
  94. X *  Have fun!  Feel free to send constructive comments or patches to:
  95. X *    jeff@quark.WV.TEK.COM  or
  96. X *    uunet!tektronix!orca.wv!jeff
  97. X */
  98. X
  99. X#include <stdio.h>
  100. X#include <ctype.h>
  101. X
  102. X/* ARGSUSED */
  103. Xmain(argc,argv)
  104. Xint argc;
  105. Xchar **argv;
  106. X
  107. X{
  108. X    int ch;            /* Tmp character holder */
  109. X    int lastch;            /* Last char displayed */
  110. X    int nextch;            /* Next character to be displayed (For I') */
  111. X    int newsent;        /* Start of sentence flag */
  112. X
  113. X    newsent = 1;        /* Start file with a new sentence */
  114. X    nextch = lastch = -1;    /* Nothing in them yet. */
  115. X
  116. X    while(1) {
  117. X        /* if readahead buffer is empty, then get another char */
  118. X        if ( nextch == -1) {
  119. X            if ( (ch = getc(stdin)) == EOF )
  120. X                exit(0);
  121. X        } else {
  122. X            ch = nextch;
  123. X            nextch = -1;
  124. X        }
  125. X        /* Default, is to make it lower case. */
  126. X        ch = tolower(ch);
  127. X
  128. X        /* Cap "(For example...)" */
  129. X        if ( lastch == '(')
  130. X            ch = toupper(ch);
  131. X
  132. X        /* Cap "I will, I've */
  133. X        if ( (isspace(lastch)) && (ch == 'i') ) {
  134. X            if ( (nextch = getchar()) == EOF) {
  135. X                putchar(ch);
  136. X                exit(0);
  137. X            }
  138. X        /* Don't ungetc nextch, as it will be used next.  */
  139. X            if ((isspace(nextch)) || (nextch == '\'')) {
  140. X                ch = toupper(ch);
  141. X            }
  142. X        }
  143. X
  144. X        /* Cap 1st word of a new sentence. */
  145. X        if ( (newsent) && isalpha(ch)) {
  146. X            newsent = 0;
  147. X            ch = toupper(ch);
  148. X        }
  149. X
  150. X        /* Sentences end with '.', '!', ':', '?', or ';'. */
  151. X        if ( (ch == '.') || (ch == '!') ||
  152. X         (ch == ':') || (ch == ';') || (ch == '?'))
  153. X            newsent = 1;
  154. X
  155. X        /* Finally, display the character */
  156. X        putchar(ch);
  157. X        lastch = ch;
  158. X    }
  159. X}
  160. ________This_Is_The_END________
  161. if test `wc -c < casefix.c` -ne 2226; then
  162.     echo 'shar: casefix.c was damaged during transit (should have been 2226 bytes)'
  163. fi
  164. fi        ; : end of overwriting check
  165. exit 0
  166.