unix2dos. How does it understand wild cards?

unix2dos. How does it understand wild cards?

Post by Greg Zubk » Mon, 27 Nov 1995 04:00:00



Hi John Birchfield!

There is a very little chance, that this letter really will come to
you.
I downloaded from Internet a package called dos2unix.zip

I unzipped it and there was a unix2dos.com file.

I wanted to understand how it works, so I have looked in the
unix2dos.c version of the file.

I have run UNIX2dos.com as followes:
        1. I have put unix2dos.com in my c:\util, which was in
                my PATH statement in autoexec.bat
        2. I copied in my work directory the source files from UNIX.
        3. I typed unix2dos *.*
        4. I saw messages coming "cleaning file..."
        5. it did all the files O.K.
Then I wanted to see what is going on, so I have recompiled the
program using a Borland compiler.
 i had to change the following:

#if MSDOS
#       define link(x,y) rename (x, y)
#       define R_CNTRL   "rb"
#       define W_CNTRL   "wb"
#else
#       define R_CNTRL   "r"
#       define W_CNTRL   "w"
#endif

as:

#define MSDOS
#ifdef  MSDOS
#       define link(x,y) rename (x, y)
#       define R_CNTRL   "rb"
#       define W_CNTRL   "wb"
#else
#       define R_CNTRL   "r"
#       define W_CNTRL   "w"
#endif

 because it would not link.
Anyway, i compiled it and put in a de* and try to run it.
It did *on fopen, because file path name was *.*.
When I did supplu good file name it worked fine.

Why your version (unix2dos.com) worked originally O.K. with *.*
wildcard?

I could not understand in the source, how it picks up all the file
name in the directory?

/*
 *                              UNIX2DOS.C
 *
 * Convert lf's to crlf combinations in a file but keep it's original
 * date/time stamp.
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef TRUE
#       define TRUE  (1)
#       define FALSE (0)
#endif

#if MSDOS
#       define link(x,y) rename (x, y)
#       define R_CNTRL   "rb"
#       define W_CNTRL   "wb"
#else
#       define R_CNTRL   "r"
#       define W_CNTRL   "w"
#endif

struct stat s_buf;

main (argc, argv)
int argc;
char **argv;
{
        char *path;
        while (--argc>0)
        {
                if (stat (path=*++argv, &s_buf) != -1)
                {
                        printf ("Unix2Dos: Cleaning file %s ...\n", path);
                        if (u2dos (path))
                        {
                                fprintf (stderr, "Unix2Dos: Problems cleaning file %s\n", path);
                        }
                }
                else
                {
                        fprintf (stderr, "Unix2Dos: Can't stat '%s'\n", path);
                }
        }

Quote:}

int
u2dos (path)
char *path;
{
        FILE *in, *out;
        int ch,
            rval = FALSE;
        char temppath [16];
        struct utimbuf { time_t actime, modtime; } ut_buf;

        strcpy (temppath, "./clntmp");

/* I also have changed here gsz

#if !defined (MSDOS)
        strcat (temppath, "XXXXXX");
        mktemp (temppath);
#endif  
*/

#ifdef MSDOS
        strcat (temppath, "XXXXXX");
        mktemp (temppath);
#endif  

        if ((in=fopen (path, R_CNTRL)) == (FILE *) 0)
                return TRUE;
        if ((out=fopen (temppath, W_CNTRL)) == (FILE *) 0)
        {
                fclose (in);
                return TRUE;
        }
        while ((ch = getc (in)) != EOF)
                if (((ch == '\012') && (putc ('\015', out) == EOF)) ||
                    (putc (ch, out) == EOF)                   )
                {
                        rval = TRUE;
                        break;
                }
        if (fclose (in) == EOF)
        {
                rval = TRUE;
        }
        if (fclose (out) == EOF)
        {
                rval = TRUE;
        }
        ut_buf.actime = s_buf.st_atime;
        ut_buf.modtime = s_buf.st_mtime;
        if (utime (temppath, &ut_buf) == -1)
                rval = TRUE;
        if (unlink (path) == -1)
                rval = TRUE;
        if (rval)
        {
                unlink (temppath);
                return TRUE;
        }
        if (link (temppath,path) == -1)
        {
                fprintf (stderr, "Unix2Dos: Problems renaming '%s' to '%s'\n",
temppath, path);
                fprintf (stderr, "          However, file '%s' remains\n", temppath);
                exit (1);
        }
        unlink (temppath);
        return FALSE;

Quote:}

 
 
 

unix2dos. How does it understand wild cards?

Post by Edward L » Fri, 01 Dec 1995 04:00:00


If you have a Borland compiler, look in the documentation for wildargs.obj
or something similar.  Linking your program with this file will allow
wildcard expansion.

-Ed L