🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sources.apple2
1 messages
1 total messages Started by Jonathan A. Chandross Thu, 02 May 1991 21:08
v001SRC042: conv -- Character Converter For Oraca (GS)
#42
Author: Jonathan A. Chandross
Date: Thu, 02 May 1991 21:08
235 lines
7002 bytes
Submitted-by: Jawaid Bazyar (bazyar@cs.uiuc.edu)
Posting-number: Volume 1, Source:42
Archive-name: util/gs/shell/orca/conv
Architecture: ONLY_2gs
Version-number: 1.2


conv performs the following conversions:
	lf <--> cr
	upper case --> lower case
	tabs --> spaces

It requires the ORCA shell to run.

Enjoy

###################################

=conv.doc
-============
-    CONV
-============
-
-Version 1.2
-
-CONV is a general purpose file format converter program.  Included with
-this version of CONV are the following translation options:
-
-   crlf       convert Apple text to Unix text
-   lfcr       convert Unix text to Apple text
-   lower      convert all the letters in a filename to lowercase
-   detab      converts the tabs in a file to spaces
-
-CONV (except for detab) is invoked with the following command:
-
-   conv -<option> <filename>...
-
-The detab operation is called slightly differently:
-
-   conv -detab <col> <filename>...
-
-The value <col> is a number indicating how many columns lie between tab
-stops.  Eight (8) is the value normally used in Unix (and the ORCA shell),
-and four (4) is good for C programs.  Note that CONV -detab does not blindly
-insert <col> spaces for every tab it finds.  It outputs enough spaces only to
-move to the next tab stop.
-
-Update Log:
-
-       CONV didn't support wildcards correctly in v1.0, an oversight.
-       It also now uses the GS/OS BeginSession call for better performance.
-       Of course the real bottleneck is the fact that CONV is written in C.
-       Bug me enough and I'll redo the necessary parts in assembly.
-
-Note:
-
-A filespec is a method of identifying files on a disk.  In the ORCA
-shell, a filespec can contain the = and ? wildcards, in addition to
-plain filenames.  CONV supports multiple filespecs, e.g.
-	conv -LFCR a.c b.c c.c d=.c
-etc.  Any combination of wildcarded and/or vanilla filespecs is allowed.
-This functionality, however, comes at a price.  CONV works only under
-the ORCA shell or a compatible.  At this time, there are no shells truly
-compatible with ORCA.
-
-----
-
-Jawaid Bazyar
-Derek Taubert
-
-Copyright 1990 by Procyon Software
-Freeware - distribute but don't sell!
-
-This utility is FreeWare.  Distribute them as much as you like, just
-don't sell them or distribute modified versions.  Send me your comments -
-I'm eager to hear from you for suggestions and improvements.
-
-Also, if you make any modifications to the code please do not redistribute
-them. Instead, send me the changed source along with an explanation and
-I will consider including your change in the next version.
-
-	Jawaid Bazyar
-	1120 Maple Street
-	Mt. Vernon, IL 62864
-
-	Internet/ARPAnet     bazyar@cs.uiuc.edu
-	GEnie                J.BAZYAR
-
=conv.c
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <gsos.h>
-#include <shell.h>
-
-void usage()
-{
-    printf("Usage: conv -<convspec> <filespec>... \n");
-    printf("  <convspec> is one of the following:\n");
-    printf("    CRLF  - convert CR to LF\n");
-    printf("    LFCR  - convert LF to CR\n");
-    printf("    lower - change the filename to lowercase\n");
-    printf("    detab <col> - convert tabs to spaces (tab stop every COL\
- columns)\n");
-    exit(1);
-}
-
-GSString255Ptr MakeGSString1(char *s)
-{
-GSString255Ptr n;
-    n = malloc(sizeof(GSString255));
-    strcpy((char *) n->text,s);
-    n->length = strlen(s);
-    return n;
-}
-
-main(argc,argv)
-int argc;
-char *argv[];
-{
-int x;
-FILE *i,*o;
-int c,d;
-int filecount;
-int curcolumn,tabColumns;
-FileInfoRecGS info;
-char expanded[65];
-Init_WildcardPB iwpb;
-Next_WildcardPB nwpb;
-int SessionPB = 0;
-
-    filecount = 2;
-    if (argc < 3) usage();
-    { int i;
-      i = 0;
-      while (argv[1][i] = tolower(argv[1][i++]));
-    }
-
-    if (!strcmp(argv[1],"-crlf"))
-        x = 1;
-    else if (!strcmp(argv[1],"-lfcr"))
-        x = 2;
-    else if (!strcmp(argv[1],"-lower"))
-        x = 3;
-    else if (!strcmp(argv[1],"-detab")) {
-        x = 4;
-        filecount = 3;
-        sscanf(argv[2],"%d",&tabColumns);
-    }
-    else { printf("Illegal conversion parameter %s\n",argv[1]);
-        usage(); }
-
-    BeginSessionGS(&SessionPB);
-    while (filecount < argc)
-    {
-      strcpy(expanded+1,argv[filecount]);
-      expanded[0] = strlen(argv[filecount]);
-      iwpb.w_file = expanded;
-      iwpb.flags = 0x8000;
-      INIT_WILDCARD(&iwpb);
-      nwpb.nextfile = expanded;
-      NEXT_WILDCARD(&nwpb);
-      expanded[expanded[0]+1] = 0;
-      while (strlen(expanded) != 0) {
-
-        if (x == 3) {
-        char *r,*p;
-            p = malloc(strlen(expanded+1)+1);
-            strcpy(p,expanded+1);
-            r = p;
-            while (*r != '\0') { if (isupper(*r)) *r = tolower(*r); r++; }
-            printf("New filename: %s\n",p);
-            rename(expanded+1,p);
-            free(p);
-            goto NextFile; /* sorry, I can't think of a better way to do this */
-        }
-
-        i = fopen(expanded+1,"rb");
-        o = fopen("tmp000","wb");
-        info.pCount = 4;
-        info.pathname = MakeGSString1(expanded+1);
-        GetFileInfoGS(&info);
-        curcolumn = 0;
-        printf("Converting %s",expanded+1);
-        while ((c = getc(i)) != EOF)
-        {
-            if (x == 1)
-            {
-                if (c == '\r') fputc(10,o);
-                else fputc(c,o);
-            }
-            else if (x == 2)
-            {
-                if (c == '\n') fputc('\r',o);
-                else fputc(c,o);
-            }
-            else if (x == 4)
-            {
-                switch (c)
-                {
-                    case '\t':
-                    { int i;
-                      for (i = (curcolumn % tabColumns); i < tabColumns; i++)
-                          {    fputc(' ',o); curcolumn++;   }
-                    }
-                    break;
-
-                    case '\n':
-                    case '\r': curcolumn = -1;
-
-                    default: curcolumn++;
-                             fputc(c,o);
-                }
-            }
-        }
-
-        fclose(i);
-        fclose(o);
-        remove(expanded+1);
-        rename("tmp000",expanded+1);
-        SetFileInfoGS(&info);
-        free(info.pathname);
-        printf("\n");
-
-NextFile:
-        NEXT_WILDCARD(&nwpb);
-        expanded[expanded[0]+1] = 0;
-      }
-      filecount++;
-    }
-    EndSessionGS(&SessionPB);
-}
-
+ END OF ARCHIVE
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads