BOOL command(int commandc) { char filename[PATHLEN + 1]; /* file path name */ MOUSEEVENT *p; /* mouse data */ int c, i; FILE *file; HISTORY *curritem, *item; /* command history */ char *s; switch (commandc) { case ctrl('C'): /* toggle caseless mode */ if (caseless == NO) { caseless = YES; putmsg2("Caseless mode is now ON"); } else { caseless = NO; putmsg2("Caseless mode is now OFF"); } egrepcaseless(caseless); /* turn on/off -i flag */ return (NO); case ctrl('R'): /* rebuild the cross reference */ if (isuptodate == YES) { putmsg("The -d option prevents rebuilding the " "symbol database"); return (NO); } exitcurses(); freefilelist(); /* remake the source file list */ makefilelist(); rebuild(); if (errorsfound == YES) { errorsfound = NO; askforreturn(); } entercurses(); putmsg(""); /* clear any previous message */ totallines = 0; topline = nextline = 1; break; case ctrl('X'): /* mouse selection */ if ((p = getmouseevent()) == NULL) { return (NO); /* unknown control sequence */ } /* if the button number is a scrollbar tag */ if (p->button == '0') { scrollbar(p); break; } /* ignore a sweep */ if (p->x2 >= 0) { return (NO); } /* if this is a line selection */ if (p->y1 < FLDLINE) { /* find the selected line */ /* note: the selection is forced into range */ for (i = disprefs - 1; i > 0; --i) { if (p->y1 >= displine[i]) { break; } } /* display it in the file with the editor */ editref(i); } else { /* this is an input field selection */ field = mouseselection(p, FLDLINE, FIELDS); setfield(); resetcmd(); return (NO); } break; case '\t': /* go to next input field */ case '\n': case '\r': case ctrl('N'): case KEY_DOWN: case KEY_ENTER: case KEY_RIGHT: field = (field + 1) % FIELDS; setfield(); resetcmd(); return (NO); case ctrl('P'): /* go to previous input field */ case KEY_UP: case KEY_LEFT: field = (field + (FIELDS - 1)) % FIELDS; setfield(); resetcmd(); return (NO); case KEY_HOME: /* go to first input field */ field = 0; setfield(); resetcmd(); return (NO); case KEY_LL: /* go to last input field */ field = FIELDS - 1; setfield(); resetcmd(); return (NO); case ' ': /* display next page */ case '+': case ctrl('V'): case KEY_NPAGE: /* don't redisplay if there are no lines */ if (totallines == 0) { return (NO); } /* * note: seekline() is not used to move to the next * page because display() leaves the file pointer at * the next page to optimize paging forward */ break; case '-': /* display previous page */ case KEY_PPAGE: /* don't redisplay if there are no lines */ if (totallines == 0) { return (NO); } i = topline; /* save the current top line */ nextline = topline; /* go back to this page */ /* if on first page but not at beginning, go to beginning */ if (nextline > 1 && nextline <= mdisprefs) { nextline = 1; } else { /* go back the maximum displayable lines */ nextline -= mdisprefs; /* if this was the first page, go to the last page */ if (nextline < 1) { nextline = totallines - mdisprefs + 1; if (nextline < 1) { nextline = 1; } /* old top is past last line */ i = totallines + 1; } } /* * move down til the bottom line is just before the * previous top line */ c = nextline; for (;;) { seekline(nextline); display(); if (i - bottomline <= 0) { break; } nextline = ++c; } return (NO); /* display already up to date */ case '>': /* write or append the lines to a file */ if (totallines == 0) { putmsg("There are no lines to write to a file"); } else { /* get the file name */ (void) move(PRLINE, 0); (void) addstr("Write to file: "); s = "w"; if ((c = mygetch()) == '>') { (void) move(PRLINE, 0); (void) addstr(appendprompt); c = '\0'; s = "a"; } if (c != '\r' && c != '\n' && c != KEY_ENTER && c != KEY_BREAK && getaline(newpat, COLS - sizeof (appendprompt), c, NO) > 0) { shellpath(filename, sizeof (filename), newpat); if ((file = fopen(filename, s)) == NULL) { cannotopen(filename); } else { seekline(1); while ((c = getc(refsfound)) != EOF) { (void) putc(c, file); } seekline(topline); (void) fclose(file); } } clearprompt(); } return (NO); /* return to the previous field */ case '<': /* read lines from a file */ (void) move(PRLINE, 0); (void) addstr(readprompt); if (getaline(newpat, COLS - sizeof (readprompt), '\0', NO) > 0) { clearprompt(); shellpath(filename, sizeof (filename), newpat); if (readrefs(filename) == NO) { putmsg2("Ignoring an empty file"); return (NO); } return (YES); } clearprompt(); return (NO); case '^': /* pipe the lines through a shell command */ case '|': /* pipe the lines to a shell command */ if (totallines == 0) { putmsg("There are no lines to pipe to a shell command"); return (NO); } /* get the shell command */ (void) move(PRLINE, 0); (void) addstr(pipeprompt); if (getaline(newpat, COLS - sizeof (pipeprompt), '\0', NO) == 0) { clearprompt(); return (NO); } /* if the ^ command, redirect output to a temp file */ if (commandc == '^') { (void) strcat(strcat(newpat, " >"), temp2); } exitcurses(); if ((file = mypopen(newpat, "w")) == NULL) { (void) fprintf(stderr, "cscope: cannot open pipe to shell command: %s\n", newpat); } else { seekline(1); while ((c = getc(refsfound)) != EOF) { (void) putc(c, file); } seekline(topline); (void) mypclose(file); } if (commandc == '^') { if (readrefs(temp2) == NO) { putmsg("Ignoring empty output of ^ command"); } } askforreturn(); entercurses(); break; case ctrl('L'): /* redraw screen */ case KEY_CLEAR: (void) clearok(curscr, TRUE); (void) wrefresh(curscr); drawscrollbar(topline, bottomline, totallines); return (NO); case '!': /* shell escape */ (void) execute(shell, shell, (char *)NULL); seekline(topline); break; case '?': /* help */ (void) clear(); help(); (void) clear(); seekline(topline); break; case ctrl('E'): /* edit all lines */ editall(); break; case ctrl('A'): /* repeat last pattern */ case ctrl('Y'): /* (old command) */ if (*pattern != '\0') { (void) addstr(pattern); goto repeat; } break; case ctrl('B'): /* cmd history back */ case ctrl('F'): /* cmd history fwd */ curritem = currentcmd(); item = (commandc == ctrl('F')) ? nextcmd() : prevcmd(); clearmsg2(); if (curritem == item) { /* inform user that we're at history end */ putmsg2( "End of input field and search pattern history"); } if (item) { field = item->field; setfield(); atfield(); (void) addstr(item->text); (void) strcpy(pattern, item->text); switch (c = mygetch()) { case '\r': case '\n': case KEY_ENTER: goto repeat; default: ungetch(c); atfield(); (void) clrtoeol(); /* clear current field */ break; } } return (NO); case '\\': /* next character is not a command */ (void) addch('\\'); /* display the quote character */ /* get a character from the terminal */ if ((commandc = mygetch()) == EOF) { return (NO); /* quit */ } (void) addstr("\b \b"); /* erase the quote character */ goto ispat; case '.': atfield(); /* move back to the input field */ /* FALLTHROUGH */ default: /* edit a selected line */ if (isdigit(commandc) && commandc != '0' && !mouse) { if (returnrequired == NO) { editref(commandc - '1'); } else { (void) move(PRLINE, 0); (void) addstr(selectionprompt); if (getaline(newpat, COLS - sizeof (selectionprompt), commandc, NO) > 0 && (i = atoi(newpat)) > 0) { editref(i - 1); } clearprompt(); } } else if (isprint(commandc)) { /* this is the start of a pattern */ ispat: if (getaline(newpat, COLS - fldcolumn - 1, commandc, caseless) > 0) { (void) strcpy(pattern, newpat); resetcmd(); /* reset history */ repeat: addcmd(field, pattern); /* add to history */ if (field == CHANGE) { /* prompt for the new text */ (void) move(PRLINE, 0); (void) addstr(toprompt); (void) getaline(newpat, COLS - sizeof (toprompt), '\0', NO); } /* search for the pattern */ if (search() == YES) { switch (field) { case DEFINITION: case FILENAME: if (totallines > 1) { break; } topline = 1; editref(0); break; case CHANGE: return (changestring()); } } else if (field == FILENAME && access(newpat, READ) == 0) { /* try to edit the file anyway */ edit(newpat, "1"); } } else { /* no pattern--the input was erased */ return (NO); } } else { /* control character */ return (NO); } } return (YES); }
/* process a printjob command by command */ static int process(FILE* in, FILE* out,int verbose,unsigned int maxw,unsigned int maxh){ image_t* img=calloc(1,sizeof(image_t)); unsigned char* buf=malloc(0xFFFF); int returnv=0; int i; int num_colors; unsigned int xml_read; xml_read=0; fprintf(stderr,"------- parsing the printjob -------\n"); while(!returnv && !feof(in)){ unsigned char cmd; unsigned int cnt = 0; if((returnv = nextcmd(in,&cmd,buf,&cnt,&xml_read))) break; switch(cmd){ case 'c': fprintf(stderr,"ESC (c set media (len=%i):\n",cnt); fprintf(stderr," model id %x bw %x",buf[0]>> 4,buf[0]&0xf); fprintf(stderr," media %x",buf[1]); fprintf(stderr," direction %x quality %x\n",(buf[2]>>4)&3 ,buf[2]&0xf); break; case 'K': if(buf[1]==0x1f){ fprintf(stderr,"ESC [K go to command mode\n"); do{ fgets((char*)buf,0xFFFF,in); fprintf(stderr," %s",buf); }while(strcmp((char*)buf,"BJLEND\n")); }else if(cnt == 2 && buf[1]==0x0f){ fprintf(stderr,"ESC [K reset printer\n"); img->width=0; img->height=0; }else{ fprintf(stderr,"ESC [K unsupported param (len=%i): %x\n",cnt,buf[1]); } break; case 'b': fprintf(stderr,"ESC (b set data compression (len=%i): %x\n",cnt,buf[0]); break; case 'I': fprintf(stderr,"ESC (I select data transmission (len=%i): ",cnt); if(buf[0]==0)fprintf(stderr,"default"); else if(buf[0]==1)fprintf(stderr,"multi raster"); else fprintf(stderr,"unknown 0x%x %i",buf[0],buf[0]); fprintf(stderr,"\n"); break; case 'l': fprintf(stderr,"ESC (l select paper loading (len=%i):\n",cnt); fprintf(stderr," model id 0x%x ",buf[0]>>4); fprintf(stderr," source 0x%x",buf[0]&15); if ( cnt == 3 ) { fprintf(stderr," media: %x",buf[1]); fprintf(stderr," paper gap: %x\n",buf[2]); } else fprintf(stderr," media: %x\n",buf[1]); break; case 'd': img->xres = (buf[0]<<8)|buf[1]; img->yres = (buf[2]<<8)|buf[3]; fprintf(stderr,"ESC (d set raster resolution (len=%i): %i x %i\n",cnt,img->xres,img->yres); break; case 't': fprintf(stderr,"ESC (t set image cnt %i\n",cnt); if(buf[0]>>7){ /* usual order */ char order[]="CMYKcmyk"; /*char order[]="CMYKcmykHRGABDEFIJLMNOPQSTUVWXZabdef";*/ /* iP3500 test */ /*char order[]="CMYKcmykHRGBCMYcmykabd";*/ /*char order[]="CMYKcmykHpnoPQRSTykabd";*/ /*char order[]="KCMYkcmyHpnoPQRSTykabd";*/ /* MP960 photo modes: k instead of K */ /* char order[]="CMYkcmyKHRGABDEFIJLMNOPQSTUVWXZabdef";*/ /* T-shirt transfer mode: y changed to k --- no y, no K */ /*char order[]="CMYKcmkyHRGABDEFIJLMNOPQSTUVWXZabdef";*/ /* MP990, MG6100, MG8100 plain modes */ /*char order[]="KCcMmYykRHGABDEFIJLMNOPQSTUVWXZabdef";*/ /* MP990 etc. photo modes */ /* char order[]="KCcMmYykRHGABDEFIJLMNOPQSTUVWXZabdef"; */ /* int black_found = 0; */ num_colors = (cnt - 3)/3; fprintf(stderr," bit_info: using detailed color settings for max %i colors\n",num_colors); if(buf[1]==0x80) fprintf(stderr," format: BJ indexed color image format\n"); else if(buf[1]==0x00) fprintf(stderr," format: iP8500 flag set, BJ indexed color image format\n"); else if(buf[1]==0x90) fprintf(stderr," format: Pro9500 flag set, BJ indexed color image format\n"); else{ fprintf(stderr," format: settings not supported 0x%x\n",buf[1]); /* returnv = -2; */ } if(buf[2]==0x1) fprintf(stderr," ink: BJ indexed setting, also for iP8500 flag\n"); else if(buf[2]==0x4) fprintf(stderr," ink: Pro series setting \n"); else{ fprintf(stderr," ink: settings not supported 0x%x\n",buf[2]); /* returnv = -2; */ } for(i=0;i<num_colors;i++){ if(i<MAX_COLORS){ img->color[i].name=order[i]; img->color[i].compression=buf[3+i*3] >> 5; img->color[i].bpp=buf[3+i*3] & 31; img->color[i].level=(buf[3+i*3+1] << 8) + buf[3+i*3+2];/* check this carefully */ /* work around for levels not matching (bpp gives more) */ /*if ((img->color[i].level == 3) && (img->color[i].bpp == 2)) { printf("WARNING: color %c bpp %i declared levels %i, setting to 4 for testing \n",img->color[i].name,img->color[i].bpp,img->color[i].level); img->color[i].level = 4; } */ /*else if ((img->color[i].level == 4) && (img->color[i].bpp == 4)) {*/ /* levels is 16 but only each 2nd level is used */ /* printf("WARNING: color %c bpp %i declared levels %i, setting to 16 for testing \n",img->color[i].name,img->color[i].bpp,img->color[i].level); img->color[i].level = 16; } */ /* this is not supposed to give accurate images */ /* if(i<4) */ /* set to actual colors CMYK */ if((img->color[i].name =='K')||(img->color[i].name =='C')||(img->color[i].name =='M')||(img->color[i].name =='Y') ) { img->color[i].density = 255; /*if (i>7)*/ /*img->color[i].density -= 128; */ /* see if can subtract something from CMYK where 0x80 involved */ } else img->color[i].density = 128; /*128+96;*/ /* try to add 0x80 to sub-channels for MP450 hi-quality mode */ /* if((order[i] == 'K' || order[i] == 'k') && img->color[i].bpp) black_found = 1; */ /* if(order[i] == 'y' && !black_found && img->color[i].level){ printf("iP6700 hack: treating color definition at the y position as k\n"); img->color[i].name = 'k'; order[i] = 'k'; order[i+1] = 'y'; black_found = 1; img->color[i].density = 255; } */ /* %c*/ fprintf(stderr," Color %c Compression: %i bpp %i level %i\n",img->color[i].name, img->color[i].compression,img->color[i].bpp,img->color[i].level); }else{ fprintf(stderr," Color %i out of bounds!\n", i); /*printf(" Color ignoring setting %x %x %x\n",buf[3+i*3],buf[3+i*3+1],buf[3+i*3+2]);*/ } } }else if(buf[0]==0x1 && buf[1]==0x0 && buf[2]==0x1){
int process(FILE *infile,scanline_t *sf[7],int *xmin_,int *xmax_,int *ymin_,int *ymax_) { unsigned char inbuff[65540]; scanline_t *sl[7], *nsl; int xres,yres; int xmin=1000000,xmax=0,ymin=-1,ymax=0,width=0; int col=0; int line=0; int i; int cnt; int cmd; for (i=0; i<7; i++) sf[i]= sl[i]= 0; if (!infile) return 0; fseek(infile,0,SEEK_SET); while ((cmd= nextcmd(infile,inbuff,&cnt))) { switch(cmd) { case 0x64: yres=inbuff[0]*256+inbuff[1]; xres=inbuff[2]*256+inbuff[3]; fprintf(stderr,"res=%dx%ddpi\n",xres,yres); break; case 0x65: line+=(inbuff[0]*256+inbuff[1]); break; case 0x41: switch(inbuff[0]) { case 0x4b: col= 0; break; /* black */ case 0x59: col= 1; break; /* yellow */ case 0x4d: col= 2; break; /* magenta */ case 0x43: col= 3; break; /* cyan */ case 0x79: col= 4; break; /* lightyellow */ case 0x6d: col= 5; break; /* lightmagenta */ case 0x63: col= 6; break; /* lightcyan */ default: fprintf(stderr,"unkown color component 0x%02x\n",inbuff[0]); exit(-1); } nsl= scanline_store(0,line,inbuff+1,cnt-1); if (nsl) { if (nsl->width) { if (ymin<0) ymin=line; ymax=line; if (nsl->xmin<xmin) xmin=nsl->xmin; if (nsl->xmax>xmax) xmax=nsl->xmax; if (nsl->width>width) width=nsl->width; if (!sf[col]) sf[col]=nsl; else sl[col]->next= nsl; sl[col]= nsl; } else { stp_free (nsl); nsl= 0; } if (fgetc(infile)!=0x0d) { fprintf(stderr,"COLOR LINE NOT TERMINATED BY 0x0d @ %lx!!\n", ftell(infile)); } } break; case 0x62: break; default: ; } } fprintf(stderr,"size=%d..%d:%d..%d = %dx%d\n",xmin,xmax,ymin,ymax,width,ymax-ymin+1); *xmin_= xmin; *xmax_= xmax; *ymin_= ymin; *ymax_= ymax; return 1; }