home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 61 < prev    next >
Encoding:
Internet Message Format  |  1991-05-03  |  6.6 KB

  1. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  2. Newsgroups: comp.sources.apple2
  3. Subject: v001SRC042:  conv -- Character Converter For Oraca (GS)
  4. Message-ID: <May.2.17.08.33.1991.302@yoko.rutgers.edu>
  5. Date: 2 May 91 21:08:36 GMT
  6. Approved: jac@paul.rutgers.edu
  7.  
  8.  
  9. Submitted-by: Jawaid Bazyar (bazyar@cs.uiuc.edu)
  10. Posting-number: Volume 1, Source:42
  11. Archive-name: util/gs/shell/orca/conv
  12. Architecture: ONLY_2gs
  13. Version-number: 1.2
  14.  
  15.  
  16. conv performs the following conversions:
  17.     lf <--> cr
  18.     upper case --> lower case
  19.     tabs --> spaces
  20.  
  21. It requires the ORCA shell to run.
  22.  
  23. Enjoy
  24.  
  25. ###################################
  26.  
  27. =conv.doc
  28. -============
  29. -    CONV
  30. -============
  31. -
  32. -Version 1.2
  33. -
  34. -CONV is a general purpose file format converter program.  Included with
  35. -this version of CONV are the following translation options:
  36. -
  37. -   crlf       convert Apple text to Unix text
  38. -   lfcr       convert Unix text to Apple text
  39. -   lower      convert all the letters in a filename to lowercase
  40. -   detab      converts the tabs in a file to spaces
  41. -
  42. -CONV (except for detab) is invoked with the following command:
  43. -
  44. -   conv -<option> <filename>...
  45. -
  46. -The detab operation is called slightly differently:
  47. -
  48. -   conv -detab <col> <filename>...
  49. -
  50. -The value <col> is a number indicating how many columns lie between tab
  51. -stops.  Eight (8) is the value normally used in Unix (and the ORCA shell),
  52. -and four (4) is good for C programs.  Note that CONV -detab does not blindly
  53. -insert <col> spaces for every tab it finds.  It outputs enough spaces only to
  54. -move to the next tab stop.
  55. -
  56. -Update Log:
  57. -
  58. -       CONV didn't support wildcards correctly in v1.0, an oversight.
  59. -       It also now uses the GS/OS BeginSession call for better performance.
  60. -       Of course the real bottleneck is the fact that CONV is written in C.
  61. -       Bug me enough and I'll redo the necessary parts in assembly.
  62. -
  63. -Note:
  64. -
  65. -A filespec is a method of identifying files on a disk.  In the ORCA
  66. -shell, a filespec can contain the = and ? wildcards, in addition to
  67. -plain filenames.  CONV supports multiple filespecs, e.g.
  68. -    conv -LFCR a.c b.c c.c d=.c
  69. -etc.  Any combination of wildcarded and/or vanilla filespecs is allowed.
  70. -This functionality, however, comes at a price.  CONV works only under
  71. -the ORCA shell or a compatible.  At this time, there are no shells truly
  72. -compatible with ORCA.
  73. -
  74. -----
  75. -
  76. -Jawaid Bazyar
  77. -Derek Taubert
  78. -
  79. -Copyright 1990 by Procyon Software
  80. -Freeware - distribute but don't sell!
  81. -
  82. -This utility is FreeWare.  Distribute them as much as you like, just
  83. -don't sell them or distribute modified versions.  Send me your comments -
  84. -I'm eager to hear from you for suggestions and improvements.
  85. -
  86. -Also, if you make any modifications to the code please do not redistribute
  87. -them. Instead, send me the changed source along with an explanation and
  88. -I will consider including your change in the next version.
  89. -
  90. -    Jawaid Bazyar
  91. -    1120 Maple Street
  92. -    Mt. Vernon, IL 62864
  93. -
  94. -    Internet/ARPAnet     bazyar@cs.uiuc.edu
  95. -    GEnie                J.BAZYAR
  96. -
  97. =conv.c
  98. -#include <stdio.h>
  99. -#include <ctype.h>
  100. -#include <stdlib.h>
  101. -#include <gsos.h>
  102. -#include <shell.h>
  103. -
  104. -void usage()
  105. -{
  106. -    printf("Usage: conv -<convspec> <filespec>... \n");
  107. -    printf("  <convspec> is one of the following:\n");
  108. -    printf("    CRLF  - convert CR to LF\n");
  109. -    printf("    LFCR  - convert LF to CR\n");
  110. -    printf("    lower - change the filename to lowercase\n");
  111. -    printf("    detab <col> - convert tabs to spaces (tab stop every COL\
  112. - columns)\n");
  113. -    exit(1);
  114. -}
  115. -
  116. -GSString255Ptr MakeGSString1(char *s)
  117. -{
  118. -GSString255Ptr n;
  119. -    n = malloc(sizeof(GSString255));
  120. -    strcpy((char *) n->text,s);
  121. -    n->length = strlen(s);
  122. -    return n;
  123. -}
  124. -
  125. -main(argc,argv)
  126. -int argc;
  127. -char *argv[];
  128. -{
  129. -int x;
  130. -FILE *i,*o;
  131. -int c,d;
  132. -int filecount;
  133. -int curcolumn,tabColumns;
  134. -FileInfoRecGS info;
  135. -char expanded[65];
  136. -Init_WildcardPB iwpb;
  137. -Next_WildcardPB nwpb;
  138. -int SessionPB = 0;
  139. -
  140. -    filecount = 2;
  141. -    if (argc < 3) usage();
  142. -    { int i;
  143. -      i = 0;
  144. -      while (argv[1][i] = tolower(argv[1][i++]));
  145. -    }
  146. -
  147. -    if (!strcmp(argv[1],"-crlf"))
  148. -        x = 1;
  149. -    else if (!strcmp(argv[1],"-lfcr"))
  150. -        x = 2;
  151. -    else if (!strcmp(argv[1],"-lower"))
  152. -        x = 3;
  153. -    else if (!strcmp(argv[1],"-detab")) {
  154. -        x = 4;
  155. -        filecount = 3;
  156. -        sscanf(argv[2],"%d",&tabColumns);
  157. -    }
  158. -    else { printf("Illegal conversion parameter %s\n",argv[1]);
  159. -        usage(); }
  160. -
  161. -    BeginSessionGS(&SessionPB);
  162. -    while (filecount < argc)
  163. -    {
  164. -      strcpy(expanded+1,argv[filecount]);
  165. -      expanded[0] = strlen(argv[filecount]);
  166. -      iwpb.w_file = expanded;
  167. -      iwpb.flags = 0x8000;
  168. -      INIT_WILDCARD(&iwpb);
  169. -      nwpb.nextfile = expanded;
  170. -      NEXT_WILDCARD(&nwpb);
  171. -      expanded[expanded[0]+1] = 0;
  172. -      while (strlen(expanded) != 0) {
  173. -
  174. -        if (x == 3) {
  175. -        char *r,*p;
  176. -            p = malloc(strlen(expanded+1)+1);
  177. -            strcpy(p,expanded+1);
  178. -            r = p;
  179. -            while (*r != '\0') { if (isupper(*r)) *r = tolower(*r); r++; }
  180. -            printf("New filename: %s\n",p);
  181. -            rename(expanded+1,p);
  182. -            free(p);
  183. -            goto NextFile; /* sorry, I can't think of a better way to do this */
  184. -        }
  185. -
  186. -        i = fopen(expanded+1,"rb");
  187. -        o = fopen("tmp000","wb");
  188. -        info.pCount = 4;
  189. -        info.pathname = MakeGSString1(expanded+1);
  190. -        GetFileInfoGS(&info);
  191. -        curcolumn = 0;
  192. -        printf("Converting %s",expanded+1);
  193. -        while ((c = getc(i)) != EOF)
  194. -        {
  195. -            if (x == 1)
  196. -            {
  197. -                if (c == '\r') fputc(10,o);
  198. -                else fputc(c,o);
  199. -            }
  200. -            else if (x == 2)
  201. -            {
  202. -                if (c == '\n') fputc('\r',o);
  203. -                else fputc(c,o);
  204. -            }
  205. -            else if (x == 4)
  206. -            {
  207. -                switch (c)
  208. -                {
  209. -                    case '\t':
  210. -                    { int i;
  211. -                      for (i = (curcolumn % tabColumns); i < tabColumns; i++)
  212. -                          {    fputc(' ',o); curcolumn++;   }
  213. -                    }
  214. -                    break;
  215. -
  216. -                    case '\n':
  217. -                    case '\r': curcolumn = -1;
  218. -
  219. -                    default: curcolumn++;
  220. -                             fputc(c,o);
  221. -                }
  222. -            }
  223. -        }
  224. -
  225. -        fclose(i);
  226. -        fclose(o);
  227. -        remove(expanded+1);
  228. -        rename("tmp000",expanded+1);
  229. -        SetFileInfoGS(&info);
  230. -        free(info.pathname);
  231. -        printf("\n");
  232. -
  233. -NextFile:
  234. -        NEXT_WILDCARD(&nwpb);
  235. -        expanded[expanded[0]+1] = 0;
  236. -      }
  237. -      filecount++;
  238. -    }
  239. -    EndSessionGS(&SessionPB);
  240. -}
  241. -
  242. + END OF ARCHIVE
  243.