char *_GFile_find_program_dir(char *prog) { char *pt, *path, *program_dir=NULL; char filename[2000]; if ( (pt = strrchr(prog,'/'))!=NULL ) program_dir = copyn(prog,pt-prog); else if ( (path = getenv("PATH"))!=NULL ) { while ((pt = strchr(path,':'))!=NULL ) { sprintf(filename,"%.*s/%s", (int)(pt-path), path, prog); /* Under cygwin, applying access to "potrace" will find "potrace.exe" */ /* no need for special check to add ".exe" */ if ( access(filename,1)!= -1 ) { program_dir = copyn(path,pt-path); break; } path = pt+1; } if ( program_dir==NULL ) { sprintf(filename,"%s/%s", path, prog); if ( access(filename,1)!= -1 ) program_dir = copy(path); } } if ( program_dir==NULL ) return( NULL ); GFileGetAbsoluteName(program_dir,filename,sizeof(filename)); gfree(program_dir); program_dir = copy(filename); return( program_dir ); }
static char *decomposeURL(const char *url,char **host, int *port, char **username, char **password) { char *pt, *pt2, *upt, *ppt; char *path; char proto[40]; /* ftp://[user[:password]@]ftpserver[:port]/url-path */ *username = NULL; *password = NULL; *port = -1; pt = strstr(url,"://"); if ( pt==NULL ) { *host = NULL; return( copy(url)); } strncpy(proto,url,pt-url<sizeof(proto)?pt-url:sizeof(proto)); proto[(pt-url)] = '\0'; pt += 3; pt2 = strchr(pt,'/'); if ( pt2==NULL ) { pt2 = pt+strlen(pt); path = copy("/"); } else { path = copy(pt2); } upt = strchr(pt,'@'); if ( upt!=NULL && upt<pt2 ) { ppt = strchr(pt,':'); if ( ppt==NULL ) { *username = copyn(pt,upt-pt); } else { *username = copyn(pt,ppt-pt); *password = copyn(ppt+1,upt-ppt-1); } pt = upt+1; } ppt = strchr(pt,':'); if ( ppt!=NULL && ppt<pt2 ) { char *temp = copyn(ppt+1,pt2-ppt-1), *end; *port = strtol(temp,&end,10); if ( *end!='\0' ) *port = -2; free(temp); pt2 = ppt; } *host = copyn(pt,pt2-pt); if ( *username ) { *password = GIO_PasswordCache(proto,*host,*username,*password); if ( *password==NULL ) { *password = ff_ask_password(_("Password?"),"",_("Enter password for %s@%s"), *username, *host ); *password = GIO_PasswordCache(proto,*host,*username,*password); } } return( path ); }
char *_GFile_find_program_dir(char *prog) { char *pt, *path, *program_dir=NULL; char filename[2000]; #if defined(__MINGW32__) char* pt1 = strrchr(prog, '/'); char* pt2 = strrchr(prog, '\\'); if(pt1<pt2) pt1=pt2; if(pt1) program_dir = copyn(prog, pt1-prog); else if( (path = getenv("PATH")) != NULL ){ char* tmppath = copy(path); path = tmppath; for(;;){ pt1 = strchr(path, ';'); if(pt1) *pt1 = '\0'; sprintf(filename,"%s/%s", path, prog); if ( access(filename,1)!= -1 ) { program_dir = copy(path); break; } if(!pt1) break; path = pt1+1; } free(tmppath); } #else if ( (pt = strrchr(prog,'/'))!=NULL ) program_dir = copyn(prog,pt-prog); else if ( (path = getenv("PATH"))!=NULL ) { while ((pt = strchr(path,':'))!=NULL ) { sprintf(filename,"%.*s/%s", (int)(pt-path), path, prog); /* Under cygwin, applying access to "potrace" will find "potrace.exe" */ /* no need for special check to add ".exe" */ if ( access(filename,1)!= -1 ) { program_dir = copyn(path,pt-path); break; } path = pt+1; } if ( program_dir==NULL ) { sprintf(filename,"%s/%s", path, prog); if ( access(filename,1)!= -1 ) program_dir = copy(path); } } #endif if ( program_dir==NULL ) return( NULL ); GFileGetAbsoluteName(program_dir,filename,sizeof(filename)); free(program_dir); program_dir = copy(filename); return( program_dir ); }
static void GlyphMatrixInit(struct matrixinit *mi,char *glyphstr,SplineFont *sf) { struct matrix_data *md; int k, cnt; char *start, *end; memset(mi,0,sizeof(*mi)); mi->col_cnt = 1; mi->col_init = glyph_ci; md = NULL; for ( k=0; k<2; ++k ) { cnt = 0; if ( glyphstr!=NULL ) for ( start = glyphstr; *start; ) { for ( end=start; *end!='\0' && *end!=' ' && *end!=','; ++end ); if ( k ) { char *str = copyn(start,end-start); md[1*cnt+0].u.md_str = SFNameList2NameUni(sf,str); free(str); } ++cnt; while ( *end==' ' || *end==',' ) ++end; start = end; } if ( md==NULL ) md = gcalloc(1*(cnt+10),sizeof(struct matrix_data)); } mi->matrix_data = md; mi->initial_row_cnt = cnt; }
static void AddToBlock(struct block *block,char *mapname, char *dir) { int i, val, j; int len = strlen(mapname); if ( mapname[len-7]=='.' ) len -= 7; for ( i=0; i<block->cur; ++i ) { if ( (val=strncmp(block->maps[i],mapname,len))==0 ) return; /* Duplicate */ else if ( val>0 ) break; } if ( block->tot==0 ) { block->tot = 10; block->maps = galloc(10*sizeof(char *)); block->dirs = galloc(10*sizeof(char *)); } else if ( block->cur>=block->tot ) { block->tot += 10; block->maps = grealloc(block->maps,block->tot*sizeof(char *)); block->dirs = grealloc(block->dirs,block->tot*sizeof(char *)); } for ( j=block->cur; j>=i; --j ) { block->maps[j+1] = block->maps[j]; block->dirs[j+1] = block->dirs[j]; } block->maps[i] = copyn(mapname,len); block->dirs[i] = dir; ++block->cur; }
static void AppendToErrorWindow(char *buffer) { int i,linecnt; char *pt,*end; if ( buffer[strlen(buffer)-1]=='\n' ) buffer[strlen(buffer)-1] = '\0'; for ( linecnt=1, pt=buffer; (pt=strchr(pt,'\n'))!=NULL; ++linecnt ) ++pt; if ( errdata.cnt + linecnt > MAX_ERR_LINES ) { int off = errdata.cnt + linecnt - MAX_ERR_LINES; for ( i=0; i<off; ++i ) free(errdata.errlines[i]); for ( /*i=off*/; i<errdata.cnt; ++i ) errdata.errlines[i-off] = errdata.errlines[i]; for ( ; i<MAX_ERR_LINES+off ; ++i ) errdata.errlines[i-off] = NULL; errdata.cnt -= off; } for ( i=errdata.cnt, pt=buffer; i<MAX_ERR_LINES; ++i ) { end = strchr(pt,'\n'); if ( end==NULL ) end = pt+strlen(pt); errdata.errlines[i] = copyn(pt,end-pt); pt = end; if ( *pt=='\0' ) { ++i; break; } ++pt; } errdata.cnt = i; errdata.offtop = errdata.cnt - errdata.linecnt; if ( errdata.offtop<0 ) errdata.offtop = 0; Warning_Resize(errdata.gw,NULL,NULL); }
static void IkarusFontname(SplineFont *sf,char *fullname,char *fnam) { char *pt, *tpt; for ( pt=fullname; *pt==' '; ++pt ); if ( *pt=='\0' ) { /* Often the fontname is blank */ pt = strchr(fnam,'.'); if ( pt!=NULL ) *pt='\0'; for ( pt=fnam; *pt==' '; ++pt ); if ( *pt!='\0' ) strcpy(fullname,fnam); else { pt = strrchr(sf->origname,'/'); if ( pt==NULL ) pt = sf->origname-1; strncpy(fullname,pt,80); fullname[80] = '\0'; pt = strchr(fullname,'.'); if ( pt!=NULL ) *pt = '\0'; } } free(sf->fullname); sf->fullname=copy(fullname); free(sf->fontname); sf->fontname=copy(fullname); for ( pt=tpt=sf->fontname; *pt; ++pt ) { if ( isalnum(*pt) || *pt=='-' || *pt=='_' || *pt=='$' ) *tpt++ = *pt; } *tpt = '\0'; if ( (pt=strstr(fullname,"Regu"))!=NULL || (pt=strstr(fullname,"Medi"))!=NULL || (pt=strstr(fullname,"Bold"))!=NULL || (pt=strstr(fullname,"Demi"))!=NULL || (pt=strstr(fullname,"Gras"))!=NULL || (pt=strstr(fullname,"Fett"))!=NULL || (pt=strstr(fullname,"Norm"))!=NULL || (pt=strstr(fullname,"Nord"))!=NULL || (pt=strstr(fullname,"Heav"))!=NULL || (pt=strstr(fullname,"Blac"))!=NULL || (pt=strstr(fullname,"Ligh"))!=NULL || (pt=strstr(fullname,"Thin"))!=NULL ) { free(sf->weight); sf->weight = copyn(pt,4); *pt='\0'; } while ( (pt=strstr(fullname,"Ital"))!=NULL || (pt=strstr(fullname,"Slanted"))!=NULL || (pt=strstr(fullname,"Obli"))!=NULL || (pt=strstr(fullname,"Roma"))!=NULL || (pt=strstr(fullname,"Cond"))!=NULL || (pt=strstr(fullname,"Expa"))!=NULL ) { *pt='\0'; } free(sf->familyname); sf->familyname = copy(fullname); }
static char *GuessFamily(char *fontname) { char *fpt, *pt; int i, j; if ((fpt=strchr(fontname, '-')) != NULL && fpt != fontname) return (copyn(fontname, fpt - fontname)); if ((fpt=strchr(fontname, '.')) != NULL && fpt != fontname) return (copyn(fontname, fpt - fontname)); for (i=0; mods[i] != NULL; ++i) for (j=0; mods[i][j] != NULL; ++j) { pt=strstr(fontname, mods[i][j]); if (pt != NULL && (fpt==NULL || pt < fpt)) fpt=pt; } if (fpt==NULL) return (fastrdup(fontname)); return (copyn(fontname, fpt - fontname)); }
int executable(const Char *dir, const Char *name, int dir_ok) { struct stat stbuf; Char path[MAXPATHLEN + 1]; char *strname; char extension[MAXPATHLEN]; char *ptr, *p2 ; int has_ext = 0; extern void copyn(Char *, const Char *, size_t); extern void catn(Char *, const Char *, int); (void) memset(path, 0, sizeof(path)); if (dir && *dir) { copyn(path, dir, MAXPATHLEN); catn(path, name, MAXPATHLEN); p2 = ptr = short2str(path); while (*ptr++) continue; --ptr; while(ptr > p2) { if (*ptr == '/') break; if (*ptr == '.') { has_ext = 1; StringCbCopy(extension,MAXPATHLEN,ptr+1); break; } ptr--; } if (!has_ext && (nt_stat(p2, &stbuf) == -1)) catn(path, STRdotEXE, MAXPATHLEN); strname = short2str(path); } else strname = short2str(name); return (stat(strname, &stbuf) != -1 && ((dir_ok && S_ISDIR(stbuf.st_mode)) || (S_ISREG(stbuf.st_mode) && (is_nt_executable(strname,extension) || (stbuf.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR))) ))); }
/* Given a postscript array of scalars, what's the ipos'th element? */ char *MMExtractNth(char *pt,int ipos) { int i; char *end; while ( *pt==' ' ) ++pt; if ( *pt=='[' ) ++pt; for ( i=0; *pt!=']' && *pt!='\0'; ++i ) { while ( *pt==' ' ) ++pt; if ( *pt==']' || *pt=='\0' ) return( NULL ); for ( end=pt; *end!=' ' && *end!=']' && *end!='\0'; ++end ); if ( i==ipos ) return( copyn(pt,end-pt)); pt = end; } return( NULL ); }
static void *genutf8data(void *_ed,int32 *len) { int cnt, l; int s_l = errdata.start_l, s_c = errdata.start_c, e_l = errdata.end_l, e_c = errdata.end_c; char *ret, *pt; if ( s_l>e_l ) { s_l = e_l; s_c = e_c; e_l = errdata.start_l; e_c = errdata.start_c; } if ( s_l==-1 ) { *len = 0; return( copy("")); } l = s_l; if ( e_l == l ) { *len = e_c-s_c; return( copyn( errdata.errlines[l]+s_c, e_c-s_c )); } cnt = strlen(errdata.errlines[l]+s_c)+1; for ( ++l; l<e_l; ++l ) cnt += strlen(errdata.errlines[l])+1; cnt += e_c; ret = malloc(cnt+1); strcpy( ret, errdata.errlines[s_l]+s_c ); pt = ret+strlen( ret ); *pt++ = '\n'; for ( l=s_l+1; l<e_l; ++l ) { strcpy(pt,errdata.errlines[l]); pt += strlen(pt); *pt++ = '\n'; } strncpy(pt,errdata.errlines[l],e_c); *len = cnt; return( ret ); }
static void AppendToErrorWindow(char *buffer) { int i,linecnt; char *pt,*end; if ( buffer[strlen(buffer)-1]=='\n' ) buffer[strlen(buffer)-1] = '\0'; for ( linecnt=1, pt=buffer; (pt=strchr(pt,'\n'))!=NULL; ++linecnt ) ++pt; if ( errdata.cnt + linecnt > MAX_ERR_LINES ) { int off = errdata.cnt + linecnt - MAX_ERR_LINES; for ( i=0; i<off; ++i ) free(errdata.errlines[i]); for ( /*i=off*/; i<errdata.cnt; ++i ) errdata.errlines[i-off] = errdata.errlines[i]; for ( ; i<MAX_ERR_LINES+off ; ++i ) errdata.errlines[i-off] = NULL; errdata.cnt -= off; if (( errdata.start_l -= off)< 0 ) errdata.start_l = errdata.start_c = 0; if (( errdata.end_l -= off)< 0 ) errdata.end_l = errdata.start_l = -1; } for ( i=errdata.cnt, pt=buffer; i<MAX_ERR_LINES; ++i ) { end = strchr(pt,'\n'); if ( end==NULL ) end = pt+strlen(pt); errdata.errlines[i] = copyn(pt,end-pt); pt = end; if ( *pt=='\0' ) { ++i; break; } ++pt; } errdata.cnt = i; errdata.offtop = errdata.cnt - errdata.linecnt; if ( errdata.offtop<0 ) errdata.offtop = 0; GScrollBarSetBounds(errdata.vsb,0,errdata.cnt,errdata.linecnt); GScrollBarSetPos(errdata.vsb,errdata.offtop); }
int main(int argc, char **argv) { int i, c, status; char *s; char fortfile[20], *t; char buff[100]; diagfile = stderr; sigivalue = (int) signal(SIGINT, SIG_IGN) & 01; sigqvalue = (int) signal(SIGQUIT, SIG_IGN) & 01; enbint(intrupt); pid = getpid(); crfnames(); loadargs = (char **)calloc(1, (argc + 20) * sizeof(*loadargs)); if (!loadargs) fatal1("out of memory"); loadp = loadargs; --argc; ++argv; while(argc>0 && argv[0][0]=='-' && argv[0][1]!='\0') { for(s = argv[0]+1 ; *s ; ++s) switch(*s) { case 'T': /* use special passes */ switch(*++s) { case '1': fcom = s+1; goto endfor; case 'a': asmname = s+1; goto endfor; case 'l': ldname = s+1; goto endfor; case 'm': macroname = s+1; goto endfor; default: fatal1("bad option -T%c", *s); } break; case 'w': /* F66 warn or no warn */ addarg(ffary, &ffmax, s-1); break; case 'q': /* * Suppress printing of procedure names during * compilation. */ addarg(ffary, &ffmax, s-1); break; copyfflag: case 'u': case 'U': case 'M': case '1': case 'C': addarg(ffary, &ffmax, s-1); break; case 'O': optimflag = YES; addarg(ffary, &ffmax, s-1); break; case 'm': if(s[1] == '4') ++s; macroflag = YES; break; case 'S': saveasmflag = YES; case 'c': loadflag = NO; break; case 'v': verbose = YES; break; case 'd': debugflag = YES; goto copyfflag; case 'p': profileflag = YES; goto copyfflag; case 'o': if(!strcmp(s, "onetrip")) { addarg(ffary, &ffmax, s-1); goto endfor; } oflag = 1; aoutname = *++argv; --argc; break; case 'F': fortonly = YES; loadflag = NO; break; case 'I': if(s[1]=='2' || s[1]=='4' || s[1]=='s') goto copyfflag; fprintf(diagfile, "invalid flag -I%c\n", s[1]); done(1); case 'l': /* letter ell--library */ s[-1] = '-'; *loadp++ = s-1; goto endfor; case 'E': /* EFL flag argument */ while(( *eflagp++ = *++s)) ; *eflagp++ = ' '; goto endfor; case 'R': while(( *rflagp++ = *++s )) ; *rflagp++ = ' '; goto endfor; default: lflag[1] = *s; *loadp++ = copyn(strlen(lflag), lflag); break; } endfor: --argc; ++argv; } if (verbose) fprintf(stderr, xxxvers); if (argc == 0) errorx("No input files"); #ifdef mach_pdp11 if(nofloating) *loadp++ = (profileflag ? NOFLPROF : NOFLFOOT); else #endif for(i = 0 ; i<argc ; ++i) switch(c = dotchar(infname = argv[i]) ) { case 'r': /* Ratfor file */ case 'e': /* EFL file */ if( unreadable(argv[i]) ) break; s = fortfile; t = lastfield(argv[i]); while(( *s++ = *t++)) ; s[-2] = 'f'; if(macroflag) { snprintf(buff, sizeof(buff), "%s %s >%s", macroname, infname, prepfname); if(sys(buff)) { rmf(prepfname); break; } infname = prepfname; } if(c == 'e') snprintf(buff, sizeof(buff), "efl %s %s >%s", eflags, infname, fortfile); else snprintf(buff, sizeof(buff), "ratfor %s %s >%s", rflags, infname, fortfile); status = sys(buff); if(macroflag) rmf(infname); if(status) { loadflag = NO; rmf(fortfile); break; } if( ! fortonly ) { infname = argv[i] = lastfield(argv[i]); *lastchar(infname) = 'f'; if( dofort(argv[i]) ) loadflag = NO; else { if( nodup(t = setdoto(argv[i])) ) *loadp++ = t; rmf(fortfile); } } break; case 'f': /* Fortran file */ case 'F': if( unreadable(argv[i]) ) break; if( dofort(argv[i]) ) loadflag = NO; else if( nodup(t=setdoto(argv[i])) ) *loadp++ = t; break; case 'c': /* C file */ case 's': /* Assembler file */ if( unreadable(argv[i]) ) break; fprintf(diagfile, "%s:\n", argv[i]); snprintf(buff, sizeof(buff), "cc -c %s", argv[i]); if( sys(buff) ) loadflag = NO; else if( nodup(t = setdoto(argv[i])) ) *loadp++ = t; break; case 'o': if( nodup(argv[i]) ) *loadp++ = argv[i]; break; default: if( ! strcmp(argv[i], "-o") ) aoutname = argv[++i]; else *loadp++ = argv[i]; break; } if(loadflag) doload(loadargs, loadp); done(0); return 0; }
/* CCRETVAL */ int Inputl(void) { CCRETVAL retval; KEYCMD cmdnum = 0; unsigned char tch; /* the place where read() goes */ Char ch; int num; /* how many chars we have read at NL */ int expnum; struct varent *crct = inheredoc ? NULL : adrof(STRcorrect); struct varent *autol = adrof(STRautolist); struct varent *matchbeep = adrof(STRmatchbeep); struct varent *imode = adrof(STRinputmode); Char *SaveChar, *CorrChar; int matchval; /* from tenematch() */ int nr_history_exp; /* number of (attempted) history expansions */ COMMAND fn; int curlen = 0; int newlen; int idx; Char *autoexpand; if (!MapsAreInited) /* double extra just in case */ ed_InitMaps(); ClearDisp(); /* reset the display stuff */ ResetInLine(0); /* reset the input pointers */ if (GettingInput) MacroLvl = -1; /* editor was interrupted during input */ if (imode && imode->vec != NULL) { if (!Strcmp(*(imode->vec), STRinsert)) inputmode = MODE_INSERT; else if (!Strcmp(*(imode->vec), STRoverwrite)) inputmode = MODE_REPLACE; } #if defined(FIONREAD) && !defined(OREO) if (!Tty_raw_mode && MacroLvl < 0) { # ifdef SUNOS4 long chrs = 0; # else /* !SUNOS4 */ /* * *Everyone* else has an int, but SunOS wants long! * This breaks where int != long (alpha) */ int chrs = 0; # endif /* SUNOS4 */ (void) ioctl(SHIN, FIONREAD, (ioctl_t) & chrs); if (chrs == 0) { if (Rawmode() < 0) return 0; } } #endif /* FIONREAD && !OREO */ GettingInput = 1; NeedsRedraw = 0; tellwhat = 0; if (RestoreSaved) { copyn(InputBuf, SavedBuf.s, INBUFSIZE);/*FIXBUF*/ LastChar = InputBuf + LastSaved; Cursor = InputBuf + CursSaved; Hist_num = HistSaved; HistSaved = 0; RestoreSaved = 0; } if (HistSaved) { Hist_num = HistSaved; GetHistLine(); HistSaved = 0; } if (Expand) { (void) e_up_hist(0); Expand = 0; } Refresh(); /* print the prompt */ for (num = OKCMD; num == OKCMD;) { /* while still editing this line */ #ifdef DEBUG_EDIT if (Cursor > LastChar) xprintf("Cursor > LastChar\r\n"); if (Cursor < InputBuf) xprintf("Cursor < InputBuf\r\n"); if (Cursor > InputLim) xprintf("Cursor > InputLim\r\n"); if (LastChar > InputLim) xprintf("LastChar > InputLim\r\n"); if (InputLim != &InputBuf[INBUFSIZE - 2])/*FIXBUF*/ xprintf("InputLim != &InputBuf[INBUFSIZE-2]\r\n"); if ((!DoingArg) && (Argument != 1)) xprintf("(!DoingArg) && (Argument != 1)\r\n"); if (CcKeyMap[0] == 0) xprintf("CcKeyMap[0] == 0 (maybe not inited)\r\n"); #endif /* if EOF or error */ if ((num = GetNextCommand(&cmdnum, &ch)) != OKCMD) { break; } if (cmdnum >= NumFuns) {/* BUG CHECK command */ #ifdef DEBUG_EDIT xprintf(CGETS(6, 1, "ERROR: illegal command from key 0%o\r\n"), ch); #endif continue; /* try again */ } /* now do the real command */ retval = (*CcFuncTbl[cmdnum]) (ch); /* save the last command here */ LastCmd = cmdnum; /* make sure fn is initialized */ fn = (retval == CC_COMPLETE_ALL) ? LIST_ALL : LIST; /* use any return value */ switch (retval) { case CC_REFRESH: Refresh(); /*FALLTHROUGH*/ case CC_NORM: /* normal char */ Argument = 1; DoingArg = 0; /*FALLTHROUGH*/ case CC_ARGHACK: /* Suggested by Rich Salz */ /* <*****@*****.**> */ curchoice = -1; curlen = (int) (LastChar - InputBuf); break; /* keep going... */ case CC_EOF: /* end of file typed */ curchoice = -1; curlen = (int) (LastChar - InputBuf); num = 0; break; case CC_WHICH: /* tell what this command does */ tellwhat = 1; *LastChar++ = '\n'; /* for the benifit of CSH */ num = (int) (LastChar - InputBuf); /* number characters read */ break; case CC_NEWLINE: /* normal end of line */ curlen = 0; curchoice = -1; matchval = 1; if (crct && crct->vec != NULL && (!Strcmp(*(crct->vec), STRcmd) || !Strcmp(*(crct->vec), STRall))) { Char *Origin; PastBottom(); Origin = Strsave(InputBuf); cleanup_push(Origin, xfree); SaveChar = LastChar; if (SpellLine(!Strcmp(*(crct->vec), STRcmd)) == 1) { Char *Change; PastBottom(); Change = Strsave(InputBuf); cleanup_push(Change, xfree); *Strchr(Change, '\n') = '\0'; CorrChar = LastChar; /* Save the corrected end */ LastChar = InputBuf; /* Null the current line */ SoundBeep(); printprompt(2, short2str(Change)); cleanup_until(Change); Refresh(); if (xread(SHIN, &tch, 1) < 0) { #ifdef convex /* * need to print error message in case file * is migrated */ if (errno) stderror(ERR_SYSTEM, progname, strerror(errno)); #else cleanup_until(Origin); break; #endif } ch = tch; if (ch == 'y' || ch == ' ') { LastChar = CorrChar; /* Restore the corrected end */ xprintf("%s", CGETS(6, 2, "yes\n")); } else { Strcpy(InputBuf, Origin); LastChar = SaveChar; if (ch == 'e') { xprintf("%s", CGETS(6, 3, "edit\n")); *LastChar-- = '\0'; Cursor = LastChar; printprompt(3, NULL); ClearLines(); ClearDisp(); Refresh(); cleanup_until(Origin); break; } else if (ch == 'a') { xprintf("%s", CGETS(6, 4, "abort\n")); LastChar = InputBuf; /* Null the current line */ Cursor = LastChar; printprompt(0, NULL); Refresh(); cleanup_until(Origin); break; } xprintf("%s", CGETS(6, 5, "no\n")); } flush(); } cleanup_until(Origin); } else if (crct && crct->vec != NULL && !Strcmp(*(crct->vec), STRcomplete)) { if (LastChar > InputBuf && LastChar[-1] == '\n') { LastChar[-1] = '\0'; LastChar--; Cursor = LastChar; } match_unique_match = 1; /* match unique matches */ matchval = CompleteLine(); match_unique_match = 0; curlen = (int) (LastChar - InputBuf); if (matchval != 1) { PastBottom(); } if (matchval == 0) { xprintf("%s", CGETS(6, 6, "No matching command\n")); } else if (matchval == 2) { xprintf("%s", CGETS(6, 7, "Ambiguous command\n")); } if (NeedsRedraw) { ClearLines(); ClearDisp(); NeedsRedraw = 0; } Refresh(); Argument = 1; DoingArg = 0; if (matchval == 1) { PastBottom(); *LastChar++ = '\n'; *LastChar = '\0'; } curlen = (int) (LastChar - InputBuf); } else PastBottom(); if (matchval == 1) { tellwhat = 0; /* just in case */ Hist_num = 0; /* for the history commands */ /* return the number of chars read */ num = (int) (LastChar - InputBuf); /* * For continuation lines, we set the prompt to prompt 2 */ printprompt(1, NULL); } break; case CC_CORRECT: if (tenematch(InputBuf, Cursor - InputBuf, SPELL) < 0) SoundBeep(); /* Beep = No match/ambiguous */ curlen = Repair(); break; case CC_CORRECT_L: if (SpellLine(FALSE) < 0) SoundBeep(); /* Beep = No match/ambiguous */ curlen = Repair(); break; case CC_COMPLETE: case CC_COMPLETE_ALL: case CC_COMPLETE_FWD: case CC_COMPLETE_BACK: switch (retval) { case CC_COMPLETE: fn = RECOGNIZE; curlen = (int) (LastChar - InputBuf); curchoice = -1; rotate = 0; break; case CC_COMPLETE_ALL: fn = RECOGNIZE_ALL; curlen = (int) (LastChar - InputBuf); curchoice = -1; rotate = 0; break; case CC_COMPLETE_FWD: fn = RECOGNIZE_SCROLL; curchoice++; rotate = 1; break; case CC_COMPLETE_BACK: fn = RECOGNIZE_SCROLL; curchoice--; rotate = 1; break; default: abort(); } if (InputBuf[curlen] && rotate) { newlen = (int) (LastChar - InputBuf); for (idx = (int) (Cursor - InputBuf); idx <= newlen; idx++) InputBuf[idx - newlen + curlen] = InputBuf[idx]; LastChar = InputBuf + curlen; Cursor = Cursor - newlen + curlen; } curlen = (int) (LastChar - InputBuf); nr_history_exp = 0; autoexpand = varval(STRautoexpand); if (autoexpand != STRNULL) nr_history_exp += ExpandHistory(); /* try normal expansion only if no history references were found */ if (nr_history_exp == 0 || Strcmp(autoexpand, STRonlyhistory) != 0) { /* * Modified by Martin Boyer ([email protected]): * A separate variable now controls beeping after * completion, independently of autolisting. */ expnum = (int) (Cursor - InputBuf); switch (matchval = tenematch(InputBuf, Cursor-InputBuf, fn)){ case 1: if (non_unique_match && matchbeep && matchbeep->vec != NULL && (Strcmp(*(matchbeep->vec), STRnotunique) == 0)) SoundBeep(); break; case 0: if (matchbeep && matchbeep->vec != NULL) { if (Strcmp(*(matchbeep->vec), STRnomatch) == 0 || Strcmp(*(matchbeep->vec), STRambiguous) == 0 || Strcmp(*(matchbeep->vec), STRnotunique) == 0) SoundBeep(); } else SoundBeep(); break; default: if (matchval < 0) { /* Error from tenematch */ curchoice = -1; SoundBeep(); break; } if (matchbeep && matchbeep->vec != NULL) { if ((Strcmp(*(matchbeep->vec), STRambiguous) == 0 || Strcmp(*(matchbeep->vec), STRnotunique) == 0)) SoundBeep(); } else SoundBeep(); /* * Addition by David C Lawrence <*****@*****.**>: If an * attempted completion is ambiguous, list the choices. * (PWP: this is the best feature addition to tcsh I have * seen in many months.) */ if (autol && autol->vec != NULL && (Strcmp(*(autol->vec), STRambiguous) != 0 || expnum == Cursor - InputBuf)) { if (adrof(STRhighlight) && MarkIsSet) { /* clear highlighting before showing completions */ MarkIsSet = 0; ClearLines(); ClearDisp(); Refresh(); MarkIsSet = 1; } PastBottom(); fn = (retval == CC_COMPLETE_ALL) ? LIST_ALL : LIST; (void) tenematch(InputBuf, Cursor-InputBuf, fn); } break; } } if (NeedsRedraw) { PastBottom(); ClearLines(); ClearDisp(); NeedsRedraw = 0; } Refresh(); Argument = 1; DoingArg = 0; break; case CC_LIST_CHOICES: case CC_LIST_ALL: if (InputBuf[curlen] && rotate) { newlen = (int) (LastChar - InputBuf); for (idx = (int) (Cursor - InputBuf); idx <= newlen; idx++) InputBuf[idx - newlen + curlen] = InputBuf[idx]; LastChar = InputBuf + curlen; Cursor = Cursor - newlen + curlen; } curlen = (int) (LastChar - InputBuf); if (curchoice >= 0) curchoice--; fn = (retval == CC_LIST_ALL) ? LIST_ALL : LIST; /* should catch ^C here... */ if (tenematch(InputBuf, Cursor - InputBuf, fn) < 0) SoundBeep(); Refresh(); Argument = 1; DoingArg = 0; break; case CC_LIST_GLOB: if (tenematch(InputBuf, Cursor - InputBuf, GLOB) < 0) SoundBeep(); curlen = Repair(); break; case CC_EXPAND_GLOB: if (tenematch(InputBuf, Cursor - InputBuf, GLOB_EXPAND) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_NORMALIZE_PATH: if (tenematch(InputBuf, Cursor - InputBuf, PATH_NORMALIZE) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_EXPAND_VARS: if (tenematch(InputBuf, Cursor - InputBuf, VARS_EXPAND) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_NORMALIZE_COMMAND: if (tenematch(InputBuf, Cursor - InputBuf, COMMAND_NORMALIZE) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_HELPME: xputchar('\n'); /* should catch ^C here... */ (void) tenematch(InputBuf, LastChar - InputBuf, PRINT_HELP); Refresh(); Argument = 1; DoingArg = 0; curchoice = -1; curlen = (int) (LastChar - InputBuf); break; case CC_FATAL: /* fatal error, reset to known state */ #ifdef DEBUG_EDIT xprintf(CGETS(7, 8, "*** editor fatal ERROR ***\r\n\n")); #endif /* DEBUG_EDIT */ /* put (real) cursor in a known place */ ClearDisp(); /* reset the display stuff */ ResetInLine(1); /* reset the input pointers */ Refresh(); /* print the prompt again */ Argument = 1; DoingArg = 0; curchoice = -1; curlen = (int) (LastChar - InputBuf); break; case CC_ERROR: default: /* functions we don't know about */ if (adrof(STRhighlight)) { ClearLines(); ClearDisp(); Refresh(); } DoingArg = 0; Argument = 1; SoundBeep(); flush(); curchoice = -1; curlen = (int) (LastChar - InputBuf); break; } } (void) Cookedmode(); /* make sure the tty is set up correctly */ GettingInput = 0; flush(); /* flush any buffered output */ return num; }
copys(char *s) #endif { return( copyn( strlen(s)+1 , s) ); }
char *FVOpenFont(const char *title, const char *def_name, int mult ) { GtkWidget *dialog; char *filename = NULL; GtkFileFilter *filter, *standard, *first; int ans, i,k; if ( mult ) dialog = gtk_file_chooser_dialog_new (title, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, GTK_STOCK_NEW, -100, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); else dialog = gtk_file_chooser_dialog_new (title, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER( dialog ), mult ); g_object_set(G_OBJECT(dialog),"show-hidden",TRUE,NULL); if ( def_name!=NULL ) { char *pt = strrchr( def_name,'/'); if ( pt!=NULL ) { char *dir = copyn(def_name,pt-def_name); gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), dir ); gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER( dialog ), pt+1 ); free(dir); } else gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER( dialog ), def_name ); } standard = first = NULL; for ( i=0; def_font_filters[i].name!=NULL; ++i ) { filter = gtk_file_filter_new(); /* GTK's gtk_file_filter_add_pattern doesn't handled {} wildcards */ /* and I depend on those. So I use my own patern matcher */ gtk_file_filter_add_custom( filter,GTK_FILE_FILTER_FILENAME, gwwv_file_pattern_matcher, (gpointer) def_font_filters[i].wild, NULL); gtk_file_filter_set_name( filter,_(def_font_filters[i].name) ); gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( dialog ), filter ); if ( i==default_font_filter_index ) standard = filter; if ( first==NULL ) first = filter; } if ( user_font_filters!=NULL ) { for ( k=0; user_font_filters[k].name!=NULL; ++i, ++k ) { filter = gtk_file_filter_new(); gtk_file_filter_add_custom( filter,GTK_FILE_FILTER_FILENAME, gwwv_file_pattern_matcher, (gpointer) user_font_filters[k].wild, NULL); gtk_file_filter_set_name( filter,_(user_font_filters[k].name) ); gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( dialog ), filter ); if ( i==default_font_filter_index ) standard = filter; } } if ( standard==NULL ) standard = first; if ( standard!=NULL ) gtk_file_chooser_set_filter( GTK_FILE_CHOOSER( dialog ), standard ); /* New Filter button, Recent files list */ if ( RecentFiles[0]!=NULL ) { } g_signal_connect(G_OBJECT (dialog), "selection-changed", G_CALLBACK (find_fonts_callback), NULL); filename = NULL; ans = gtk_dialog_run (GTK_DIALOG (dialog)); if ( ans == GTK_RESPONSE_ACCEPT) { filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); RememberCurrentFilter(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog))); } else if ( ans == -100 ) FontNew(); /* And return NULL */ gtk_widget_destroy (dialog); return( filename ); }