home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / convloup.zip / convert.c next >
Text File  |  1997-06-08  |  4KB  |  97 lines

  1. /*********************************************************************/
  2. /*                                                                   */
  3. /* Convert Version 1.00                                              */
  4. /*                                                                   */
  5. /* Converts uppercase file names to lower case and visa versa        */
  6. /* Written by :  John Ballment                                       */
  7. /* Written on :  06 June, 1997                                       */
  8. /*                                                                   */
  9. /* I wrote this small application to convert files from uppercase    */
  10. /* to lowercase after doing a project with a couple of friends who   */
  11. /* where using Windows 95.                                           */
  12. /*                                                                   */
  13. /* Everytime they saved files onto thier disks, the filenames were   */
  14. /* in uppercase, which made it hard to port onto my OS/2 system and  */
  15. /* the UNIX system which the project was being designed for.         */
  16. /*                                                                   */
  17. /* The program command-line is as follows:                           */
  18. /*                                                                   */
  19. /*      convert -u/l <filename>                                      */
  20. /*                                                                   */
  21. /* -u = convert to uppercase (I wrote it to convert both ways)       */
  22. /* -l = convert to lowercase                                         */
  23. /* <filename> = a filename including wildcards like * and ?          */
  24. /*                                                                   */
  25. /* If you find the program useful please send a post card to:        */
  26. /*                                                                   */
  27. /*     John Ballment                                                 */
  28. /*     98 Kilsay Cres                                                */
  29. /*     Meadowbrook  Q  4131                                          */
  30. /*     Australia, plant Earth, the Milky-Way solar system            */
  31. /*                                                                   */
  32. /* Please send any bug reports to:                                   */
  33. /*                                                                   */
  34. /*     n1237462@droid.fit.qut.edu.au                                 */
  35. /*                                                                   */
  36. /*********************************************************************/
  37.  
  38. #include <stdio.h>
  39. #include <string.h>
  40.  
  41. #define OK 0
  42. #define FAILED 1
  43. #define FilenameLength 256
  44. #define FILENAME 2
  45. #define CONVERT 1
  46. #define PROGRAM 0
  47.  
  48. int main (int argc, char *argv[]) {
  49.  
  50.    char name[FilenameLength], *newname;
  51.    char temp[FilenameLength], *tempname;
  52.    int count;
  53.  
  54.    newname = name;
  55.    tempname = temp;
  56.  
  57.    if (argc < 3) {
  58.       printf("\n example usage is: %s <convert> <filename>\n", argv[PROGRAM]);
  59.       return FAILED;
  60.       }
  61.    if ((strcmp(strlwr(argv[CONVERT]), "-u")) == OK)  {
  62.       for (count = FILENAME; count <= argc - 1; count++) {
  63.          tempname = tmpnam(NULL);
  64.          if ((rename(argv[count], tempname)) != OK) {
  65.             printf("\nCould not rename file %s to temporary filename %s\n", argv[count], tempname);
  66.             return FAILED;
  67.             }
  68.          strcpy(newname, argv[count]);
  69.          strupr(newname);
  70.          if ((rename(tempname, newname)) != OK) {
  71.             printf("\nCould not rename file %s to %s\n", argv[count], newname);
  72.             return FAILED;
  73.             }
  74.          }
  75.       }
  76.    else if (strcmp(strlwr(argv[CONVERT]), "-l") == OK) {
  77.       for (count = FILENAME; count <= argc - 1; count++) {
  78.          tempname = tmpnam(NULL);
  79.          if ((rename(argv[count], tempname)) != OK) {
  80.             printf("\nCould not rename file %s to temporary filename %s\n", argv[count], tempname);
  81.             return FAILED;
  82.             }
  83.          strcpy(newname, argv[count]);
  84.          strlwr(newname);
  85.          if ((rename(tempname, newname)) != OK) {
  86.             printf("\nCould not rename file %s to %s\n", argv[count], newname);
  87.             return FAILED;
  88.             }
  89.          }
  90.       }
  91.    else {
  92.       printf("\nConvert must be either -l<ower> or -u<pper>\n");
  93.       return FAILED;
  94.       }
  95.    return OK;
  96.    }
  97.