void browse(void) { int forward, n; static int bformat, bnum; /* 0 */ forward = 1; peekc = getchr(); if(peekc != '\n'){ if(peekc == '-' || peekc == '+') { if(peekc == '-') forward = 0; getchr(); } n = getnum(); if(n > 0) bpagesize = n; } newline(); if(pflag) { bformat = listf; bnum = listn; } else { listf = bformat; listn = bnum; } if(forward) { addr1 = addr2; addr2 += bpagesize; if(addr2 > dol) addr2 = dol; } else { addr1 = addr2-bpagesize; if(addr1 <= zero) addr1 = zero+1; } printcom(); }
void commands(void) { int *a1, c, temp; char lastsep; Dir *d; for(;;) { if(pflag) { pflag = 0; addr1 = addr2 = dot; printcom(); } c = '\n'; for(addr1 = 0;;) { lastsep = c; a1 = address(); c = getchr(); if(c != ',' && c != ';') break; if(lastsep == ',') error(Q); if(a1 == 0) { a1 = zero+1; if(a1 > dol) a1--; } addr1 = a1; if(c == ';') dot = a1; } if(lastsep != '\n' && a1 == 0) a1 = dol; if((addr2=a1) == 0) { given = 0; addr2 = dot; } else given = 1; if(addr1 == 0) addr1 = addr2; switch(c) { case 'a': add(0); continue; case 'b': nonzero(); browse(); continue; case 'c': nonzero(); newline(); rdelete(addr1, addr2); append(gettty, addr1-1); continue; case 'd': nonzero(); newline(); rdelete(addr1, addr2); continue; case 'E': fchange = 0; c = 'e'; case 'e': setnoaddr(); if(vflag && fchange) { fchange = 0; error(Q); } filename(c); init(); addr2 = zero; goto caseread; case 'f': setnoaddr(); filename(c); putst(savedfile); continue; case 'g': global(1); continue; case 'i': add(-1); continue; case 'j': if(!given) addr2++; newline(); join(); continue; case 'k': nonzero(); c = getchr(); if(c < 'a' || c > 'z') error(Q); newline(); names[c-'a'] = *addr2 & ~01; anymarks |= 01; continue; case 'm': move(0); continue; case 'n': listn++; newline(); printcom(); continue; case '\n': if(a1==0) { a1 = dot+1; addr2 = a1; addr1 = a1; } if(lastsep==';') addr1 = a1; printcom(); continue; case 'l': listf++; case 'p': case 'P': newline(); printcom(); continue; case 'Q': fchange = 0; case 'q': setnoaddr(); newline(); quit(); case 'r': filename(c); caseread: if((io=open(file, OREAD)) < 0) { lastc = '\n'; error(file); } if((d = dirfstat(io)) != nil){ if(d->mode & DMAPPEND) print("warning: %s is append only\n", file); free(d); } Binit(&iobuf, io, OREAD); setwide(); squeeze(0); c = zero != dol; append(getfile, addr2); exfile(OREAD); fchange = c; continue; case 's': nonzero(); substitute(globp != 0); continue; case 't': move(1); continue; case 'u': nonzero(); newline(); if((*addr2&~01) != subnewa) error(Q); *addr2 = subolda; dot = addr2; continue; case 'v': global(0); continue; case 'W': wrapp++; case 'w': setwide(); squeeze(dol>zero); temp = getchr(); if(temp != 'q' && temp != 'Q') { peekc = temp; temp = 0; } filename(c); if(!wrapp || ((io = open(file, OWRITE)) == -1) || ((seek(io, 0L, 2)) == -1)) if((io = create(file, OWRITE, 0666)) < 0) error(file); Binit(&iobuf, io, OWRITE); wrapp = 0; if(dol > zero) putfile(); exfile(OWRITE); if(addr1<=zero+1 && addr2==dol) fchange = 0; if(temp == 'Q') fchange = 0; if(temp) quit(); continue; case '=': setwide(); squeeze(0); newline(); count = addr2 - zero; putd(); putchr('\n'); continue; case '!': callunix(); continue; case EOF: return; } error(Q); } }
/* * Wake up a process. Put it on the run-queue if it's not * already there. The "current" process is always on the * run-queue (except when the actual re-schedule is in * progress), and as such you're allowed to do the simpler * "current->state = TASK_RUNNING" to mark yourself runnable * without the overhead of this. */ static inline int try_to_wake_up(struct task_struct * p, int synchronous) { unsigned long flags; int success = 0; unsigned long qhead; int curpri; int before,after; int cpuid = smp_processor_id(); struct _cpu * cpu=smp$gl_cpu_data[cpuid]; spin_lock_irqsave(&runqueue_lock, flags); p->state = TASK_RUNNING; p->pcb$w_state = SCH$C_COM; if (p==ctl$gl_pcb) goto out; if (task_on_comqueue(p)) /* argh! */ goto out; // p->pcb$b_pri=p->pcb$b_prib-3; /* boost */ /* not here */ curpri=p->pcb$b_pri; if (mydebug4) printk("add tyr %x %x\n",p->pcb$l_pid,curpri); #ifdef __i386__ qhead=*(unsigned long *)&sch$aq_comt[curpri]; #else qhead=*(unsigned long *)&sch$aq_comh[curpri][1]; #endif if (mydebug4) printk("eq qhead %x %x %x %x\n", (unsigned long *)qhead,(unsigned long *)(qhead+4), *(unsigned long *)qhead,*(unsigned long *)(qhead+4)); if (mydebug4) printk("p %x %x %x\n",qhead,*(void**)qhead,p); if (mydebug4) printk("iq3 %x\n",sch$aq_comh[curpri]); before=numproc(); // printcom(); // printcom2(); mycheckaddr(0); insque(p,qhead); nr_running++; after=numproc(); if(after-before!=1) { printcom(); printcom2(); panic("insq1 %x %x %x %x\n",p,p->pcb$l_pid,before,after); } if (mydebug4) printk("p %x %x %x\n",qhead,*(void**)qhead,p); if (mydebug4) printk("iq3 %x\n",sch$aq_comh[curpri]); if (mydebug4) printk("eq qhead %x %x %x %x\n", (unsigned long *)qhead,(unsigned long *)(qhead+4), *(unsigned long *)qhead,*(unsigned long *)(qhead+4)); if (mydebug4) printk("comq1 %x %x\n",curpri,sch$gl_comqs); sch$gl_comqs=sch$gl_comqs | (1 << curpri); mycheckaddr(0); if (mydebug4) printk("comq1 %x %x\n",curpri,sch$gl_comqs); if (mydebug4) { int i; struct _pcb *tmp2,*tmp3=qhead; unsigned long tmp; printk("p %x\n",p); printk("%x %x %x %x\n",tmp3,tmp3->pcb$l_sqfl,tmp3->pcb$l_sqfl->pcb$l_sqfl,tmp3->pcb$l_sqfl->pcb$l_sqfl->pcb$l_sqfl); for(i=0;i<32;i++) { tmp=&sch$aq_comh[i]; // printk("i %x %x i",i,tmp); if(*(unsigned long *)tmp == tmp) {; } else { tmp2=((struct _pcb *)tmp)->pcb$l_sqfl->pcb$l_sqfl; do { printk("com2 %x %x %x %x\n",tmp2,tmp2->pcb$l_pid,tmp2->pcb$b_pri,i); tmp2=tmp2->pcb$l_sqfl; } while (tmp2!=tmp); } } } if (!synchronous || !(p->cpus_allowed & (1 << smp_processor_id()))) reschedule_idle(p); success = 1; out: spin_unlock_irqrestore(&runqueue_lock, flags); return success; }
asmlinkage void sch$resched(void) { int cpuid = smp_processor_id(); struct _cpu * cpu=smp$gl_cpu_data[cpuid]; struct _pcb * curpcb; unsigned long curpri; unsigned long qhead; int before,after; // lock sched db, soon //if (spl(IPL$_SCHED)) return; // old=spl(IPL$_SCHED); // svpctx, do not think we need to do this here #ifdef __x86_64__ if (intr_blocked(IPL$_RESCHED)) return; regtrap(REG_INTR,IPL$_RESCHED); #endif /** spinlock sched and set ipl */ setipl(IPL$_SCHED); vmslock(&SPIN_SCHED,-1); spin_lock_irq(&runqueue_lock); /* eventually change to sched? */ /** get current pcb and priority */ curpcb=cpu->cpu$l_curpcb; release_kernel_lock(curpcb, cpuid); curpri=cpu->cpu$b_cur_pri; /** clear bit in cpu_priority table */ sch$al_cpu_priority[curpri]=sch$al_cpu_priority[curpri] & (~ cpu->cpu$l_cpuid_mask ); /** if no process with this pri on any cpu, clear bit in active_priority table */ if (!sch$al_cpu_priority[curpri]) sch$gl_active_priority=sch$gl_active_priority & (~ (1 << (31-curpri))); /** now some if's remaining from linux - TODO: check if still needed */ if (curpcb == idle_task(curpcb->pcb$l_cpu_id)) goto out; if (curpcb->state==TASK_INTERRUPTIBLE) if (signal_pending(curpcb)) { curpcb->state = TASK_RUNNING; curpcb->pcb$w_state = SCH$C_CUR; } #if 0 if (curpcb->state!=TASK_RUNNING) { curpcb->pcb$w_state=SCH$C_LEF; // use here temporarily } #endif #if 0 if (curpcb->state==TASK_RUNNING) { #endif #ifdef DEBUG_SCHED before=numproc(); // printcom(); //if (curpcb==0xa018c000 && qhead==0xa018c000) // panic("aieeeeeh\n"); mycheckaddr(0); //if (curpcb==qhead) panic(" a panic\n"); #endif /** set pri bit in comqs */ sch$gl_comqs=sch$gl_comqs | (1 << curpri); // curpcb->state=TASK_INTERRUPTIBLE; /* soon SCH$C_COM ? */ /** set state of cur pcb to COM */ curpcb->pcb$w_state=SCH$C_COM; /** insert pcb at tail of comqueue */ #ifdef __i386__ qhead=*(unsigned long *)&sch$aq_comt[curpri]; #else qhead=*(unsigned long *)&sch$aq_comh[curpri][1]; #endif if (!task_on_comqueue(curpcb)) { if (curpcb==qhead) panic(" a panic\n"); insque(curpcb,qhead); } else { panic("something\n"); } #ifdef DEBUG_SCHED mycheckaddr(42); #endif /** linux leftover */ nr_running++; #ifdef DEBUG_SCHED after=numproc(); if(after-before!=1) { //printk("entry qhead %x %x\n",curpcb,qhead); printcom(); panic("insq2 %x %x\n",before,after); } #endif out: /** clear idle_cpus to signal all idle cpus to try to reschedule */ sch$gl_idle_cpus=0; #if 0 } #endif /** go some intro sch$sched */ sch$sched(1); }
/* * Scan the JPEG file for Exif data and parse it. */ static int doit(FILE *fp, const char *fname) { int mark, gotapp1, first, rc; unsigned int len, rlen; unsigned char *exifbuf; struct exiftags *t; long app1; gotapp1 = FALSE; first = 0; exifbuf = NULL; rc = 0; while (jpegscan(fp, &mark, &len, !(first++))) { if (mark != JPEG_M_APP1) { if (fseek(fp, len, SEEK_CUR)) exifdie((const char *)strerror(errno)); continue; } exifbuf = (unsigned char *)malloc(len); if (!exifbuf) exifdie((const char *)strerror(errno)); app1 = ftell(fp); rlen = fread(exifbuf, 1, len, fp); if (rlen != len) { fprintf(stderr, "%s: error reading JPEG (length " "mismatch)\n", fname); free(exifbuf); return (1); } gotapp1 = TRUE; t = exifscan(exifbuf, len, FALSE); if (t && t->props) { if (bflag || com) rc = writecom(fp, fname, app1, findprop(t->props, tags, EXIF_T_USERCOMMENT), exifbuf, t->md.btiff); else rc = printcom(fname, findprop(t->props, tags, EXIF_T_USERCOMMENT), t->md.btiff); } else { fprintf(stderr, "%s: couldn't find Exif properties\n", fname); rc = 1; } exiffree(t); free(exifbuf); } if (!gotapp1) { fprintf(stderr, "%s: couldn't find Exif data\n", fname); return (1); } return (rc); }