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

  1. From: jeff@onion.pdx.com (Jeff Beadles)
  2. Newsgroups: alt.sources
  3. Subject: Utility to convert uppercase filenames
  4. Message-ID: <1990Dec12.061449.2776@onion.pdx.com>
  5. Date: 12 Dec 90 06:14:49 GMT
  6.  
  7. In article <7529@castle.ed.ac.uk> aipdc@castle.ed.ac.uk (Paul Crowley) writes:
  8. >I'd like to know if there's an "intelligent" casing program out there
  9. >that I could feed "BIFF" posts through.  Something that would capitalise
  10. >after full stops, and recognise some proper nouns, for example. 
  11. >Mixed-case is so much easier to read.
  12.  
  13. ***
  14.  Note:  Alt.sources is for source code postings only.  Please PLEASE use
  15.     alt.sources.d for discussions.  Thank you.
  16. ***
  17.  
  18. Now, on to the source code.  I've posted this before, but since it's so short
  19. I'll post it again.  It gets "I" right, but doesn't know about other proper
  20. nouns.  It's free, so if you don't like it, "rm" it. :-)
  21.  
  22.  
  23. -------Start of readme (from the casefix.sh archive)------
  24. casefix.c - Copyright 1990, Jeff Beadles.  All rights reserved.
  25.  
  26. Permission is granted to copy this at NO charge, as long as the copyright
  27. message remains intact.
  28.  
  29. This program will take all all upper/lower case text, and attempt to convert it
  30. to mixed case.  It is not 100% accurate.  It doesn't know about things
  31. like proper nouns.  (But what do you expect for free? :-)
  32.  
  33. To compile:  cc -o casefix casefix.c  (Simple enough.)
  34.  
  35. To use:  casefix < ifile > ofile
  36.  
  37. Have fun!  Feel free to send constructive comments or patches.
  38.  
  39.     -Jeff
  40.  
  41.  
  42.  
  43. #--------------------------------CUT HERE-------------------------------------
  44. #! /bin/sh
  45. #
  46. # This is a shell archive.  Save this into a file, edit it
  47. # and delete all lines above this comment.  Then give this
  48. # file to sh by executing the command "sh file".  The files
  49. # will be extracted into the current directory owned by
  50. # you with default permissions.
  51. #
  52. # The files contained herein are:
  53. #
  54. # -rw-r--r--  1 jeff          605 Dec 11 22:10 README
  55. # -rw-r--r--  1 jeff         2213 Dec 11 22:10 casefix.c
  56. #
  57. echo 'x - README'
  58. if test -f README; then echo 'shar: not overwriting README'; else
  59. sed 's/^X//' << '________This_Is_The_END________' > README
  60. Xcasefix.c - Copyright 1990, Jeff Beadles.  All rights reserved.
  61. X
  62. XPermission is granted to copy this at NO charge, as long as the copyright
  63. Xmessage remains intact.
  64. X
  65. XThis program will take all all upper/lower case text, and attempt to convert it
  66. Xto mixed case.  It is not 100% accurate.  It doesn't know about things
  67. Xlike proper nouns.  (But what do you expect for free? :-)
  68. X
  69. XTo compile:  cc -o casefix casefix.c  (Simple enough.)
  70. X
  71. XTo use:  casefix < ifile > ofile
  72. X
  73. XHave fun!  Feel free to send constructive comments or patches.
  74. X
  75. X    -Jeff
  76. X-- 
  77. XJeff Beadles    jeff@onion.pdx.com    (or) ...!uunet!onion.pdx.com!jeff
  78. ________This_Is_The_END________
  79. if test `wc -c < README` -ne 605; then
  80.     echo 'shar: README was damaged during transit (should have been 605 bytes)'
  81. fi
  82. fi        ; : end of overwriting check
  83. echo 'x - casefix.c'
  84. if test -f casefix.c; then echo 'shar: not overwriting casefix.c'; else
  85. sed 's/^X//' << '________This_Is_The_END________' > casefix.c
  86. X/*
  87. X * Submittor: Jeff Beadles    jeff@onion.pdx.com
  88. X * Date: Sat Mar 10 15:12:46 PST 1990
  89. X * Name: casefix
  90. X * Version: 1.0
  91. X * Machine: Unix
  92. X * Synopsis: Fixes all upper/lower case text into mixed case.
  93. X * Category: utils
  94. X */
  95. X
  96. X/* casefix.c - Copyright 1990, Jeff Beadles.  All rights reserved.
  97. X * Permission is granted to copy this at NO charge, as long as the copyright
  98. X * message remains intact.
  99. X *
  100. X * This is not 100% accurate.  It doesn't know about things like proper nouns.
  101. X * (But what do you expect for free? :-)
  102. X *
  103. X * To compile:  cc -o casefix casefix.c  (Simple enough.)
  104. X *
  105. X * To use:  casefix < ifile > ofile
  106. X *
  107. X *  Have fun!  Feel free to send constructive comments or patches to:
  108. X *    jeff@onion.pdx.com
  109. X *    uunet!onion.pdx.com!jeff
  110. X */
  111. X
  112. X#include <stdio.h>
  113. X#include <ctype.h>
  114. X
  115. X/* ARGSUSED */
  116. Xmain(argc,argv)
  117. Xint argc;
  118. Xchar **argv;
  119. X
  120. X{
  121. X    int ch;            /* Tmp character holder */
  122. X    int lastch;            /* Last char displayed */
  123. X    int nextch;            /* Next character to be displayed (For I') */
  124. X    int newsent;        /* Start of sentence flag */
  125. X
  126. X    newsent = 1;        /* Start file with a new sentence */
  127. X    nextch = lastch = -1;    /* Nothing in them yet. */
  128. X
  129. X    while(1) {
  130. X        /* if readahead buffer is empty, then get another char */
  131. X        if ( nextch == -1) {
  132. X            if ( (ch = getc(stdin)) == EOF )
  133. X                exit(0);
  134. X        } else {
  135. X            ch = nextch;
  136. X            nextch = -1;
  137. X        }
  138. X        /* Default, is to make it lower case. */
  139. X        ch = tolower(ch);
  140. X
  141. X        /* Cap "(For example...)" */
  142. X        if ( lastch == '(')
  143. X            ch = toupper(ch);
  144. X
  145. X        /* Cap "I will, I've */
  146. X        if ( (isspace(lastch)) && (ch == 'i') ) {
  147. X            if ( (nextch = getchar()) == EOF) {
  148. X                putchar(ch);
  149. X                exit(0);
  150. X            }
  151. X        /* Don't ungetc nextch, as it will be used next.  */
  152. X            if ((isspace(nextch)) || (nextch == '\'')) {
  153. X                ch = toupper(ch);
  154. X            }
  155. X        }
  156. X
  157. X        /* Cap 1st word of a new sentence. */
  158. X        if ( (newsent) && isalpha(ch)) {
  159. X            newsent = 0;
  160. X            ch = toupper(ch);
  161. X        }
  162. X
  163. X        /* Sentences end with '.', '!', ':', '?', or ';'. */
  164. X        if ( (ch == '.') || (ch == '!') ||
  165. X         (ch == ':') || (ch == ';') || (ch == '?'))
  166. X            newsent = 1;
  167. X
  168. X        /* Finally, display the character */
  169. X        putchar(ch);
  170. X        lastch = ch;
  171. X    }
  172. X}
  173. ________This_Is_The_END________
  174. if test `wc -c < casefix.c` -ne 2213; then
  175.     echo 'shar: casefix.c was damaged during transit (should have been 2213 bytes)'
  176. fi
  177. fi        ; : end of overwriting check
  178. exit 0
  179.