Annotation of 43BSD/contrib/cpm/src/copy.c, revision 1.1

1.1     ! root        1: /*     copy.c  1.8     83/05/13        */
        !             2: 
        !             3: #include <stdio.h>
        !             4: #include "cpmio.h"
        !             5: #include "cpmfio.h"
        !             6: 
        !             7: #define        CTRL_Z  0x1a            /* CP/M end-of-file */
        !             8: 
        !             9: /* 
        !            10:  * copy cpmfile to unix file 
        !            11:  */
        !            12: 
        !            13: copyc(cmdline, bin)
        !            14:        char cmdline[];
        !            15: {
        !            16: 
        !            17:        char    *index(), *i;
        !            18: 
        !            19:        if ((i = index(cmdline,' ')) == NULL) {
        !            20:                printf("too few arguments: %s\n", cmdline);
        !            21:                return;
        !            22:        }
        !            23:        *i = '\0';
        !            24:        copy(cmdline, i+1, bin);
        !            25: }
        !            26: 
        !            27: copy(cpmfile, unixfile, bin)
        !            28:        char cpmfile[], unixfile[];
        !            29: {
        !            30: 
        !            31:        FILE *ufid;
        !            32:        char name[9], ext[4];
        !            33:        C_FILE *cid;
        !            34: 
        !            35:        if (!(namesep(cpmfile, name, ext))) 
        !            36:                return;
        !            37:        if ((cid = c_open(name, ext, READ)) == NULL)
        !            38:                return;
        !            39: 
        !            40:        if ( unixfile == (char *)stdout )
        !            41:                ufid = stdout;
        !            42:        else {
        !            43:                if (access(unixfile,0) == 0) {
        !            44:                        printf("%s already exists\n", unixfile);
        !            45:                        return;
        !            46:                }
        !            47:                if ((ufid = fopen(unixfile, "w")) == NULL) {
        !            48:                        printf("can't open %s\n", unixfile);
        !            49:                        return;
        !            50:                }
        !            51:        }
        !            52:        if (bin)
        !            53:                copybin(cid, ufid);
        !            54:        else
        !            55:                copytext(cid, ufid);
        !            56:        c_close(cid);  
        !            57: }
        !            58: 
        !            59: copytext(cid, ufid)
        !            60:        FILE *ufid;
        !            61:        C_FILE *cid;
        !            62: {
        !            63:        int c = 0;
        !            64: 
        !            65:        while (((c = c_getc(cid)) != EOF) && (c != CTRL_Z)) {
        !            66:                if ( c != '\r') 
        !            67:                        putc(c, ufid);
        !            68:        }
        !            69:        if (isatty(fileno(ufid))) 
        !            70:                printf("\n");
        !            71:        else
        !            72:                fclose(ufid);
        !            73: }
        !            74: 
        !            75: copybin(cid, ufid)
        !            76:        FILE *ufid;
        !            77:        C_FILE *cid;
        !            78: {
        !            79:        int c = 0;
        !            80: 
        !            81:        while ((c = c_getc(cid)) != EOF) 
        !            82:                putc(c, ufid);
        !            83:        fclose(ufid);
        !            84: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.