From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 18-JUN-1993 09:51:37.79
To:	EVERHART
CC:	
Subj:	Re: Wanted: Two vax utility programs

X-Newsgroups: comp.os.vms
From: bf7012536@v9000.ntu.ac.sg
Subject: Re: Wanted: Two vax utility programs
Message-Id: <1993Jun17.052048.1@ntuvax.ntu.ac.sg>
Lines: 94
Sender: news@ntuix.ntu.ac.sg (USENET News System)
Nntp-Posting-Host: v9001.ntu.ac.sg
Organization: Nanyang Technological University - Singapore
Date: Wed, 16 Jun 1993 21:20:48 GMT
To: Info-VAX@kl.sri.com
X-Gateway-Source-Info: USENET

nchizek@galaxy.gov.bc.ca wanted a crlf converter for dos / vax.  here is a
simple one that i wrote in a hurry.  Could anyone modify it to be portable 
for three environment, dos/unix/vax?

thank you.

NTUVAX Cookie Monster.

---------------------------------
/*/

     Simple CRLF Converter.  Original March 28, 1993 by NTU Cookie Monster.

/*/

#include <stdio.h>

#ifndef __MSDOS__
#define __VAX_C__
#endif

#ifdef __UNIX_C__
#define  del              "rm"
#define  ren              "mv"
#endif

#ifdef __MSDOS__
#define  del              "del"
#define  ren              "ren"
#endif

#ifdef __VAX_C__
#define  del              "delete"
#define  ren              "rename"
#endif

#define  tmpfile          "crlf.tmp"

int main( argc, argv )
int argc;
char *argv[];
{
    FILE *fin, *fout;

    if (argc<3) {
        printf("Usage: %s <d/uv> <filename>\n", argv[0]);
        exit(0);
    }

    if ((fin=fopen(argv[2],"rb")) == NULL) {
        printf("Unable to open %s for input!\n", argv[2]);
        exit(0);
    }

    if ((fout=fopen(tmpfile,"wb")) == NULL) {
        printf("No Space to create temporary file!\n");
        exit(0);
    }

    convert(*argv[1], fin, fout);

    fclose(fin);
    fclose(fout);

    cleanup(argv[2], tmpfile);
}

int convert(fmt, fin, fout)
char fmt;
FILE *fin, *fout;
{
    int c;

    for (c=fgetc(fin); c != EOF; c=fgetc(fin))
    {
        switch(fmt)           /* do not put break; */
        {
            case 'd': if (c=='\x0a') fputc('\x0d', fout);
            case 'u': case 'v': if (c!='\x0d') fputc(c, fout);
        }
    }
}

int cleanup(filename, tmp)
char *filename, *tmp;
{
   char rename[80], delete[80];

   sprintf(delete, "%s %s", del, filename);
   system(delete);

   sprintf(rename, "%s %s %s", ren, tmp, filename);
   system(rename);
}

