home *** CD-ROM | disk | FTP | other *** search
Wrap
/* * msdos.c: hterm msdos dependent part * * Author: HIRANO Satoshi * * (C) 1986 Halca Computer Science Laboratory UEC TM * University of Electro Communications * University of Tokyo * * * Edition history: * 1.1 90/02/04 Halca.Hirano creation * 1.2 90/06/17 Halca.Hirano change directory conversion way in getNextFileName() * old: a:dir -> a:/dir * new: a:dir -> a:dir (This is correct on MSDOS.) * * $Header: msdos.cv 1.3 90/07/04 00:31:20 hirano Exp $ */ #ifdef MSDOS #include <stdio.h> #include <string.h> #include <ctype.h> #ifdef __TURBOC__ #include <dir.h> #endif #if !defined(__TURBOC__) || __TURBOC__ >= 0x0200 #include <sys/types.h> #endif #include <sys/stat.h> #include "config.h" #include "hterm.h" #include "option.h" #include "default.h" #include "global.h" #ifdef COMP_MSC static struct find_t fileNext; /* wild card */ #define fn_name name #define fn_attr attrib #endif #ifdef COMP_TURBOC static struct ffblk fileNext; #define _A_NORMAL 0 #define _A_SUBDIR 0x10 #define fn_name ff_name #define fn_attr ff_attrib #endif #define skipSpace(p) {while(*(p)==' '||*(p)=='\t')(p)++;} #define skipText(p) {for (;*(p)&&*(p)!=' '&&*(p)!='\t'&&*(p)!='\n';(p)++);} static void (INTERRUPT FAR *origCritHandler)() = 0; /* original error handler */ static u_char ctrlCCheck; void FAR INTERRUPT critHandler(unsigned int es,unsigned int ds,unsigned int di,unsigned int si,unsigned int bp,unsigned int sp,unsigned int bx,unsigned int dx,unsigned int cx,unsigned int ax); void FAR *allocMem(size) /* * allocate memory, if we couldn't get enough memory return 0 */ long size; { unsigned int seg; void FAR *ptr; if (ALLOCMEM((unsigned int)((size/16L)+1), &seg) != ALLOCOK) { return((void FAR *)NULL); } FP_SEG(ptr) = seg; FP_OFF(ptr) = 0; return(ptr); } void freeMem(ptr) void FAR *ptr; { if (ptr) FREEMEM(FP_SEG(ptr)); } void moveData(to, from, size) void FAR *to; void FAR *from; short size; { MOVEDATA(FP_SEG(from), FP_OFF(from), FP_SEG(to), FP_OFF(to), size); } int getNextFileName(first, fileList, fileName, dirFlag) /* * Get next file in a 'file list' * * fileList should be like 'abc*.* a:def.x c:/*.* e:\slkj\lkj' * * return NO if not found * return YES if found */ int first; /* first or not flag */ char **fileList; /* pointer to file name list pointer */ char **fileName; /* pointer to got file name pointer */ int dirFlag; /* find sub directory also or not */ { char *p, *q, *r, buf2[MAX_FILE_NAME]; static char myDirName[MAX_FILE_NAME] = ""; static char myFileName[MAX_FILE_NAME] = ""; redo: if (first || FINDNEXT(&fileNext) != 0) { /* * first or file not found * * separate current file and prepare next file */ skipSpace(*fileList); q = p = *fileList; /* q = p = first char */ if (*p == '\0' || *p == '\n') /* end of files */ return(NO); skipText(q); r = q; /* r = q = last char + 1 */ skipSpace(q); /* q = next file */ *r = '\0'; /* terminate file name */ if (*q != '\0' && *q != '\n') /* if next file exists */ *fileList = q; /* update next file pointer */ else *fileList = r; /* next file is null */ /* * convert \ char to / char */ toSlash(p); /* * get directory part */ strcpy(buf2, p); p = buf2; q = strrchr(p, (int)'/'); if (q) { /* with directory */ strncpy(myDirName, p, q-p+1); myDirName[q-p+1] = '\0'; } else myDirName[0] = '\0'; /* * OK, find first entry */ if (FINDFIRST(p, (_A_NORMAL|(dirFlag ? _A_SUBDIR : 0)), &fileNext)) { return(NO); /* not found */ } } /* * found something */ if (fileNext.fn_name[0] == '.') { first = NO; goto redo; /* skip current or parent dir */ } sprintf(myFileName, "%s%s", myDirName, fileNext.fn_name); if (fileNext.fn_attr & _A_SUBDIR) strcat(myFileName, "/"); *fileName = myFileName; return(YES); } void changeDirectory() { char drive = (char)0; char *p, *q; #ifdef COMP_MSC int junk = 0; #endif char localFile[MAX_FILE_NAME]; char *err = "No such directory or drive"; int oldMode; if (mode == M_COMM) showPage1(); oldMode = mode; mode = M_SETUP; getcwd(localFile, MAX_FILE_NAME); toSlash(localFile); if (localFile[1] == ':') /* remember current drive */ drive = localFile[0]; if (emacs("Change directory: ", localFile, MAX_FILE_NAME, (E_HELP|E_FILE)) == ERR || localFile[0] == '\0') { if (oldMode == M_COMM) showPage0(); mode = oldMode; return; } /* * change drive if desired */ q = p = localFile; if (*(p+1) == ':') { q = &localFile[2]; if (drive && *p != drive) { #ifdef COMP_MSC _dos_setdrive(toupper(*p) - 'A' + 1, &junk); if (junk == 0) { #endif /* COMP_MSC */ #ifdef COMP_TURBOC if (setdisk(toupper(*p) - 'A' + 1/* by manual */) == ERR) { #endif /* COMP_TURBOC */ /* * CAUTION! setdisk() does not return error code * even if the drive is not ready. * I hate this. * Thus following message will not be used. */ goto error; } } } /* * change directory */ if (*q && strlen(q) != 1) { /* if not root dir */ p = q + strlen(q)-1; if (*p == '/' || *p == '\\') *p = '\0'; /* strip extra '/' */ } if ((*q && chdir(q) == ERR) || getcwd(localFile, MAX_FILE_NAME) == NULL) { error: if (oldMode == M_SETUP) putStatus(err); else { showPage0(); putComment(err, ""); } bell(); mode = oldMode; return; } toSlash(localFile); if (oldMode == M_SETUP) putStatus(localFile); else { showPage0(); putComment(localFile, ""); } mode = oldMode; } /* ** void interrupt far critHandler(es, ds, di, si, bp, sp, bx, dx, cx, ax) * critical error handler */ void interrupt far critHandler(es, ds, di, si, bp, sp, bx, dx, cx, ax) unsigned es, ds, di, si, bp, sp, bx, dx, cx, ax; { ax &= 0xff00; ax |= 0x3; /* system call failure */ } void setCritHandler() /* * set critical error handler */ { origCritHandler = GET_DOSVECT(0x24); SET_DOSVECT(0x24, critHandler); /* * get current CTRL-C check status */ rg.h.ah = 0x33; rg.h.al = 0; /* get code */ int86(0x21, &rg, &rg); ctrlCCheck = rg.h.dl; /* * set new CTRL-C check status */ rg.h.ah = 0x33; rg.h.al = 1; /* get code */ rg.h.dl = 0; /* no CTRL-C check please */ int86(0x21, &rg, &rg); } void restoreCritHandler() { if (origCritHandler) SET_DOSVECT(0x24, origCritHandler); origCritHandler = NULL; /* * set old CTRL-C check status */ rg.h.ah = 0x33; rg.h.al = 1; /* get code */ rg.h.dl = ctrlCCheck; int86(0x21, &rg, &rg); } #endif /* MSDOS */