Annotation of researchv10no/libpicfile/picopen_w.c, revision 1.1.1.1

1.1       root        1: #include <picfile.h>
                      2: #include <stdio.h>
                      3: #include <libc.h>
                      4: #define        NPROP   1024
                      5: PRD_error(f, buf)
                      6: PICFILE *f;
                      7: char *buf;
                      8: {
                      9:        return 0;
                     10: }
                     11: extern char cmdline[513];      /* from getflags */
                     12: PICFILE *picopen_w(file, type, x, y, w, h, chan, argv, cmap)
                     13: char *file, *type, *chan, *argv[], *cmap;
                     14: {
                     15:        int i;
                     16:        char prop[NPROP];
                     17:        PICFILE *p=(PICFILE *)malloc(sizeof(PICFILE));
                     18:        if(p==0) return 0;
                     19:        p->flags=PIC_NOCLOSE;
                     20:        p->argc=-1;
                     21:        p->cmap=0;
                     22:        if(strcmp(file, "OUT")==0)
                     23:                p->fd=1;
                     24:        else{
                     25:                p->fd=creat(file, 0666);
                     26:                if(p->fd<0){
                     27:                Error:
                     28:                        if(!(p->flags&PIC_NOCLOSE)) close(p->fd);
                     29:                        if(p->argc>=0){
                     30:                                for(i=0;i!=p->argc;i++) free(p->argv[i]);
                     31:                                free((char *)p->argv);
                     32:                        }
                     33:                        if(p->cmap) free(p->cmap);
                     34:                        free((char *)p);
                     35:                        return 0;
                     36:                }
                     37:                p->flags=0;
                     38:        }       
                     39:        p->argc=0;
                     40:        p->argv=(char **)malloc(sizeof(char *));
                     41:        p->argv[0]=0;
                     42:        for(i=0;PIC_conf[i].type;i++)
                     43:                if(strcmp(type, PIC_conf[i].type)==0) break;
                     44:        if(!PIC_conf[i].type){
                     45:                PIC_error="Illegal TYPE";
                     46:                goto Error;
                     47:        }
                     48:        p->rd=PRD_error;
                     49:        p->wr=PIC_conf[i].wr;
                     50:        p->cl=PIC_conf[i].cl;
                     51:        p->line=0;
                     52:        p->buf=0;
                     53:        picputprop(p, "TYPE", type);
                     54:        p->type=picgetprop(p, "TYPE");
                     55:        sprintf(prop, "%d %d %d %d", x, y, x+w, y+h);
                     56:        picputprop(p, "WINDOW", prop);
                     57:        p->x=x;
                     58:        p->y=y;
                     59:        p->width=w;
                     60:        p->height=h;
                     61:        p->nchan=strlen(chan);
                     62:        if(PIC_conf[i].nchan!=0 && PIC_conf[i].nchan!=p->nchan){
                     63:                PIC_error="wrong NCHAN for this TYPE";
                     64:                goto Error;
                     65:        }
                     66:        sprintf(prop, "%d", p->nchan);
                     67:        picputprop(p, "NCHAN", prop);
                     68:        picputprop(p, "CHAN", chan);
                     69:        p->chan=picgetprop(p, "CHAN");
                     70:        if(PIC_command) picputprop(p, "COMMAND", PIC_command);
                     71:        if(cmdline[0])
                     72:                strcpy(prop, cmdline);
                     73:        else if(argv){
                     74:                prop[0]='\0';
                     75:                for(i=0;argv[i];i++){
                     76:                        if(i!=0) strcat(prop, " ");
                     77:                        strcat(prop, argv[i]);
                     78:                }
                     79:        }
                     80:        else
                     81:                sprintf(prop, "magically-create %s", file);
                     82:        picputprop(p, "COMMAND", prop);
                     83:        if(cmap){
                     84:                p->cmap=malloc(3*256);
                     85:                if(p->cmap==0){
                     86:                        PIC_error="No memory for colormap";
                     87:                        goto Error;
                     88:                }
                     89:                memcpy(p->cmap, cmap, 3*256);
                     90:                picputprop(p, "CMAP", "");
                     91:        }
                     92:        else
                     93:                p->cmap=0;
                     94:        return p;
                     95: }
                     96: PWR_header(p)
                     97: PICFILE *p;
                     98: {
                     99:        register char **ap, *vp, *ep;
                    100:        int nlen;
                    101:        for(ap=p->argv;*ap;ap++){
                    102:                vp=strchr(*ap, '=')+1;
                    103:                nlen=vp-*ap;
                    104:                for(;;){
                    105:                        write(p->fd, *ap, nlen);
                    106:                        ep=strchr(vp, '\n');
                    107:                        if(ep){
                    108:                                write(p->fd, vp, ep+1-vp);
                    109:                                vp=ep+1;
                    110:                        }
                    111:                        else{
                    112:                                write(p->fd, vp, strlen(vp));
                    113:                                write(p->fd, "\n", 1);
                    114:                                break;
                    115:                        }
                    116:                }
                    117:        }
                    118:        write(p->fd, "\n", 1);
                    119:        if(p->cmap)
                    120:                write(p->fd, p->cmap, 3*256);
                    121: }

unix.superglobalmegacorp.com

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