TIP: Click on subject to list as thread! ANSI
echo: muffin
to: Bo Simonsen
from: Vince Coen
date: 2003-11-23 23:31:00
subject: Backspace

Hello Bo!

23 Nov 03 15:13, you wrote to Russell Tiedt:

 BS> I'm gonna find dos2unix and run it thru the sqafix source.

Well just in case you can't ,  here it is:

=== Cut ===
/*
 *  dos2unix.c
 *
 *  A utility to convert text files from DOS to UNIX format.  Bytes values
 *  of 0x0d (CR) and 0x1a (EOF or Ctrl+Z) are stripped.
 *
 *  Copyright (c) December 1998 Clem Dye 
 *  Copyright (c) June 2003 Andrew Clarke 
 */

/*
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/*
 *  The author of the original source code is unknown.
 *
 *  Modified in December 1998 by Clem Dye to compile cleanly using Microsoft
 *  Visual C.  Added exit(1) statements in main() to improve error reporting
 *  when the program is used in batch scripts.
 *
 *  Modified in June 2003 by Andrew Clarke  to compile
 *  cleanly with several other compilers.  General code clean-up and better
 *  error handling.
 */

#define PROGNAME "dos2unix"

#include 
#include 
#include 
#include 
#include 
#include 

#ifdef __GNUC__
#include 
#include 
#else
#include 
#include 
#endif

static struct stat s_buf;

static int dos2u(char *path)
{
    FILE *ifp, *ofp;
    int ch, rval;
    char temppath[250];
    struct utimbuf ut_buf;

    strcpy(temppath, "./clntmp");
    strcat(temppath, "XXXXXX");
    mktemp(temppath);

    ifp = fopen(path, "rb");

    if (ifp == NULL)
    {
        perror(path);
        return EXIT_FAILURE;
    }

    ofp = fopen(temppath, "wb");

    if (ofp == NULL)
    {
        perror(temppath);
        fclose(ifp);
        return EXIT_FAILURE;
    }

    rval = EXIT_SUCCESS;

#define CR 0x0d
#define CZ 0x1a

    ch = getc(ifp);

    while (ch != EOF)
    {
        if (ch != CR && ch != CZ)
        {
            if (putc(ch, ofp) == EOF)
            {
                perror(temppath);
                rval = EXIT_FAILURE;
                break;
            }
        }

        ch = getc(ifp);
    }

    if (fclose(ifp) != 0)
    {
        perror(path);
        rval = EXIT_FAILURE;
    }

    if (fclose(ofp) != 0)
    {
        perror(temppath);
        rval = EXIT_FAILURE;
    }

    ut_buf.actime = s_buf.st_atime;
    ut_buf.modtime = s_buf.st_mtime;

    if (utime(temppath, &ut_buf) != 0)
    {
        perror(temppath);
        rval = EXIT_FAILURE;
    }

    if (remove(path) != 0)
    {
        perror(path);
        rval = EXIT_FAILURE;
    }

    if (rval != EXIT_SUCCESS)
    {
        remove(temppath);
        return rval;
    }

    if (rename(temppath, path) != 0)
    {
        fprintf(stderr, PROGNAME ": Problems renaming '%s' to '%s': 
%s\n",temppath, path, strerror(errno));
        fprintf(stderr, "          However, file '%s'
remains.\n", temppath);
        exit(EXIT_FAILURE);
    }

    remove(temppath);

    return rval;
}

int main(int argc, char **argv)
{
    char *path;

    while (--argc > 0)
    {
        path = *++argv;

        if (stat(path, &s_buf) != 0)
        {
            fprintf(stderr, PROGNAME ": Can't stat '%s': %s\n", path, 
strerror(errno));
            return EXIT_FAILURE;
        }

        printf(PROGNAME ": Processing file '%s' ...\n", path);

        if (dos2u(path) != EXIT_SUCCESS)
        {
            fprintf(stderr, PROGNAME ": Problems processing file '%s'.\n", 
path);
            return EXIT_FAILURE;
        }
    }

    return EXIT_SUCCESS;
}
=== Cut ===


Vince

--- Linux/Mbse/GoldED+/LNX 1.1.5
* Origin: Air Applewood, Linux Gateway for Essex (2:257/609)
SEEN-BY: 633/267 270
@PATH: 257/609 250/501 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.