home *** CD-ROM | disk | FTP | other *** search
- #include <sys/types.h>
- #include <sys/dir.h>
- #include <stdio.h>
- #include <string.h>
- char *zork[300];
- main(argc,argv)
- char **argv;
- {
- int arcnt,level,k;
- char line[133],fnd[133];
- k=chdir(LIBDIR);
- if(k<0)exit(1);
- level=0;
- arcnt=1;
- for(;;){
- if(arcnt>=argc) {
- puts("");
- if(level)printf("Further ");
- puts(
- "Help is available for the following topics:");
- if(listfd(1)<0)exit(1);
- printf("\nHelp on what topic? ");
- gets(line);
- }
- else{
- printf("%s:\n",argv[arcnt]);
- if(listfd(0)<0)exit(1);
- strcpy(line,argv[arcnt]);
- arcnt++;
- }
- if(strlen(line)>0){
- k=completion(line,zork);
- freezork(zork);
- if(!k)continue;
- if(!strcmp(line,"q") ||
- !strcmp(line,"quit") ||
- !strcmp(line,"exit"))exit(0);
- if(line[0]=='!'){
- strcpy(fnd,"man ");
- strcat(fnd,&line[1]);
- system(fnd);
- continue;
- }
- }
- if((k=strlen(line))==0 && level==0)exit(1);
- if(k==0){
- level--;
- chdir("..");
- continue;
- }
- strcpy(fnd,line);
- strcat(line,".txt");
- if(mymode(line)){
- if(listit(line)<0)exit(1);
- }
- if(mymode(fnd)&040000){
- /* printf("\nFurther ");*/
- chdir(fnd);
- level++;
- }
- }
- }
- freezork(p)
- char **p;
- {
- while(*p){
- free(*p);
- *p = (char *)0;
- p++;
- }
- }
- completion(line,p)
- char *line;
- char **p;
- {
- int i,j,count=0;
- char *q;
- q=line;
- if(*q=='!')q++;
- for(i=0;p[i];i++)if(kindex(p[i],q)==0){
- if(strcmp(p[i],q)==0)return 1;
- count++;
- j=i;
- }
- if(count!=1){
- printf("ambiguous\n");
- return 0;
- }
- strcpy(q,p[j]);
- return 1;
-
- }
-
-