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

  1. From: jeff@onion.pdx.com (Jeff Beadles)
  2. Newsgroups: alt.sources
  3. Subject: casefix Version 1.1
  4. Message-ID: <1990Dec13.202514.2023@onion.pdx.com>
  5. Date: 13 Dec 90 20:25:14 GMT
  6.  
  7.  
  8. Well, there was a bug on some systems with the original version of casefix that
  9. I posted last week.  Some system's don't handle toupper/tolower properly if the
  10. character is not alpha to be begin with.  So, I've changed things like
  11.     ch = tolower(ch) to...
  12.  
  13.     if (isupper(ch))
  14.         ch = tolower(ch);
  15.  
  16. Also, I've added the provision for '\n\n' to also be considered the end
  17. of a sentence.
  18.  
  19. I decided not to post a patch, as the entire source listing is <5k.
  20.  
  21.  
  22. Have fun, and remember to always post follow-up's to alt.sources.d :-)
  23.  
  24.     -Jeff
  25.  
  26. #--------------------------------CUT HERE-------------------------------------
  27. #! /bin/sh
  28. #
  29. # This is a shell archive.  Save this into a file, edit it
  30. # and delete all lines above this comment.  Then give this
  31. # file to sh by executing the command "sh file".  The files
  32. # will be extracted into the current directory owned by
  33. # you with default permissions.
  34. #
  35. # The files contained herein are:
  36. #
  37. # -rw-r--r--  1 jeff          601 Dec 13 12:15 README
  38. # -rw-r--r--  1 jeff         2549 Dec 13 12:19 casefix.c
  39. #
  40. echo 'x - README'
  41. if test -f README; then echo 'shar: not overwriting README'; else
  42. sed 's/^X//' << '________This_Is_The_END________' > README
  43. Xcasefix.c - Copyright 1990, Jeff Beadles.  All rights reserved.
  44. X
  45. XPermission is granted to copy this at NO charge, as long as the copyright
  46. Xmessage remains intact.
  47. X
  48. XThis program will take all all upper/lower case text, and attempt to convert it
  49. Xto mixed case.  It is not 100% accurate.  It doesn't know about things
  50. Xlike proper nouns.  (But what do you expect for free? :-)
  51. X
  52. XTo compile:  cc -o casefix casefix.c  (Simple enough.)
  53. X
  54. XTo use:  casefix < ifile > ofile
  55. X
  56. XHave fun!  Feel free to send constructive comments or patches.
  57. X
  58. X    -Jeff
  59. X-- 
  60. XJeff Beadles    jeff@onion.pdx.com (or) uunet!onion.pdx.com!jeff
  61. ________This_Is_The_END________
  62. if test `wc -c < README` -ne 601; then
  63.     echo 'shar: README was damaged during transit (should have been 601 bytes)'
  64. fi
  65. fi        ; : end of overwriting check
  66. echo 'x - casefix.c'
  67. if test -f casefix.c; then echo 'shar: not overwriting casefix.c'; else
  68. sed 's/^X//' << '________This_Is_The_END________' > casefix.c
  69. X/*
  70. X * Submittor: Jeff Beadles    jeff@onion.pdx.com
  71. X * Date: Thu Dec 13 12:11:39 PST 1990
  72. X * Name: casefix
  73. X * Version: 1.1
  74. X * Machine: Unix
  75. X * Synopsis: Fixes all upper/lower case text into mixed case.
  76. X * Category: utils
  77. X */
  78. X
  79. X/* casefix.c - Copyright 1990, Jeff Beadles.  All rights reserved.
  80. X * Permission is granted to copy this at NO charge, as long as the copyright
  81. X * message remains intact.
  82. X *
  83. X * This is not 100% accurate.  It doesn't know about things like proper nouns.
  84. X * (But what do you expect for free? :-)
  85. X *
  86. X * To compile:  cc -o casefix casefix.c  (Simple enough.)
  87. X *
  88. X * To use:  casefix < ifile > ofile
  89. X *
  90. X *  Have fun!  Feel free to send constructive comments or patches to:
  91. X *    jeff@onion.pdx.com    (or)
  92. X *    uunet!onion.pdx.com!jeff
  93. X *
  94. X * Version 1.1: Fixed a bug on some machines where if you use toupper/tolower
  95. X *        on a non-alpha character, it scrambles it.  Grr....
  96. X *        Also, '\n\n' marks the end of a sentence.
  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        if(isupper(ch))
  127. X        ch = tolower(ch);
  128. X
  129. X        /* Cap "(For example...)" */
  130. X        if ( (lastch == '(') && (islower(ch)))
  131. X            ch = toupper(ch);
  132. X
  133. X        /* Cap "I will, I've */
  134. X        if ( (isspace(lastch)) && (ch == 'i') ) {
  135. X            if ( (nextch = getchar()) == EOF) {
  136. X                putchar(ch);
  137. X                exit(0);
  138. X            }
  139. X        /* Don't ungetc nextch, as it will be used next.  */
  140. X            if ((isspace(nextch)) || (nextch == '\'')) {
  141. X            if(islower(ch)) {
  142. X                    ch = toupper(ch);
  143. X            }
  144. X            }
  145. X        }
  146. X
  147. X        /* Cap 1st word of a new sentence. */
  148. X        if ( (newsent) && isalpha(ch)) {
  149. X            newsent = 0;
  150. X        if(islower(ch)) {
  151. X                ch = toupper(ch);
  152. X        }
  153. X        }
  154. X
  155. X        /* Sentences end with '.', '!', ':', '?', or ';'. or '\n\n' */
  156. X        if ( (ch == '.') || (ch == '!') ||
  157. X         (ch == ':') || (ch == ';') || (ch == '?') ||
  158. X         ( (ch == '\n') && (lastch == '\n')) )
  159. X            newsent = 1;
  160. X
  161. X        /* Finally, display the character */
  162. X        putchar(ch);
  163. X        lastch = ch;
  164. X    }
  165. X}
  166. ________This_Is_The_END________
  167. if test `wc -c < casefix.c` -ne 2549; then
  168.     echo 'shar: casefix.c was damaged during transit (should have been 2549 bytes)'
  169. fi
  170. fi        ; : end of overwriting check
  171. exit 0
  172.