📄 mac.c
字号:
int p; n = 0; do { p = rawgetc();#ifdef O_META if (p & 0x7f) p &= 0x7f; /* was normal ascii char */#endif *buf++ = p; n++; } while (rawchkc() && n <= size); return n;}/* This didn't seem to be any place else */intabs(n)int n;{ return n >= 0 ? n : -n;}/* Simplified stat() routine emulates what is needed most. */intstat(fname,buf)char *fname;struct stat *buf;{ CInfoPBRec p; char *nm; nm = cvt_fnm(fname); CtoPstr(nm); byte_zero(&p,sizeof(CInfoPBRec)); p.hFileInfo.ioCompletion = 0; p.hFileInfo.ioNamePtr = (StringPtr) nm; p.hFileInfo.ioFVersNum = 0; p.hFileInfo.ioFDirIndex = 0; p.hFileInfo.ioVRefNum = cur_vol; p.hFileInfo.ioDirID = cur_dir; switch (PBGetCatInfo(&p,0)) { case noErr: errno = 0; break; case nsvErr: case paramErr: case bdNamErr: case fnfErr: errno = ENOENT; break; case ioErr: errno = EIO; break; default: errno = ENOENT; break; } buf->st_dev = p.hFileInfo.ioVRefNum + 1; /* don't want 0 */ buf->st_ino = p.hFileInfo.ioDirID; buf->st_size = p.hFileInfo.ioFlLgLen; buf->st_mtime = p.hFileInfo.ioFlMdDat; buf->st_mode = (p.hFileInfo.ioFlAttrib & 0x10) ? S_IFDIR : 0; PtoCstr(nm); return errno == 0 ? 0 : -1;}private boolis_dir(fname)char *fname;{ struct stat s; return (stat(fname,&s) == 0) && (s.st_mode & S_IFDIR);}/* Directory related routines. Jove keeps track of the true Volume (disk) number and directory number, and avoids "Working Directory Reference Numbers", which are confusing. */private intgetdir() /* call this only once, during startup. */{ WDPBRec p; p.ioCompletion = 0; p.ioNamePtr = NULL; if (PBHGetVol(&p,0) != noErr) return -1; /* BIG trouble */ cur_vol = p.ioWDVRefNum; cur_dir = p.ioWDDirID; SFSaveDisk = 0 - cur_vol; /* these are for SF dialogs */ CurDirStore = cur_dir; return 0; /* ??? added by DHR */}private intsetdir(vol,dir)int vol;long dir;{ WDPBRec p; p.ioCompletion = 0; p.ioNamePtr = NULL; p.ioVRefNum = vol; p.ioWDDirID = dir; if (PBHSetVol(&p,0) != noErr) return -1; cur_vol = vol; cur_dir = dir; SFSaveDisk = 0 - vol; /* these are for SF dialogs */ CurDirStore = dir;}intchdir(dir)char *dir;{ CInfoPBRec d; WDPBRec p; char *t; char *nm; if (strcmp(dir,"/") == 0) return -1; /* There is no root... */ nm = malloc(strlen(dir) + 2); if (nm == NULL) return -1; strcpy(nm,dir); t = nm; while (*t) { if (*t == '/') *t = ':'; t++; } t = nm; while (*t == ':') t++; /*get rid of initial slashes */ strcat(nm,":"); CtoPstr(t); d.dirInfo.ioCompletion = 0; /* get the directory number */ d.dirInfo.ioNamePtr = (StringPtr) t; d.dirInfo.ioVRefNum = cur_vol; d.dirInfo.ioFDirIndex = 0; d.dirInfo.ioDrDirID = 0; PBGetCatInfo(&d,0); free(nm); if (d.dirInfo.ioResult != noErr || (d.dirInfo.ioFlAttrib & 0x10) == 0 || setdir(d.dirInfo.ioVRefNum,d.dirInfo.ioDrDirID) < 0) return -1; return 0;}/* Scandir returns the number of entries or -1 if the directory cannot be opened or malloc fails. */intjscandir(dir, nmptr, qualify, sorter) /* this function has NOT been debugged */char *dir;char ***nmptr;int (*qualify) proto((char *));int (*sorter) proto((UnivConstPtr, UnivConstPtr));{ CInfoPBRec d; Str255 buf; long DirID; char **ourarray, *nm, *t; unsigned int nalloc = 10, nentries = 0, index = 1; char *getwd(); if (strcmp(dir,"/") == 0) return -1; /* There is no root... */ if (strcmp(dir,".") == 0) dir = getwd(); nm = malloc(strlen(dir) + 2); if (nm == NULL) return -1; strcpy(nm,dir); t = nm; while (*t) { if (*t == '/') *t = ':'; t++; } t = nm; while (*t == ':') t++; /*get rid of initial slashes */ strcat(nm,":"); CtoPstr(t); byte_zero(&d,sizeof(CInfoPBRec)); d.dirInfo.ioCompletion = 0; /* get the directory number */ d.dirInfo.ioNamePtr = (StringPtr) t; d.dirInfo.ioVRefNum = cur_vol; d.dirInfo.ioFDirIndex = 0; d.dirInfo.ioDrDirID = 0; PBGetCatInfo(&d,0); PtoCstr(t); free(nm); if (d.dirInfo.ioResult != noErr || ((d.dirInfo.ioFlAttrib & 0x10) == 0)) return -1; DirID = d.dirInfo.ioDrDirID; ourarray = (char **) emalloc(nalloc * sizeof (char *)); for (;;) { byte_zero(&d,sizeof(CInfoPBRec)); d.dirInfo.ioCompletion = (long) 0; d.dirInfo.ioVRefNum = cur_vol; d.dirInfo.ioFVersNum = 0; d.dirInfo.ioNamePtr = (StringPtr) buf; d.dirInfo.ioFDirIndex = index++; d.dirInfo.ioVRefNum = cur_vol; d.dirInfo.ioDrDirID = DirID; if (PBGetCatInfo(&d,0) != noErr) break; /* we are done, then */ PtoCstr((char *) buf);#ifdef NEVER if (d.dirInfo.ioFlAttrib & 0x10) strcat(buf,"/");#endif if (qualify != NULL && (*qualify)((char *) buf) == 0) continue; if (nentries == nalloc) ourarray = (char **) erealloc((char *) ourarray, (nalloc += 10) * sizeof (char *)); ourarray[nentries] = (char *) emalloc(strlen(buf)+1); null_ncpy(ourarray[nentries], (char *) buf, strlen((char *) buf)); nentries += 1; } if ((nentries + 1) != nalloc) ourarray = (char **) erealloc((char *) ourarray, ((nentries + 1) * sizeof (char *))); if (sorter != NULL) qsort((char *) ourarray, nentries, sizeof (char **), sorter); *nmptr = ourarray; ourarray[nentries] = NULL; /* guaranteed NULL pointer */ return nentries;}voidfreedir(dir, nentries)char ***dir;int nentries;{ char **ptr = *dir; while (nentries--) free(*ptr++);}intalphacomp(a, b)UnivConstPtr a, b;{ return strcmp(*(const char **)a, *(const char **)b);}boolchkCWD(name) /* eventually, may check validity of cwd */char *name;{ return TRUE;}char *getwd(){ CInfoPBRec d; static char ret[255]; char nm[50], tmp[255]; ret[0] = '\0'; d.dirInfo.ioDrDirID = cur_dir; for (;;) { d.dirInfo.ioCompletion = 0; d.dirInfo.ioNamePtr = (StringPtr) nm; d.dirInfo.ioVRefNum = cur_vol; d.dirInfo.ioFDirIndex = -1; PBGetCatInfo(&d,0); if (d.dirInfo.ioResult != noErr) return NULL; PtoCstr((char *) nm); strcpy(tmp,ret); strcpy(ret,"/"); strcat(ret,nm); strcat(ret,tmp); if (d.dirInfo.ioDrDirID == 2) break; /* home directory */ d.dirInfo.ioDrDirID = d.dirInfo.ioDrParID; } return ret;}private char *gethome() /* this will be startup directory */{ static char *ret = NULL; if (ret == NULL) { char *item = getwd(); ret = emalloc(strlen(item)+1); strcpy(ret,item); } return ret;}/* Routines that put up and manipulate the "About Jove" dialog. *//* (ORIGINALLY IN) about_j.c. */#define DLOGNAME "\pABOUT_JDLOG"#define DONE_ITEM 1#define LIST_ITEM 2#define DWIDTH 460 /* there should be an easy way to get this */#define DHEIGHT 240 /* from the resource file! */WindowPtr makedisplay();ListHandle makelist();private WindowPtr theWindow;private ListHandle theList;private Rect theListRect;private EventRecord theEvent;private voidabout_j(){ void do_list(), do_events(); WindowPtr OldWindow; GetPort(&OldWindow); if ((theWindow = makedisplay()) == 0) return; SetPort(theWindow); if (theList = makelist()) { LActivate(1,theList); do_list(); ShowWindow(theWindow); do_events(); } SetPort(OldWindow); LDispose(theList); DisposDialog(theWindow);}private WindowPtrmakedisplay(){ static int dlogid = 0; DialogPtr theDialog; Handle theHandle; Handle theResource; Str255 buf; long itemType; Rect theRect; short dh,dv; /* to center dialog on the screen */ Str255 nostring; if (dlogid == 0) { if ((theResource = GetNamedResource('DLOG',DLOGNAME)) == 0) return (WindowPtr)NULL; itemType = 'DLOG'; GetResInfo(theResource,&dlogid,&itemType,buf); } theDialog = GetNewDialog(dlogid,(long) 0,(WindowPtr) -1); strcpy((char *) nostring,"\p"); ParamText("\pMacJove - Copyright (C) 1986, 1987, 1988 J. Payne, K. Gegenfurtner,", "\pK. Mitchum. Portions (C) THINK Technologies, Inc.",nostring,nostring); dh = screenBits.bounds.left + (screenBits.bounds.right - DWIDTH) / 2; dv = screenBits.bounds.top + (screenBits.bounds.bottom - DHEIGHT) / 2; MoveWindow((WindowPtr)theDialog,dh,dv,0); ShowWindow((WindowPtr)theDialog); GetDItem(theDialog,LIST_ITEM,&itemType,&theHandle,&theRect); theListRect = theRect; theListRect.right -= 15; ((WindowPtr)theDialog)->txFont = FONT; ((WindowPtr)theDialog)->txSize = TEXTSIZE; return (WindowPtr) theDialog;}private voiddo_display() /* draw necessary controls, lines */{ Rect rViewF; /* framing rect for list */ int offset; rViewF = theListRect; rViewF.left--; rViewF.top--; rViewF.right++; rViewF.bottom++; FrameRect(&rViewF); DrawControls(theWindow);}private ListHandlemakelist(){ Point csize; Rect dataBounds, rView; /* list boundaries */ csize.h = csize.v = 0; SetRect(&dataBounds,0,0,1,0); return LNew(&theListRect,&dataBounds,csize,0,theWindow,0,0,0,1);}private voiddo_list(){ void printbind(); int row, col; struct cmd *f; Str255 buf; Point theCell; theCell.h = 0; for (f = commands, row = 0; f->Name; f++, row++) { LAddRow(1,row,theList); theCell.v = row; printbind(f,buf); strcat(buf,f->Name); LSetCell(buf,strlen((char *)buf),theCell,theList); }}private voidprintbind(f,buf)struct cmd *f;char *buf;{ char c; if (f->c_map == 0 || (c = f->c_key) == 0x7f) { strcpy(buf," "); return; } switch(f->c_map) { case F_MAINMAP : strcpy(buf," "); break; case F_PREF1MAP : strcpy(buf," ESC "); break; case F_PREF2MAP : strcpy(buf," ^X "); break; } if (c < ' ') { buf[5] = '^'; /* control char */ c |= 0x40; } else { buf[5] = ' '; } if (c >= 'a' && c<= 'z') c &= 0x5f; buf[6] = c; buf[7] = ' '; buf[8] = '\0';}private pascal BooleanProcFilter(theDialog,event,itemHit)DialogPtr theDialog;EventRecord *event;int *itemHit;{ theEvent = *event; if (theEvent.what == keyDown && theEvent.message & charCodeMask == '\r') { *itemHit = 1; return TRUE; } if (theEvent.what == activateEvt && (WindowPtr) theEvent.message == theWindow) { LDoDraw(1,theList); LActivate(1,theList); } if (theEvent.what == updateEvt && (WindowPtr) theEvent.message == theWindow) { BeginUpdate(theWindow); do_display(); DrawDialog(theWindow); LUpdate((GrafPtr) theWindow->visRgn,theList); EndUpdate(theWindow); } return FALSE;}voiddo_events(){ int item; bool done = NO; Point p; while (!done) { ModalDialog(ProcFilter,&item); switch(item) { case DONE_ITEM : done = YES; /* ??? fall through? -- DHR */ case LIST_ITEM : p = theEvent.where; GlobalToLocal(&p); LClick(p,theEvent.modifiers,theList); break; } }}/* Window and Control related routines. *//* (ORIGINALLY IN) tcon.c. control handler routines for Jove. K. Mitchum 12/86 */#define MINC 0#define MAXC ((int)100)#define INITC 0#define EVENTLIST (mDownMask | keyDownMask )extern longGetCRefCon(); /* omitted in ControlMgr.h */private Point p;private intext; /* mouse down in jove text */private bool wc_adjust proto((int, int, struct wind_config *, int));voiddocontrols() /* called from redisplay routines */{ void MakeScrollBar(), AdjustScrollBar(), drawfluff(); Window *w; int top; w = fwind; top = 0; do { if (w->w_control) HideControl(w->w_control); w = w->w_next; } while (w != fwind); w = fwind; do { w->w_topline = top; if (w->w_control) AdjustScrollBar(w); else MakeScrollBar(w); ShowControl(w->w_control); top += w->w_height; w = w->w_next; } while (w != fwind); Windchange = NO; drawfluff();}voidMakeScrollBar(w) /* set up control */Window *w;{ Rect BarRect; int wheight, wtop; WindowPtr window = theScreen; wheight = w->w_height; wtop = w->w_topline; SetRect(&BarRect,window->portRect.right - SCROLLWIDTH + 1, window->portRect.top -2 + wtop * HEIGHT, window->portRect.right +1, window->portRect.top + ((wheight + wtop) * HEIGHT + 1)); w->w_control = ((char **) NewControl(window,&BarRect,"/psbar",1,INITC, MINC,MAXC,scrollBarProc,w));}voidAdjustScrollBar(w) /* redo existing control */Window *w;{ int wtop,wheight; ControlHandle handle; WindowPtr window; handle = (ControlHandle) w->w_control; wtop = w->w_topline; wheight = w->w_height; window = (*handle)->contrlOwner; if (handle == 0) return; SizeControl(handle,SCROLLWIDTH,wheight * HEIGHT + 1); MoveControl(handle,window->portRect.right - SCROLLWIDTH + 1, window->portRect.top -1 + wtop * HEIGHT);}voidSetScrollBar(handle) /* set value of the bar */ControlHandle handle;{ SetCtlValue(handle,ltoc());}private voiddrawfluff() /* draw controls and dividers */{ Window *w = fwind; DrawControls(theScreen); DrawGrowIcon(theScreen);}voidRemoveScrollBar(w)Window *w;{ if (w->w_control) DisposeControl(w->w_control); w->w_control = 0;}private pascal voidDScroll(control,part)ControlHandle control;int part;{ DownScroll(); redisplay();}private pascal voidUScroll(control,part)ControlHandle control;int part;{ UpScroll(); redisplay();}private pascal voidNPage(control,part)ControlHandle control;int part;{ NextPage(); redisplay();}private pascal voidPPage(control,part)ControlHandle control;int part;{ PrevPage(); redisplay();}private long npos; /* number of lines in buffer */private intltoc() /* calculate ctlvalue for line position */{ register long ipos; register Line *lp = curbuf->b_first; for (npos = 1; lp ; npos++, lp = lp->l_next) { if (lp == curline) ipos = npos; } return (int) ((ipos * MAXC) / npos);}private Line *ctol(ctlv) /* find buffer line for ctlvalue */int ctlv;{extern char *itoa(); register long ipos; register Line *lp = curbuf->b_first; ipos = (npos * ctlv)/MAXC; while (ipos-- && lp->l_next) lp = lp->l_next; return lp;}private voiddoWind(event,window)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -