diff options
Diffstat (limited to 'lib/libftp/utils/uftp.c')
-rw-r--r-- | lib/libftp/utils/uftp.c | 232 |
1 files changed, 116 insertions, 116 deletions
diff --git a/lib/libftp/utils/uftp.c b/lib/libftp/utils/uftp.c index fe64ffd..4c8961f 100644 --- a/lib/libftp/utils/uftp.c +++ b/lib/libftp/utils/uftp.c @@ -37,25 +37,25 @@ main(int argc, char **argv) register char *p1; FILE *fp; String tmp; - - if (setjmp(start)!=0) + + if (setjmp(start)!=0) goto main_loop; - + setsignals(); - - + + FtpSetErrorHandler(&FtpInit,my_error); FtpSetIOHandler(&FtpInit,my_error); - + strcpy(defaultuser,getpwuid(getuid())->pw_name); - + memset(ftp,0,sizeof(FTP*)*NFRAMES); memset(iftp,0,sizeof(LINKINFO)*NFRAMES); - - + + batch(SYSTEMRC); if (access(getrcname(),F_OK)) @@ -69,16 +69,16 @@ main(int argc, char **argv) else { - + fprintf(out,"set timeout 120\nset hash\nset debug\nset bin\n"); fprintf(out,"set prompt \"%%T %%u@%%h:%%d\\> \"\n"); fprintf(out,"alias a alias\na ed ! emacs\nalias tn ! telnet\n"); - + fclose(out); } } - + batch(getrcname()); batch(getaliasrcname()); @@ -88,7 +88,7 @@ main(int argc, char **argv) strcat(tmp,argv[i]); if (i+1!=argc) strcat(tmp," "); } - + if (tmp[0]!=0) { String new; @@ -99,8 +99,8 @@ main(int argc, char **argv) else */ strcpy(new,"open "); - - if (ifalias(tmp)) + + if (ifalias(tmp)) execute (tmp); else strcat(new,tmp), @@ -111,25 +111,25 @@ main(int argc, char **argv) main_loop: setsignals(); - + while (1) { - + setjmp(start); if (lastcmd) exit(0); - + if (isatty(fileno(stdin))) p1=readline(getprompt()); else p1=gets(cmd); - - if (p1==NULL) + + if (p1==NULL) { putchar('\n'); exit(0); } - + strcpy(cmd,p1); if (cmd[0]) add_history(cmd); @@ -144,15 +144,15 @@ INLINE char *findspace(char *str) } - + char *word(char *str, int n) { String new; register char *p1, *p2; register int i; - + strcpy(new,str); - + p1=new; while (isspace(*p1)) p1++; @@ -160,7 +160,7 @@ char *word(char *str, int n) if (n>1 ) for (i=0;i<n-1;i++) /* Skip n-1 words */ { - if ((*p1=='"')||(*p1=='\'')) + if ((*p1=='"')||(*p1=='\'')) { p1=strchr(p1+1,*p1); if (p1==NULL) return ""; @@ -181,7 +181,7 @@ char *word(char *str, int n) *p2=0; return p1+1; } - + if ((p2=findspace(p1)) != NULL ) { *p2=0; @@ -191,8 +191,8 @@ char *word(char *str, int n) } -/* Exacute few command separated by ';' . The character ' must use for mark complex - works*/ +/* Exacute few command separated by ';' . The character ' must use for mark complex + works*/ execute (char *cmd) { @@ -208,13 +208,13 @@ execute (char *cmd) { *p++=*cmd++; while ( *cmd != '\'' && *cmd != 0 ) *p++=*cmd++; - if ( *cmd == 0 ) + if ( *cmd == 0 ) return puts("Unbalanced \', please corrected!\n"); *p++=*cmd; continue; } - - if ( *cmd == ';' ) + + if ( *cmd == ';' ) { *p=0; execute(newcmd); @@ -224,11 +224,11 @@ execute (char *cmd) *p++=*cmd; } - + *p=0; cmd=newcmd; - - if ( *cmd=='\\' ) + + if ( *cmd=='\\' ) cmd++; else { @@ -238,17 +238,17 @@ execute (char *cmd) return execute(new); } - if ( *cmd == '!' ) + if ( *cmd == '!' ) { int pid,_pid; int status; - + if (!(pid=fork())) { execlp((getenv("SHELL")==NULL)?"/bin/sh":(char *)getenv("SHELL"), "shell","-c",cmd+1,NULL); } - + while(1) { _pid=wait(&status); @@ -256,8 +256,8 @@ execute (char *cmd) return; } } - - + + redir(cmd); if (cmd[strlen(cmd)-1]=='&') @@ -271,14 +271,14 @@ execute (char *cmd) strcpy(cmd,tmp); } - + strcpy(w1,word(cmd,1)); strcpy(w2,word(cmd,2)); strcpy(w3,word(cmd,3)); strcpy(w4,word(cmd,4)); strcpy(w5,word(cmd,5)); strcpy(w6,word(cmd,6)); - + return executev(w1,w2,w3,w4,w5,w6); } @@ -286,18 +286,18 @@ executev(ARGS) { CMDS *xcmd=&cmds[0]; String tmp; - + if (isdigit(*w1)) - return + return atoi(w1)<NFRAMES?frame=atoi(w1):0, executev(w2,w3,w4,w5,w6,""); - + while ( xcmd -> cmd != NULL ) { if ( !strcmp(xcmd->cmd,w1) && (xcmd -> func != NULL) ) { int status; - + if ( xcmd -> need && LINK == NULL) return puts("Need connection to server"); iftp[frame].lock=1; unsetsignals(); @@ -308,11 +308,11 @@ executev(ARGS) } xcmd++; } - - + + if (LINK!=NULL && glassmode) return FtpCommand(LINK,cmd,"",0,EOF); - + printf("%s: unknown command\n",w1); fflush(stdout); return -1; @@ -332,7 +332,7 @@ void intr(int sig) newframe(int connecteble) { register int i; - + if (connecteble) for (i=0; i<NFRAMES; i++) if (ftp[i]!=NULL) return frame=i; for (i=0; i<NFRAMES; i++) if (ftp[i]==NULL) return frame=i; @@ -345,7 +345,7 @@ STATUS my_error(FTP *ftp, int code, char *msg) if (code==LQUIT||(ftp==NULL)) log(msg); else FtpLog(ftp->title,msg); - + if ( abs(code) == 530 && (strstr(msg,"anonymous")!=NULL)) { Ftp_reopen(); @@ -358,7 +358,7 @@ char *getrcname() { static String rcpath; struct passwd *pwd=getpwuid(getuid()); - + sprintf(rcpath,"%s/.uftprc",pwd->pw_dir); return rcpath; } @@ -367,7 +367,7 @@ char *getaliasrcname() { static String rcpath; struct passwd *pwd=getpwuid(getuid()); - + sprintf(rcpath,"%s/.uftp_aliases",pwd->pw_dir); return rcpath; } @@ -378,14 +378,14 @@ char *makestr(va_alist) char *p1; va_list args; String new={0}; - + va_start(args); while(1) { p1=va_arg(args,char *); if (p1==NULL) break; - if (*p1!=0) + if (*p1!=0) { if (new[0]!=0) strcat(new," "); strcat(new,p1); @@ -395,7 +395,7 @@ char *makestr(va_alist) return new; } - + #define ADD(str,chr) (*str++=chr,*str=0) INLINE ADDSTR(char **str, char *str1) @@ -409,59 +409,59 @@ char *expandalias(char *str) String new={0},w1={0}; char *p,*p1=new,*args; int dollar=0; - + strcpy(w1,word(str,1)); if ( (p=strchr(str,' '))!=NULL ) args=p+1; else args=""; - - while (a) + + while (a) { if (!strcmp(a->name,w1)) break; a=a->next; } - - if (!a) + + if (!a) return str; - + for ( p=a->str; *p; p++) { - if ( *p != '$' ) + if ( *p != '$' ) { ADD(p1,*p); continue; } - + dollar=1; p++; - - if (isdigit(*p)) + + if (isdigit(*p)) { ADDSTR(&p1,word(str,(*p)-'0'+1)); continue; } - switch (*p) - { - + switch (*p) + { + case '\0': case '$': ADD(p1,'$');continue; case '*': ADDSTR(&p1,args);continue; default: ADD(p1,'$');ADD(p1,*p);continue; } } - - if (!dollar) + + if (!dollar) { ADD(p1,' '); ADDSTR(&p1,args); } *p=0; - + return new; } @@ -481,12 +481,12 @@ ifalias(char *cmd) } return 0; } - + char *getprompt() { - + static String _prompt; String tmp; char *s; @@ -499,22 +499,22 @@ char *getprompt() case '%': switch (*++s) { - - case 'H': + + case 'H': strcat(_prompt,iftp[frame].host); break; - + case 'h': strcpy(tmp,iftp[frame].host); if (strchr(tmp,'.')!=NULL) *(char *)strchr(tmp,'.')=0; strcat(_prompt,tmp); break; - case 'M': + case 'M': gethostname(tmp, sizeof tmp); strcat(_prompt,gethostbyname(tmp)->h_name); break; - + case 'm': gethostname(tmp, sizeof tmp); strcpy(tmp,gethostbyname(tmp)->h_name); @@ -525,7 +525,7 @@ char *getprompt() case 'u': strcat(_prompt,iftp[frame].user); break; - + case 'd': strcat(_prompt,iftp[frame].pwd); break; @@ -543,16 +543,16 @@ char *getprompt() sprintf(tmp,"%d",(LINK==NULL)?0:LINK->port); strcat(_prompt,tmp); break; - + case 't': - + sprintf(tmp,"%d",(LINK==NULL)?0:LINK->timeout.tv_sec); strcat(_prompt,tmp); break; - + case 'T': - + { time_t t=time((time_t *)0); struct tm *lt=localtime(&t); @@ -567,7 +567,7 @@ char *getprompt() sprintf(tmp,"%d",getpid()); strcat(_prompt,tmp); break; - + default: sprintf(tmp,"%%%c",*s); strcat(_prompt,tmp); @@ -576,7 +576,7 @@ char *getprompt() break; case '^': - + ++s; if (isalpha(*s)) { @@ -584,17 +584,17 @@ char *getprompt() strcat(_prompt,tmp); } break; - + default: - + sprintf(tmp,"%c",*s); strcat(_prompt,tmp); break; } return _prompt; } - - + + void noop() { int i; @@ -603,26 +603,26 @@ void noop() if (noopinterval==0) return; - + curtime = time((time_t *)0); - + signal(SIGALRM,noop); - - if (prevtime==0) + + if (prevtime==0) { prevtime=curtime; alarm(noopinterval); return; } - - if (curtime-prevtime < noopinterval) + + if (curtime-prevtime < noopinterval) { alarm(prevtime+noopinterval-curtime); return; } - + printf("Waiting...");fflush(stdout); - + for (i=0;i<NFRAMES;i++) { if ( ftp[i]==NULL || FTPCMD(ftp[i]) == NULL || iftp[i].lock ) @@ -633,7 +633,7 @@ void noop() func3=ftp[i]->IO; ftp[i]->IO=NULL; save = ftp[i]->timeout.tv_sec; ftp[i]->timeout.tv_sec = nooptimeout; - + FtpCommand(ftp[i],"NOOP","",0,EOF); ftp[i]->timeout.tv_sec = save; @@ -642,10 +642,10 @@ void noop() ftp[i]->IO=func1; } - + alarm(noopinterval); prevtime=curtime; - + for (i=0;i<10;i++) putchar(8),putchar(' '),putchar(8); fflush(stdout); } @@ -667,7 +667,7 @@ unsetsignals() int myhash(FTP *ftp,unsigned int chars) { - + if (hashmode) { if (chars==0) return ftp -> counter=0; @@ -676,7 +676,7 @@ int myhash(FTP *ftp,unsigned int chars) fflush(stdout); } - if (!lastcmd) + if (!lastcmd) { noop(); alarm(0); @@ -688,7 +688,7 @@ int myhash(FTP *ftp,unsigned int chars) char *makefilename(char *f1, char *f2) { char *p; - + if (*f2!=0) return f2; @@ -702,21 +702,21 @@ redir(char *cmdline) char *p=cmdline; String result; char *r=result; - + for ( ; *p ; p++ , r++ ) { - if ( *p == '\\' ) + if ( *p == '\\' ) { *r = * ++ p ; continue; } - + if ( *p == '>' || *p == '<' ) { String filename; char *q=filename; char c=*p; - + for (p++;isspace(*p)&&*p!=0;p++); if (*p=='"') { @@ -725,10 +725,10 @@ redir(char *cmdline) } else for (; !isspace(*p) && *p!=0 ; p++,q++) *q=*p; - + *q=0; - - if ( c == '>' ) + + if ( c == '>' ) output(filename); else input(filename); @@ -745,7 +745,7 @@ FILE *is=NULL,*os=NULL; input(char *filename) { - + if ((is=Ftpfopen(filename,"r"))==NULL) { perror(filename); @@ -761,13 +761,13 @@ input(char *filename) output(char *filename) { - + if ((os=Ftpfopen(filename,"w"))==NULL) { perror(filename); return; } - + fflush(stdout); otty=dup(1); close(1); @@ -803,10 +803,10 @@ batch(char *filename) { FILE *fp; String tmp; - + if ((fp=fopen(filename,"r"))!=NULL) { - + while ( fgets(tmp, sizeof tmp, fp) != NULL) { tmp[strlen(tmp)-1]=0; @@ -816,7 +816,7 @@ batch(char *filename) fclose(fp); } } - + |