Annotation of 43BSD/contrib/cpm/src/pip.c, revision 1.1.1.1

1.1       root        1: /*     pip.c   1.5     83/05/13        */
                      2: 
                      3: #include <stdio.h>
                      4: #include "cpmio.h"
                      5: #include "cpmfio.h"
                      6: 
                      7: /*
                      8:  * Copy unix file to cpm
                      9:  */
                     10: 
                     11: pip(cmdline, bin)
                     12:        char cmdline[];
                     13: {
                     14: 
                     15:        char    *index(), *i;
                     16: 
                     17:        if ((i = index(cmdline,' ')) == NULL) {
                     18:                printf("too few arguments: %s\n", cmdline);
                     19:                return;
                     20:        }
                     21:        *i = '\0';
                     22:        pipc(cmdline,i+1, bin);
                     23: }
                     24: 
                     25: pipc(unixfile, cpmfile, bin)
                     26:        char cpmfile[], unixfile[];
                     27: {
                     28: 
                     29:        FILE *ufid;
                     30:        char name[9], ext[4];
                     31:        C_FILE *cid;
                     32:        int flag = 0;
                     33: 
                     34:        if ((ufid = fopen(unixfile, "r")) == NULL) {
                     35:                printf("can't open %s\n", unixfile);
                     36:                return;
                     37:        }
                     38:        if (!(namesep(cpmfile, name, ext))) 
                     39:                return;
                     40:        if (bin)
                     41:                flag = BINARY;
                     42:        if ((cid = c_creat(name, ext, flag)) == NULL)
                     43:                return;
                     44:        if (bin)
                     45:                pipbin(cid, ufid);
                     46:        else
                     47:                piptext(cid, ufid);
                     48:        c_close(cid); 
                     49:        fclose(ufid);
                     50: }
                     51: 
                     52: piptext(cid, ufid)
                     53:        FILE *ufid;
                     54:        C_FILE *cid;
                     55: {
                     56:        int c = 0;
                     57: 
                     58:        while ((c = getc(ufid)) != EOF) {
                     59:                if (c == '\n')  {
                     60:                        if (c_putc('\r', cid) == EOF) 
                     61:                                break;
                     62:                }
                     63:                if (c_putc(c, cid) == EOF) 
                     64:                        break;
                     65:        }
                     66: }
                     67: 
                     68: pipbin(cid, ufid)
                     69:        FILE *ufid;
                     70:        C_FILE *cid;
                     71: {
                     72:        char buf[128];
                     73: 
                     74:        while (read(fileno(ufid), buf, 128) != 0) {
                     75:                if (c_write(cid, buf, 128) != 128) {
                     76:                        fprintf(stderr, "pipbin: write error\n");
                     77:                        return;
                     78:                }
                     79:        }
                     80: }

unix.superglobalmegacorp.com

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