ex_delete() { #if DISKFLAG char filename[13],pathname[80]; int saveMP; if (midiplexer) saveMP=MPoff(); filename[0]=0; /* uses drive and path from most recent disk function */ if (getfile(pathname,filename,ALL_EXT,DEL_TITL)>0) { if (big_alert(1,CHEKDEL1,filename,CHEKDEL2)==1) { /* delete all files with this pathname (pathname might contain wild card characters) -- error message only for first one */ graf_mouse(BEE_MOUSE); if (Fdelete(pathname)) big_alert(1,BADDEL1,filename,BADDEL2); else while (!Fdelete(pathname)) ; graf_mouse(ARROWMOUSE); } } if (midiplexer&&saveMP) MPon(); #endif } /* end ex_delete() */
static void printFile(char *fileNam) { int fi, fo; #define NBUFF 256 char buff[NBUFF]; long len; fileNam[0] = 'd'; /* force data file */ if ( (fi=Fopen(fileNam, FO_READ)) >= 0 ) { if ( (fo=Fcreate(prDevice, 0)) < 0) fo=Fopen(prDevice, FO_WRITE); /* Fopen may return < 0 for devices like PRN: ! */ if ( fo > -31) { while ( (len=Fread(fi, NBUFF, buff)) > 0) Fwrite(fo, len, buff); Fclose(fo); } else { uiPrintf(uiH, uiPrERR, "cannot open device|>%s<", prDevice); } Fclose(fi); } else { uiPrintf(uiH, uiPrERR, "cannot open dFile"); } Fdelete(fileNam); fileNam[0] = 'c'; /* force control file */ Fdelete(fileNam); }
bool d_cmd(File *f, Cmd *cp) { Fdelete(f, addr.r.p1, addr.r.p2); f->ndot.r.p1 = f->ndot.r.p2 = addr.r.p1; return true; }
bool c_cmd(File *f, Cmd *cp) { Fdelete(f, addr.r.p1, addr.r.p2); f->ndot.r.p1 = f->ndot.r.p2 = addr.r.p2; return append(f, cp, addr.r.p2); }
int x_unlink(const char *file) { #if USE_gemdos return xerror((int) gemdos(65, file)); #else return xerror(Fdelete(file)); #endif }
/* This callback is called when the FD is available for read. The inotify events are read from FD and converted into input_events. */ static void inotify_callback (int fd, void *_) { struct input_event event; Lisp_Object watch_object; int to_read; char *buffer; ssize_t n; size_t i; to_read = 0; if (ioctl (fd, FIONREAD, &to_read) == -1) report_file_notify_error ("Error while retrieving file system events", Qnil); buffer = xmalloc (to_read); n = read (fd, buffer, to_read); if (n < 0) { xfree (buffer); report_file_notify_error ("Error while reading file system events", Qnil); } EVENT_INIT (event); event.kind = FILE_NOTIFY_EVENT; i = 0; while (i < (size_t)n) { struct inotify_event *ev = (struct inotify_event*)&buffer[i]; watch_object = Fassoc (make_watch_descriptor (ev->wd), watch_list); if (!NILP (watch_object)) { event.arg = inotifyevent_to_event (watch_object, ev); /* If event was removed automatically: Drop it from watch list. */ if (ev->mask & IN_IGNORED) watch_list = Fdelete (watch_object, watch_list); if (!NILP (event.arg)) kbd_buffer_store_event (&event); } i += sizeof (*ev) + ev->len; } xfree (buffer); }
void _initReport() { time_t now; struct tm *snow; char txt[20]; if (glb.opt.log) { if (_fexist(glb.opt.LOG_File,NULL)) Fdelete(glb.opt.LOG_File); time(&now); snow=localtime(&now); strftime(txt,20L,"%d/%m/%y %H:%M:%S",snow); sprintf(glb.div.log,"------------------- [%s] -------------------\n",txt); _reportLog(LOG_INI); } }
int __unlink (const char *filename) { char dosnamebuf[PATH_MAX]; int retval; char* dosname = (char*) filename; if (filename == NULL) { __set_errno (EFAULT); return -1; } if (!__libc_unix_names) { dosname = dosnamebuf; _unx2dos (filename, dosname, sizeof (dosnamebuf)); } retval = (int) Fdelete (dosname); if (retval < 0) { struct stat sb; if ((retval == -ENOTDIR) && (_enoent (dosname))) retval = -ENOENT; else if (retval == -EACCES && __quickstat (filename, &sb, 0) == 0) { if (S_ISDIR (sb.st_mode)) retval = -EISDIR; } __set_errno (-retval); return -1; } return 0; }
VOID spol_remv(WORD start) { WORD i; gl_spnxt--; if (gl_spdel[start]) #if GEMDOS Fdelete(ADDR(gl_sppfn[start])); #else dos_delete(ADDR(gl_sppfn[start])); #endif spol_free(gl_sppfn[start]); if ( (start == 0) && (gl_sptab[0]) ) spol_form(); for (i=start; i<(NUM_SPOL - 1); i++) { gl_sppfn[i] = gl_sppfn[i+1]; gl_spdel[i] = gl_spdel[i+1]; gl_sptab[i] = gl_sptab[i+1]; gl_spcnt[i] = gl_spcnt[i+1]; gl_spprn[i] = gl_spprn[i+1]; the_spol[i + F1NAME].ob_state = the_spol[i + F1NAME + 1].ob_state; } gl_sppfn[i] = NULL; gl_spdel[i] = FALSE; gl_sptab[i] = FALSE; gl_spcnt[i] = 0; gl_spprn[i] = 0; the_spol[i + F1NAME].ob_state = NORMAL; spol_bttn(); }
int doact( VOID ) { /* char *saved; */ DMABUFFER *dumb, * saved; REG int ret, retmsg; int error; if ( f_level >= ( COPYMAXDEPTH + 1 ) ) { act_1: do1_alert( STFO8DEE ); return( FALSE ); } /* changed CHAR * to DMABUFFER * in expression below - JTT */ if ( !( dumb = (DMABUFFER *)malloc( (LONG)sizeof( DMABUFFER ) ) ) ) goto act_1; f_level++; retmsg = TRUE; saved = (DMABUFFER *)Fgetdta(); Fsetdta( dumb ); strcat(getall, fixsrc); if ( !( error = Fsfirst(fixsrc, 0x37) ) ) { do { if ( !ch_undo( ) || f_cancel ) /* user want to abort */ { f_abort = 1; retmsg = FALSE; goto mvend; } if (dumb->d_fname[0] != HOME) { if (SUBDIR & dumb->d_fattr) { chkbuf(srclen, srcbuf, &fixsrc); /* check buf size */ addfile(fixsrc, dumb->d_fname); /* add a dir into the path */ strcat(bckslsh, fixsrc); if (opcode != OP_DELETE) { chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ strcat(dumb->d_fname, fixdst); } else goto dorec; updatbox(dumb->d_fname); rechkd1: /* update check the dir existing or not */ switch( chkdf( dumb->d_fname, CPDIR ) ) { case QUIT: f_abort = 1; retmsg = FALSE; goto mvend; case SKIP: backdir(fixsrc); backdir(fixdst); updatnum(NUMDIR, --numdirs); srclen -= FILE_LEN; /* subtract the add lenth */ dstlen -= FILE_LEN; /* subtract the add lenth */ retmsg = TRUE; continue; case FALSE: goto mvend; case CHECK: goto rechkd1; case OK: recrtd: if (Dcreate(fixdst)) { if ( write_save ) goto kk_1; switch( fill_string( fixdst, CNTCRTDR ) ) { case 1: /* skip */ backdir(fixsrc); backdir(fixdst); updatnum(NUMDIR, --numdirs); srclen -= FILE_LEN; /* subtract the add lenth */ dstlen -= FILE_LEN; /* subtract the add lenth */ continue; case 2: /* retry */ goto recrtd; default: /* quit */ f_abort = 1; retmsg = FALSE; goto mvend; }/* switch */ }/* if recrtd */ break; } kk_1: updatnum(NUMDIR, --numdirs); strcat(bckslsh, fixdst); dorec: if (!doact()) /* do the recursion */ { retmsg = FALSE; goto mvend; } if (opcode == OP_COPY) goto clndir; rmstarb(fixsrc); /* after call, -> c:\d1\ */ if (opcode == OP_DELETE) { getlastpath(filestr, fixsrc); updatbox(filestr); } remvd: if (Ddelete(fixsrc)) { /* delete a dir */ if ( ( ret = fill_string( fixsrc, CNTDELD ) ) == 2 ) goto remvd; /* retry */ else if (ret == 3) { /* abort */ f_abort = 1; retmsg = FALSE; goto mvend; } } else /* No error */ upfdesk( fixsrc, (BYTE*)0 ); clndir: backdir(fixsrc); /* back one dir */ srclen -= FILE_LEN; /* subtract the add lenth */ if (opcode == OP_DELETE) updatnum(NUMDIR, --numdirs); else { backdir(fixdst); /* back one dir */ dstlen -= FILE_LEN; /* subtract the add lenth */ } } else { getlastpath(filestr, fixdst); updatname(CPDIR, filestr); /* update the dir */ updatname( CPFILE, dumb->d_fname ); /* update the file */ chkbuf(srclen, srcbuf, &fixsrc); /* check buf size */ addfile(fixsrc, dumb->d_fname); if (opcode != OP_DELETE) { chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ addfile(fixdst, dumb->d_fname); rename = 0; if (!(retmsg = wrfile(dumb->d_fname))) goto mvend; if ((rename) || (retmsg == SKIP)) goto clnfile; } if (opcode == OP_COPY) goto clnfile; remvf: if (ret = (WORD)(Fdelete(fixsrc))) /* rm the file from source */ { /* seek error or drive not ready */ /* if ((ret == E_SEEK) || (ret == EDRVNR)) { retmsg = FALSE; goto mvend; } */ /* retry */ if ( ( ret = fill_string( fixsrc, CNTDELF ) ) == 2 ) goto remvf; else if ( ret == 3 ) { /* abort */ f_abort = 1; retmsg = FALSE; goto mvend; } } else upfdesk( fixsrc, (BYTE*)0 ); clnfile: backdir(fixsrc); /* back one dir */ srclen -= FILE_LEN; /* subtract the add lenth */ if (opcode == OP_DELETE) updatnum(NUMFILE, --numfiles); else { backdir(fixdst); /* back one dir */ dstlen -= FILE_LEN; /* subtract the add lenth */ } } } } while (!Fsnext()); } else { if ( error != EFILNF ) /* if not file not found */ retmsg = FALSE; /* then return error */ } mvend: Fsetdta( saved ); f_level--; free( dumb ); return( retmsg ); }
bool s_cmd(File *f, Cmd *cp) { int i, j, c, n; Posn p1, op, delta = 0; bool didsub = false; n = cp->num; op= -1; compile(cp->re); for(p1 = addr.r.p1; p1<=addr.r.p2 && execute(f, p1, addr.r.p2); ){ if(sel.p[0].p1==sel.p[0].p2){ /* empty match? */ if(sel.p[0].p1==op){ p1++; continue; } p1 = sel.p[0].p2+1; }else p1 = sel.p[0].p2; op = sel.p[0].p2; if(--n>0) continue; Strzero(&genstr); for(i = 0; i<cp->ctext->n; i++) if((c = cp->ctext->s[i])=='\\' && i<cp->ctext->n-1){ c = cp->ctext->s[++i]; if('1'<=c && c<='9') { j = c-'0'; if(sel.p[j].p2-sel.p[j].p1>BLOCKSIZE) error(Elongtag); Fchars(f, genbuf, sel.p[j].p1, sel.p[j].p2); Strinsert(&genstr, tmprstr(genbuf, (sel.p[j].p2-sel.p[j].p1)), genstr.n); }else Straddc(&genstr, c); }else if(c!='&') Straddc(&genstr, c); else{ if(sel.p[0].p2-sel.p[0].p1>BLOCKSIZE) error(Elongrhs); Fchars(f, genbuf, sel.p[0].p1, sel.p[0].p2); Strinsert(&genstr, tmprstr(genbuf, (int)(sel.p[0].p2-sel.p[0].p1)), genstr.n); } if(sel.p[0].p1!=sel.p[0].p2){ Fdelete(f, sel.p[0].p1, sel.p[0].p2); delta-=sel.p[0].p2-sel.p[0].p1; } if(genstr.n){ Finsert(f, &genstr, sel.p[0].p2); delta+=genstr.n; } didsub = true; if(!cp->flag) break; } if(!didsub && nest==0) error(Enosub); f->ndot.r.p1 = addr.r.p1, f->ndot.r.p2 = addr.r.p2+delta; return true; }
void comm_exit(void) { Fdelete(COMM_DEVICE_NAME); }
int __rename(const char *_oldname, const char *_newname) { char oldnamebuf[PATH_MAX], newnamebuf[PATH_MAX]; int rval, r; long xattr; struct stat oldstat; struct stat newstat; char* oldname = (char*) _oldname; char* newname = (char*) _newname; if (_oldname == NULL || _newname == NULL) { __set_errno (EFAULT); return -1; } if (!__libc_unix_names) { oldname = oldnamebuf; newname = newnamebuf; _unx2dos(_oldname, oldname, sizeof (oldnamebuf)); _unx2dos(_newname, newname, sizeof (newnamebuf)); } xattr = __sys_stat (newname, &newstat, 1, 0); if (xattr == 0) xattr = __sys_stat (oldname, &oldstat, 1, 0); if (xattr == 0) { /* Find some errors. FIXME: That should be done conditionally when the kernel can do that. */ /* First check: new is a directory and old isn't. */ if (S_ISDIR (newstat.st_mode) && !S_ISDIR (oldstat.st_mode)) { __set_errno (EISDIR); return -1; } /* Check if newname is a non-empty directory? What will currently happen then? This should result in ENOTEMPTY. */ /* Check for same file. */ if (newstat.st_dev == oldstat.st_dev && newstat.st_ino == oldstat.st_ino) { /* Same file. */ __set_errno (EEXIST); return -1; } } rval = Frename(0, oldname, newname); if (rval == 0) return 0; if (rval != -EXDEV && rval != -ENOENT && rval != -ENOTDIR) { if (!strcmp(newname, oldname)) { /* on inode-less filesystems do at least catch rename("foo", "foo"); */ __set_errno (EEXIST); return -1; } if (!(r = Fdelete (newname))) rval = Frename(0, oldname, newname); /* kludge for kernel versions that suffer from `too much DOS' :) i.e. * still look at the files write permission instead of the directories * even on real filesystems and when running in the MiNT domain: * if it says EACCES and the dest.dir exists try the old link/unlink way... */ if (rval == -EACCES && r != -ENOTDIR) { if (!(rval = Flink (oldname, newname))) { if ((r = Fdelete (oldname)) && r != -ENOENT && r != -ENOTDIR) { (void) Fdelete (newname); } else { rval = 0; /* alright that did it! */ } } else if (rval == -ENOSYS) { rval = -EACCES; /* filesystem doesn't know link()... */ } } } if (rval < 0) { if ((rval == -ENOTDIR) && (xattr != -ENOSYS) && (_enoent(__sys_stat (oldname, &oldstat, 1, 0) ? oldname : newname))) rval = -ENOENT; __set_errno (-rval); rval = -1; } return rval; }
WORD wrfile( char *fstr ) { REG int ret, retmsg; int inhand,outhand; int time[2]; DMABUFFER *mydta, *saved; char *buffer; long copysiz, bufsiz, wrsiz, tmpsiz; int crted,sttime; char buf[2]; crted = 0; sttime = 1; retmsg = TRUE; rename = 0; open: /* open the source file */ if ( ( inhand = (WORD)Fopen(fixsrc, 0) ) < 0 ) { /* seek error or drive not ready */ /* if ( (inhand == E_SEEK) || (inhand == EDRVNR) ) return( FALSE ); */ /* skip */ if ( ( ret = fill_string( fixsrc, CNTOPEN ) ) == 1 ) { updatnum(NUMFILE, --numfiles); return SKIP; } else if (ret == 2) /* retry */ goto open; else /* abort */ goto ww_3; } if ( !ch_undo() || f_cancel ) /* user want to stop */ { Fclose( inhand ); ww_3: f_abort = 1; return( FALSE ); } saved = (DMABUFFER *)Fgetdta(); Fsetdta(mydta=(DMABUFFER *)malloc( (long)sizeof(DMABUFFER))); if ( Fsfirst( fixsrc, 0x37 ) ) { retmsg = SKIP; if ( do1_alert( RDERROR ) == 2 ) /* abort */ { f_abort = 1; retmsg = FALSE; } goto y2; } copysiz = mydta->d_fsize; buffer = (char *)malloc( copysiz ); if ( buffer ) { bufsiz = copysiz; } else { for (bufsiz = 128*1024L; bufsiz >= 1024L; bufsiz /= 2) { if ((buffer = (char *)malloc( bufsiz )) != 0) break; } if (!buffer) goto y2; } Fdatime( &time, inhand, 0 ); /* read the time and date */ rechkd: switch(chkdf(fstr, CPFILE)) { case CHECK: goto rechkd; case SKIP: retmsg = SKIP; goto y1; case QUIT: f_abort = 1; retmsg = FALSE; goto y1; case FALSE: retmsg = FALSE; goto y1; } /* if it is move operation, then try rename first */ if ( opcode == OP_MOVE ) { /* if same name and path, don't do it */ if ( strcmp( fixsrc, fixdst ) ) goto y22; Fclose( inhand ); if ( Frename(0, fixsrc, fixdst) >= 0 ) { inhand = (WORD)Fopen( fixdst, 0 ); if ( !p_timedate ) /* get the new time and date */ { time[0] = Tgettime(); time[1] = Tgetdate(); Fdatime( &time, inhand, 1 ); } y22: rename = 1; goto y1; } else inhand = (WORD)Fopen( fixsrc, 0 ); } while ( copysiz >= 0 ) /* let it passes through for zero file */ { tmpsiz = (copysiz > bufsiz) ? bufsiz : copysiz; if (Fread(inhand, tmpsiz, buffer) < 0) { retmsg = SKIP; if ( crted ) Fdelete( fixdst ); if (do1_alert( RDERROR ) == 2) { /* abort */ f_abort = 1; retmsg = FALSE; } goto y1; /* skip */ } create: if ( sttime ) { sttime = 0; if ((outhand = (WORD)Fcreate(fixdst, mydta->d_fattr&7)) < 0) { if ( ( ret = fill_string( fixdst, CNTCRTFL ) ) == 2 ) goto create; else if (ret == 3) /* abort */ { f_abort = 1; retmsg = FALSE; } else retmsg = SKIP; goto y1; } crted = 1; } if ((wrsiz = Fwrite(outhand, tmpsiz, buffer)) < 0) { retmsg = SKIP; Fclose(outhand); Fdelete(fixdst); if (do1_alert( WRERROR ) == 2) { /* abort */ f_abort = 1; retmsg = FALSE; } goto y1; } /* check if there are sufficent memory */ if (wrsiz != tmpsiz) { /* not sufficent memory ??*/ f_abort = 1; retmsg = FALSE; Fclose(outhand); Fdelete(fixdst); buf[0] = *fixdst; buf[1] = 0; fill_string( buf, STDISKFU ); goto y1; } copysiz -= tmpsiz; if ( !copysiz ) break; } if ( p_timedate ) Fdatime( &time, outhand, 1 ); y0: Fclose(outhand); y1: free(buffer); y2: updatnum(NUMFILE, --numfiles); Fsetdta(saved); y3: Fclose(inhand); free(mydta); if ( ( opcode == OP_MOVE ) && ( retmsg == TRUE ) ) upfdesk( fixsrc, fixdst ); return(retmsg); }
int OnObjectNotifyIBrowser(void *gw, int obj) { GEM_WINDOW *wnd = (GEM_WINDOW *) gw ; WBROWSER *wb = wnd->Extension ; CMD_BROWSER *wdlg = wnd->DlgData->UserData ; OBJECT *bobj = wnd->DlgData->BaseObject ; int i, off_x, off_y ; int code = -1 ; char buf[PATH_MAX] ; switch( obj ) { case IMGB_OPEN : if ( wb->base_path[0] ) sprintf( buf, "%s\\*.*", wb->base_path ) ; else sprintf( buf, "%s\\*.*", config.path_img ) ; if ( file_name( buf, "", buf ) == 1 ) { strcpy( wb->nom, buf ) ; DisplayImg( wnd, 0, 1 ) ; } deselect( bobj, obj ) ; update_nav( wnd ) ; break ; case IMGB_PREVIOUS : if ( wb->fimg_list ) { if ( wb->pos > 0 ) { wb->pos-- ; sprintf( wb->nom, "%s\\%s", wb->base_path, wb->fimg_list[wb->pos] ) ; DisplayImg( wnd, 0, 0 ) ; } } deselect( bobj, obj ) ; update_nav( wnd ) ; break ; case IMGB_NEXT : if ( wb->fimg_list ) { if ( wb->pos < wb->nb_files - 1 ) { wb->pos++ ; sprintf( wb->nom, "%s\\%s", wb->base_path, wb->fimg_list[wb->pos] ) ; DisplayImg( wnd, 0, 0 ) ; } } deselect( bobj, obj ) ; update_nav( wnd ) ; break ; case IMGB_SCALE : deselect( bobj, obj ) ; objc_offset( bobj, obj, &off_x, &off_y ) ; i = popup_formdo( &wdlg->popup_zoom, off_x, off_y, 1 + wb->pzoom_index, 0 ) ; if ( i > 0 ) { wb->pzoom_index = i - 1 ; write_text( bobj, obj, wdlg->popup_zoom[i].ob_spec.free_string ) ; if ( i > 1 ) sscanf( wdlg->popup_zoom[i].ob_spec.free_string, "%d%%", &wb->pczoom ) ; else wb->pczoom = -1 ; adapt_display( wnd ) ; } break ; case IMGB_EDIT : deselect( bobj, obj ) ; if ( wb->fimg_list ) new_edit_vximage( wb ) ; xobjc_draw( wnd->window_handle, bobj, obj ) ; break ; case IMGB_DELETE : deselect( bobj, obj ) ; if ( wb->fimg_list ) { if ( form_interrogation( 2, msg[MSG_CONFIRMDEL] ) == 1 ) { if ( Fdelete( wb-> nom ) ) form_stop( 1, msg[MSG_WRITEERROR] ) ; } } xobjc_draw( wnd->window_handle, bobj, obj ) ; break ; case IMGB_PRINT : deselect( bobj, obj ) ; switch( print_image( &wb->raster, &wb->inf_img ) ) { case PNOGDOS : form_stop(1, msg[MSG_PNOGDOS]) ; break ; case PTIMEOUT : form_stop(1, msg[MSG_PTIMEOUT]) ; break ; case PWRITERR : form_stop(1, msg[MSG_PWRITERR]) ; break ; case PNOHANDLE : form_stop(1, msg[MSG_PNOHANDLE]) ; break ; case PROTERR : form_error(8) ; break ; case PNODRIVER : form_stop(1, msg[MSG_PNODRIVER]) ; break ; } xobjc_draw( wnd->window_handle, bobj, obj ) ; break ; } return( code ) ; }
WORD doright( int flag ) { REG int ret,retmsg; char *temp, buf[14]; retmsg = TRUE; if (opcode == OP_DELETE) { temp = fixdst; fixdst = fixsrc; } if (flag == DTOD) { if (!(retmsg=doact())) goto endright; if (opcode != OP_COPY) retmsg = deleted(); /* rm the first folder */ } else /* file to file */ { getlastpath(filestr, fixdst); backdir(fixdst); getlastpath(buf, fixdst); strcat(filestr, fixdst); updatname(CPFILE, filestr); updatname(CPDIR, buf); if ( opcode != OP_DELETE ) if ((!(retmsg = wrfile(filestr)))||(rename)||(retmsg == SKIP)) goto endright; if (opcode != OP_COPY) { redel: if ( (ret = (WORD)Fdelete(fixsrc)) ) { /* seek error or drive not ready */ /* if ( (ret == E_SEEK) || (ret == EDRVNR) ) { retmsg = FALSE; goto endright; } */ if ( ( ret = fill_string( fixsrc, CNTDELF ) ) == 2 ) goto redel; if ( ret == 1 ) /* skip */ retmsg = SKIP; else { f_abort = 1; retmsg = FALSE; } goto endright; /* error */ } else { if (opcode == OP_DELETE) updatnum(NUMFILE, --numfiles); } } if ( retmsg == TRUE ) { /* if ( opcode == OP_MOVE ) upfdesk( fixsrc, fixdst ); */ if ( opcode == OP_DELETE ) upfdesk( fixsrc, (BYTE*)0 ); } } endright: free(fixsrc); if (opcode == OP_DELETE) free(temp); else free(fixdst); return(retmsg); }
/* * Install hard disk driver. * */ install() { int i, pdev, ldev; int maxsiz; char *s, *d, sdev, dvr[15]; char *lbuf; extern char rootstart, rootend; extern char bootstart, bootend; if ((ldev = glogdev()) < 0) return BAILOUT; /* final warning */ sdev = ldev + 'C'; (instfnl[INSTDRV].ob_spec)->te_ptext = &sdev; instfnl[INSTOK].ob_state = NORMAL; instfnl[INSTCN].ob_state = NORMAL; if (execform(instfnl) != INSTOK) return BAILOUT; /* find maximum sector size on system */ if (!vernum) /* new version of AHDI? */ maxsiz = 512; /* if not, sector size is always 512 bytes */ else maxsiz = *(vernum + 1); /* max sector size kept after version # */ if (!(lbuf = Malloc((long)maxsiz))) { err(nomemory); return ERROR; } /* find which physical unit the chosen logical drive belongs to */ pdev = physdev[ldev]; pdev &= 0x1f; /* mask off extra bits */ /* Remove old driver if there is one */ dvr[0] = sdev; strcpy(&dvr[1], OLDDVR); if (!(Fsfirst(dvr, 0x04))) /* 0x04 = system files */ Fdelete(dvr); /* copy driver to specified unit */ if (copydvr(sdev) != OK) return ERROR; /* read in the root sector */ if (getroot(pdev, lbuf) != 0) { err(rootread); goto argh; } /* copy boot code into root sector */ for (d = lbuf, s = &rootstart, i = &rootend - &rootstart; i--;) *d++ = *s++; /* if gemroot() is not successful, return with error */ if (gemroot(lbuf, 1) != 0) { err(cantinst); goto argh; } /* write installed root sector back to disk */ if (putroot(pdev, lbuf) != 0) { err(rootwrit); goto argh; } /* read boot sector from partition */ if (getboot(ldev, lbuf) != 0) { err(bootread); goto argh; } /* * copy boot code to boot sector, avoiding the BPB information * copy bytes 0..1 for BRA.S to code; * leave bytes 2..$1d unaltered (information for BPB); * copy bytes $1e..$1fe for code. */ s = &bootstart; d = lbuf; *d++ = *s++; *d++ = *s++; d += 0x1c; s += 0x1c; for (i = &bootend-&bootstart-0x1e; i--;) *d++ = *s++; /* make the image executable */ Protobt(lbuf, -1L, -1, 1); /* write the installed boot sector back to disk */ if (putboot(ldev, lbuf) != 0) { err(bootwrit); goto argh; } return; argh: dvr[0] = sdev; strcpy(&dvr[1], DVRNAME); Fdelete(dvr); }
int inmesg(Tmesg type) { Rune buf[1025]; int i, m; short s; long l, l1; File *f; Posn p0, p1; Range r; String *str; char *c; Rune *rp; if(type > TMAX) panic("inmesg"); journal(0, tname[type]); inp = indata; switch(type) { case -1: panic("rcv error"); default: fprint(2, "unknown type %d\n", type); panic("rcv unknown"); case Tversion: tversion = inshort(); journaln(0, tversion); break; case Tstartcmdfile: l = invlong(); /* for 64-bit pointers */ journaln(0, l); Strdupl(&genstr, samname); cmd = newfile(); outTsv(Hbindname, cmd->tag, l); outTs(Hcurrent, cmd->tag); Fsetname(cmd, &genstr); cmd->rasp = emalloc(sizeof(List)); cmd->state = Clean; if(cmdstr.n) { Finsert(cmd, &cmdstr, 0L); Strdelete(&cmdstr, 0L, (Posn)cmdstr.n); } Fupdate(cmd, FALSE, TRUE); outT0(Hunlock); break; case Tcheck: /* go through whichfile to check the tag */ outTs(Hcheck, whichfile(inshort())->tag); break; case Trequest: f = whichfile(inshort()); p0 = inlong(); p1 = p0+inshort(); journaln(0, p0); journaln(0, p1-p0); if(f->state == Unread) panic("Trequest: unread"); if(p1>f->nrunes) p1 = f->nrunes; if(p0>f->nrunes) /* can happen e.g. scrolling during command */ p0 = f->nrunes; if(p0 == p1) { i = 0; r.p1 = r.p2 = p0; } else { r = rdata(f->rasp, p0, p1-p0); i = r.p2-r.p1; if(Fchars(f, buf, r.p1, r.p2)!=i) panic("Trequest 2"); } buf[i]=0; outTslS(Hdata, f->tag, r.p1, tmprstr(buf, i+1)); break; case Torigin: s = inshort(); l = inlong(); l1 = inlong(); journaln(0, l1); lookorigin(whichfile(s), l, l1); break; case Tstartfile: termlocked++; f = whichfile(inshort()); if(!f->rasp) /* this might be a duplicate message */ f->rasp = emalloc(sizeof(List)); current(f); outTsv(Hbindname, f->tag, invlong()); /* for 64-bit pointers */ outTs(Hcurrent, f->tag); journaln(0, f->tag); if(f->state == Unread) load(f); else { if(f->nrunes>0) { rgrow(f->rasp, 0L, f->nrunes); outTsll(Hgrow, f->tag, 0L, f->nrunes); } outTs(Hcheck0, f->tag); moveto(f, f->dot.r); } break; case Tworkfile: i = inshort(); f = whichfile(i); current(f); f->dot.r.p1 = inlong(); f->dot.r.p2 = inlong(); f->tdot = f->dot.r; journaln(0, i); journaln(0, f->dot.r.p1); journaln(0, f->dot.r.p2); break; case Ttype: f = whichfile(inshort()); p0 = inlong(); journaln(0, p0); journal(0, (char*)inp); str = tmpcstr((char*)inp); i = str->n; Finsert(f, str, p0); if(Fupdate(f, FALSE, FALSE)) modnum++; if(f==cmd && p0==f->nrunes-i && i>0 && str->s[i-1]=='\n') { freetmpstr(str); termlocked++; termcommand(); } else freetmpstr(str); f->dot.r.p1 = f->dot.r.p2 = p0+i; /* terminal knows this already */ f->tdot = f->dot.r; break; case Tcut: f = whichfile(inshort()); p0 = inlong(); p1 = inlong(); journaln(0, p0); journaln(0, p1); Fdelete(f, p0, p1); if(Fupdate(f, FALSE, FALSE)) modnum++; f->dot.r.p1 = f->dot.r.p2 = p0; f->tdot = f->dot.r; /* terminal knows the value of dot already */ break; case Tpaste: f = whichfile(inshort()); p0 = inlong(); journaln(0, p0); for(l=0; l<snarfbuf->nrunes; l+=m) { m = snarfbuf->nrunes-l; if(m>BLOCKSIZE) m = BLOCKSIZE; Bread(snarfbuf, genbuf, m, l); Finsert(f, tmprstr(genbuf, m), p0); } if(Fupdate(f, FALSE, TRUE)) modnum++; f->dot.r.p1 = p0; f->dot.r.p2 = p0+snarfbuf->nrunes; f->tdot.p1 = -1; /* force telldot to tell (arguably a BUG) */ telldot(f); outTs(Hunlockfile, f->tag); break; case Tsnarf: i = inshort(); p0 = inlong(); p1 = inlong(); snarf(whichfile(i), p0, p1, snarfbuf, 0); break; case Tstartnewfile: l = invlong(); Strdupl(&genstr, empty); f = newfile(); f->rasp = emalloc(sizeof(List)); outTsv(Hbindname, f->tag, l); Fsetname(f, &genstr); outTs(Hcurrent, f->tag); current(f); load(f); break; case Twrite: termlocked++; i = inshort(); journaln(0, i); f = whichfile(i); addr.r.p1 = 0; addr.r.p2 = f->nrunes; if(f->name.s[0] == 0) error(Enoname); Strduplstr(&genstr, &f->name); writef(f); break; case Tclose: termlocked++; i = inshort(); journaln(0, i); f = whichfile(i); current(f); trytoclose(f); /* if trytoclose fails, will error out */ delete(f); break; case Tlook: f = whichfile(inshort()); termlocked++; p0 = inlong(); p1 = inlong(); journaln(0, p0); journaln(0, p1); setgenstr(f, p0, p1); for(l = 0; l<genstr.n; l++) { i = genstr.s[l]; if(utfrune(".*+?(|)\\[]^$", i)) Strinsert(&genstr, tmpcstr("\\"), l++); } Straddc(&genstr, '\0'); nextmatch(f, &genstr, p1, 1); moveto(f, sel.p[0]); break; case Tsearch: termlocked++; if(curfile == 0) error(Enofile); if(lastpat.s[0] == 0) panic("Tsearch"); nextmatch(curfile, &lastpat, curfile->dot.r.p2, 1); moveto(curfile, sel.p[0]); break; case Tsend: termlocked++; inshort(); /* ignored */ p0 = inlong(); p1 = inlong(); setgenstr(cmd, p0, p1); Bdelete(snarfbuf, (Posn)0, snarfbuf->nrunes); Binsert(snarfbuf, &genstr, (Posn)0); outTl(Hsnarflen, genstr.n); if(genstr.s[genstr.n-1] != '\n') Straddc(&genstr, '\n'); Finsert(cmd, &genstr, cmd->nrunes); Fupdate(cmd, FALSE, TRUE); cmd->dot.r.p1 = cmd->dot.r.p2 = cmd->nrunes; telldot(cmd); termcommand(); break; case Tdclick: f = whichfile(inshort()); p1 = inlong(); doubleclick(f, p1); f->tdot.p1 = f->tdot.p2 = p1; telldot(f); outTs(Hunlockfile, f->tag); break; case Tstartsnarf: if (snarfbuf->nrunes <= 0) { /* nothing to export */ outTs(Hsetsnarf, 0); break; } c = 0; i = 0; m = snarfbuf->nrunes; if(m > 32000) { /* tmprstr stores len in a short */ m = 32000; dprint("?warning: snarf buffer truncated\n"); } rp = malloc(m*sizeof(Rune)); if(rp) { Bread(snarfbuf, rp, m, 0); c = Strtoc(tmprstr(rp, m)); free(rp); i = strlen(c); } outTs(Hsetsnarf, i); if(c) { Write(1, c, i); free(c); } else dprint("snarf buffer too long\n"); break; case Tsetsnarf: m = inshort(); if(m > SNARFSIZE) error(Etoolong); c = malloc(m+1); if(c) { for(i=0; i<m; i++) c[i] = rcvchar(); c[m] = 0; str = tmpcstr(c); free(c); Bdelete(snarfbuf, (Posn)0, snarfbuf->nrunes); Binsert(snarfbuf, str, (Posn)0); freetmpstr(str); outT0(Hunlock); } break; case Tack: waitack = 0; break; case Texit: exits(0); } return TRUE; }