/* BU FUNCTIONS -- BU (4) ****/ /* Displaying and Collecting File Attributes */ #include /* defines to TRY to help code comprehension */ #define ASK_EACH (query) #define GEN_PATT (!(query)) #define FIRST_RUN (first_go) #define OTHER_RUNS (!(first_go)) #define NEXT_T ++t_cnt #define INVALID_ATT (attest == ERROR) #define LEAVE_IT 0 #define SET_A_BIT 1 #define RESET_BIT 2 #define UP '\013' /*(YOUR TERMINAL ^K ) ? LEAVE : SELF-SET */ #define TAB '\011' get_atts(fcb_in,first_go) /* query is a global */ char fcb_in[12]; int first_go; { /* start get_atts */ char options[29], /* storage for valid cmds look-up */ attbuf[4], /* store for chars in attr. name */ in_chr, *in_chrptr; int t_cnt, attest, /* string posn after options search */ i, changes; changes = NULL; in_chrptr = &in_chr; strcpy(options,"---$R/O$R/W$SYS$DIR$ARC$NRC$"); if(ASK_EACH) t_cnt = 5; /* force false value to skip while loop if necess */ else t_cnt = NULL; if (! (GEN_PATT && OTHER_RUNS) ) { setmem(&attpat[0],3,NULL); t_cnt = askatts(fcb_in,t_cnt,first_go); /* may return 5 skip value */ } while (t_cnt < 3) { /*while t_cnt */ attest = ERROR; while (INVALID_ATT && ( (GEN_PATT && FIRST_RUN) || ASK_EACH ) ) { /*while inval&&genpat||askeach */ setmem(&attbuf[0],4,NULL); i = 0; while (i < 3) { /* while i<3 */ in_chr = toupper(getchar()); if(isalpha(in_chr)) { attbuf[i] =in_chr; ++i; } /* endif attestisalpha */ else if( (in_chr == '-') || (in_chr == '/') ) { attbuf[i] = in_chr; ++i; } else if(in_chr == 0x03) { exit(0); } else { puts("\007"); /* Main error routine */ if (in_chr == '\n') /* fix up if offline */ putchar(UP); t_cnt = (askatts(fcb_in,t_cnt,first_go)); i = 0; /* means start new 3 chars */ } /* endifs and elseifs */ } /* enddo while i < 3 */ putchar(' '); attest = (index(options,attbuf)); if INVALID_ATT { puts("\007\007\007"); t_cnt = (askatts(fcb_in,t_cnt,first_go)); } } /* enddo while inval&all&1st||each */ if( (GEN_PATT && FIRST_RUN) || ASK_EACH) { if (attest== LEAVE_IT) attpat[t_cnt] = LEAVE_IT; else attpat[t_cnt] =((attest/4) - (t_cnt*2)); } switch(attpat[t_cnt]) { case LEAVE_IT : NEXT_T; break; case SET_A_BIT : if(ASK_EACH || OTHER_RUNS) fcb_in[9 + t_cnt] |= 0x80; NEXT_T; break; case RESET_BIT : if(ASK_EACH || OTHER_RUNS) fcb_in[9 + t_cnt] &= 0x7f; NEXT_T; break; default: puts("\007\007"); t_cnt =(askatts(fcb_in,t_cnt,first_go)); break; } /* end switch */ } /* enddo while t_cnt<3 */ if( (GEN_PATT && FIRST_RUN) || (ASK_EACH && t_cnt < 5) ) { for (t_cnt = 0; t_cnt < 3; t_cnt++) changes += attpat[t_cnt]; } if( (GEN_PATT && OTHER_RUNS) || (ASK_EACH && t_cnt < 5)) { printf(" --> "); showatts(fcb_in); } puts("\n"); return ( (t_cnt == 5) ? NULL : changes); } /*******************************************************************/ /* routine to request attribute setting input pattern */ /* returns a desired value for t_cnt */ askatts(fcb_in,t_cnt,first_go) /* query is a global */ char fcb_in[12]; int t_cnt; { char c; int t_b, i; if( GEN_PATT && FIRST_RUN ) /* first time for pattern */ { printf("\015 Enter PATTERN required --> R/W DIR NRC "); } else { printf("\015 %2d ",cur_user); printf(" %s set to ",fcb_in+1); showatts(fcb_in); if(t_cnt == 5) { printf("Change ? [Y/N] "); c = toupper(getchar()); printf("\b%c",c); if(c == 'Y') { puts("es "); t_cnt=0; for (i = 0; i < 19; i++) putchar('\b'); } else puts("=No"); } /* endifelse t_cnt ==5 */ } /* endifelse genpatt */ if(t_cnt != 5) { t_b = 3 - t_cnt; /* back cursor up to att for entry */ while (t_b > 0) { puts("\b\b\b\b"); t_b--; } } return ( (GEN_PATT && FIRST_RUN) ? NULL : t_cnt); } /********************************************************************/ /* Display setting of the file attributes */ showatts(fcb_in) char fcb_in[12]; { if(!(fcb_in[9] & 0x80) ) printf(" R/W"); else printf(" R/O"); if (!(fcb_in[10] & 0x80) ) printf(" DIR"); else printf(" SYS"); if(!(fcb_in[11] & 0x80) ) printf(" NRC "); else printf(" ARC "); } /* end showatts routine */ /**********************************************************************/ usage_att(query,in_fcb,first_go) /* query is a global */ char in_fcb[12]; { char attpat[3]; printf(" ** CHANGE ATTRIBUTES REQUEST **\n\n"); printf(" Enter ^C to abort -- otherwise,\n"); if (query) printf(" when prompted after each filename,\n"); printf(" enter PATTERN for attributes required\n\n"); printf(" Where R/O = set to READ ONLY\n"); printf(" R/W = set to READ-WRITE\n"); printf(" DIR = set visible in DIRECTORY\n"); printf(" SYS = set invisible (ie, SYSTEM)\n"); printf(" ARC = set ARCHIVE bit of file\n"); printf(" NRC = reset ARCHIVE bit\n"); printf(" or --- = leave attribute as is.\n\n"); printf(" e.g., R/W --- ARC = reset t1', leave t2' as is, set t3'\n\n"); if(!(query)) { setmem(&attpat[0],3,NULL); if( !( get_atts(in_fcb,first_go) ) ) { printf("No attribute changes requested.\n"); reset(); exit(0); } /* endif not changes */ } /* endif not query*/ } /* End BU4.C (bu vers 2.0) revised 7 May 1986 -- Peter G. Martin */