int flush_nl(void) { if(need_nl) { putchar('\n'); return incline(); } return E_None; }
/* * print_summary: prints dir summary */ int print_summary(unsigned long files , unsigned long bytes) { char buffer[32]; if (optB) return 0; convert(files, buffer); printf("%10s file(s)", buffer); convert(bytes, buffer); printf(" %12s bytes\n", buffer); need_nl = 1; return incline(); }
int print_total(unsigned long files, unsigned long dirs, unsigned long bytes) { int rv; if(optB) return 0; rv = flush_nl(); if(rv == E_None) { printf("\tTotal of %s\n", path); if((rv = incline()) == E_None) return print_summary(files, dirs, bytes); } return rv; }
int dir_print_free(void) { char buffer[32]; union REGS r; if(optB) return 0; /* print number of dirs and bytes free */ r.h.ah = 0x36; r.h.dl = toupper(*path) - 'A' + 1; int86(0x21, &r, &r); convert((unsigned long)r.x.ax * r.x.bx * r.x.cx, buffer); printf(" %15s bytes free\n", buffer); return incline(); }
int print_total (unsigned long files, unsigned long bytes) { int rv; if(optB) return 0; rv = flush_nl(); if(rv == E_None) { printf("Total files listed:\n"); if((rv = incline()) == E_None) return print_summary(files, bytes); } return rv; }
int print_summary(unsigned long files , unsigned long dirs , unsigned long bytes) { char buffer[32]; if (optB) return 0; convert(files, buffer); printf(" %6s file%c", buffer, files == 1 ? ' ' : 's'); convert(bytes, buffer); printf(" %12s byte%c\n", buffer, bytes == 1 ? ' ' : 's'); need_nl = 1; // printf("%9d dirs", dirs); return incline(); }
STATIC char * S_skipspace(pTHX_ register char *s, int incline) { if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { while (s < PL_bufend && SPACE_OR_TAB(*s)) s++; return s; } for (;;) { STRLEN prevlen; SSize_t oldprevlen, oldoldprevlen; SSize_t oldloplen = 0, oldunilen = 0; while (s < PL_bufend && isSPACE(*s)) { if (*s++ == '\n' && ((incline == 2) || (PL_in_eval && !PL_rsfp && !incline))) incline(s); } /* comment */ if (s < PL_bufend && *s == '#') { while (s < PL_bufend && *s != '\n') s++; if (s < PL_bufend) { s++; if (PL_in_eval && !PL_rsfp && !incline) { incline(s); continue; } } } /* also skip leading whitespace on the beginning of a line before deciding * whether or not to recharge the linestr. --rafl */ while (s < PL_bufend && isSPACE(*s)) { if (*s++ == '\n' && PL_in_eval && !PL_rsfp && !incline) incline(s); } /* only continue to recharge the buffer if we're at the end * of the buffer, we're not reading from a source filter, and * we're in normal lexing mode */ if (s < PL_bufend || !PL_rsfp || PL_lex_inwhat || PL_lex_state == LEX_FORMLINE) return s; /* try to recharge the buffer */ if ((s = filter_gets(PL_linestr, PL_rsfp, (prevlen = SvCUR(PL_linestr)))) == Nullch) { /* end of file. Add on the -p or -n magic */ if (PL_minus_p) { sv_setpv(PL_linestr, ";}continue{print or die qq(-p destination: $!\\n);}"); PL_minus_n = PL_minus_p = 0; } else if (PL_minus_n) { sv_setpvn(PL_linestr, ";}", 2); PL_minus_n = 0; } else sv_setpvn(PL_linestr,";", 1); /* reset variables for next time we lex */ PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr); PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); PL_last_lop = PL_last_uni = Nullch; /* In perl versions previous to p4-rawid: //depot/perl@32954 -P * preprocessors were supported here. We don't support -P at all, even * on perls that support it, and use the following chunk from blead * perl. (rafl) */ /* Close the filehandle. Could be from * STDIN, or a regular file. If we were reading code from * STDIN (because the commandline held no -e or filename) * then we don't close it, we reset it so the code can * read from STDIN too. */ if ((PerlIO*)PL_rsfp == PerlIO_stdin()) PerlIO_clearerr(PL_rsfp); else (void)PerlIO_close(PL_rsfp); PL_rsfp = Nullfp; return s; } /* not at end of file, so we only read another line */ /* make corresponding updates to old pointers, for yyerror() */ oldprevlen = PL_oldbufptr - PL_bufend; oldoldprevlen = PL_oldoldbufptr - PL_bufend; if (PL_last_uni) oldunilen = PL_last_uni - PL_bufend; if (PL_last_lop) oldloplen = PL_last_lop - PL_bufend; PL_linestart = PL_bufptr = s + prevlen; PL_bufend = s + SvCUR(PL_linestr); s = PL_bufptr; PL_oldbufptr = s + oldprevlen; PL_oldoldbufptr = s + oldoldprevlen; if (PL_last_uni) PL_last_uni = s + oldunilen; if (PL_last_lop) PL_last_lop = s + oldloplen; if (!incline) incline(s); /* debugger active and we're not compiling the debugger code, * so store the line into the debugger's array of lines */ if (PERLDB_LINE && PL_curstash != PL_debstash) { AV *fileav = CopFILEAV(PL_curcop); if (fileav) { SV * const sv = NEWSV(85,0); sv_upgrade(sv, SVt_PVMG); sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); (void)SvIOK_on(sv); SvIV_set(sv, 0); av_store(fileav,(I32)CopLINE(PL_curcop),sv); } } } }
/* * dir_list * * list the files in the directory */ int dir_list(int pathlen , char *pattern , unsigned long *dcnt , unsigned long *fcnt , unsigned long *bcnt ) { struct ffblk file; unsigned long bytecount = 0; unsigned long filecount = 0; unsigned long dircount = 0; int time; int count; unsigned mode = FA_RDONLY | FA_ARCH | FA_DIREC; int rv = E_None; assert(path); assert(pattern); assert(pathlen >= 2); /* at least root */ /* if the user wants all files listed */ if (optA) mode |= FA_HIDDEN | FA_SYSTEM; /* Search for matching entries */ path[pathlen - 1] = '\\'; strcpy(&path[pathlen], pattern); if (FINDFIRST(path, &file, mode) == 0) { /* moved down here because if we are recursively searching and * don't find any files, we don't want just to print * Directory of C:\SOMEDIR * with nothing else */ if (!optB) { rv = flush_nl(); if(rv == E_None) { /* path without superflous '\' at its end */ if(pathlen == 3) /* root directory */ path[pathlen] = '\0'; /* path := path w/o filename */ else path[pathlen - 1] = '\0'; /* /// Changed to exactly match DOS's formatting. - Ron Cemer */ printf("%sDirectory of %s\n", (optS ? "" : " "), path); if((rv = incline()) == E_None) { putchar('\n'); rv = incline(); } } } /* For counting columns of output */ count = WIDE_COLUMNS; /* if optB && optS the path with trailing backslash is needed, also for optS below do {} while */ strcpy(&path[pathlen - 1], "\\"); if(rv == E_None) do { assert(strlen(file.ff_name) < 13); if (cbreak) rv = E_CBreak; else { if (optL) strlwr(file.ff_name); if (optW) { char buffer[sizeof(file.ff_name) + 3]; if (file.ff_attrib & FA_DIREC) { sprintf(buffer, "[%s]", file.ff_name); dircount++; } else { strcpy(buffer, file.ff_name); filecount++; bytecount += file.ff_fsize; } printf("%-15s", buffer); if (!--count) { /* outputted 5 columns */ putchar('\n'); rv = incline(); count = WIDE_COLUMNS; } } else if (optB) { if (strcmp(file.ff_name, ".") == 0 || strcmp(file.ff_name, "..") == 0) continue; if (optS) fputs(path, stdout); printf("%-13s\n", file.ff_name); if (file.ff_attrib & FA_DIREC) dircount++; else { filecount++; bytecount += file.ff_fsize; } rv = incline(); } else { char buffer[sizeof(long) * 4 + 2], *ext; if (file.ff_name[0] == '.') printf("%-13s", file.ff_name); else { ext = strrchr(file.ff_name, '.'); if (!ext) ext = ""; else *ext++ = '\0'; printf("%-8s %-3s ", file.ff_name, ext); } if (file.ff_attrib & FA_DIREC) { printf("%-14s", " <DIR>"); dircount++; } else { convert(file.ff_fsize, buffer); printf(" %10s ", buffer); bytecount += file.ff_fsize; filecount++; } printf(" %.2d-%.2d-%02d", ((file.ff_fdate >> 5) & 0x000f), (file.ff_fdate & 0x001f), ((file.ff_fdate >> 9) + 80) % 100); time = file.ff_ftime >> 5 >> 6; printf(" %2d:%.2u%c\n", (time == 0 ? 12 : (time <= 12 ? time : time - 12)), ((file.ff_ftime >> 5) & 0x003f), (time <= 11 ? 'a' : 'p')); rv = incline(); } } } while (rv == E_None && FINDNEXT(&file) == 0); } if (rv == E_None && optW && (count != 0)) { putchar('\n'); rv = incline(); } if (rv == E_None) if(filecount || dircount) { /* The code that was here is now in print_summary */ rv = print_summary(filecount, bytecount); } else if(!optS) { error_file_not_found(); rv = E_Other; } if(rv == E_None /* no error */ && optS) { /* do recursively */ /* already set for optB && optS before do {} while above path[pathlen - 1] = '\\'; */ strcpy(&path[pathlen], "*.*"); if (FINDFIRST(path, &file, mode) == 0) do { if((file.ff_attrib & FA_DIREC) != 0 /* is directory */ && strcmp(file.ff_name, ".") != 0 /* not cur dir */ && strcmp(file.ff_name, "..") != 0) { /* not parent dir */ if (optL) strlwr(file.ff_name); strcpy(&path[pathlen], file.ff_name); rv = dir_list(pathlen + strlen(file.ff_name) + 1, pattern , &dircount, &filecount, &bytecount ); } } while (rv == E_None && FINDNEXT(&file) == 0); } *dcnt += dircount; *fcnt += filecount; *bcnt += bytecount; return rv; }
/* * dir_print_header * * print the header for the dir command */ int dir_print_header(int drive) { /* one byte alignment */ #pragma -a- struct media_id { int info_level; int serial1; int serial2; char vol_id[11]; char file_sys[8]; } media; /* standard alignment */ #pragma -a. struct ffblk f; struct SREGS s; union REGS r; int currDisk; int rv; if (cbreak) return E_CBreak; if (optB) return 0; currDisk = getdisk(); if(changeDrive(drive+1) != 0) { setdisk(currDisk); return 1; } /* get the media ID of the drive */ /* Format of disk info: Offset Size Description (Table 01766) 00h WORD 0000h (info level) 02h DWORD disk serial number (binary) 06h 11 BYTEs volume label or "NO NAME " if none present 11h 8 BYTEs (AL=00h only) filesystem type (see #01767) */ r.x.ax = 0x6900; r.x.bx = drive + 1; s.ds = FP_SEG(&media); r.x.dx = FP_OFF(&media); int86x(0x21, &r, &r, &s); /* print drive info */ printf("\n Volume in drive %c", drive + 'A'); if (FINDFIRST("\\*.*", &f, FA_LABEL) == 0) { /* Added to remove "." from labels which are longer than 8 characters (as DOS does). */ char *dotptr = strchr(f.ff_name, '.'); if (dotptr != NULL) if(strlen(dotptr + 1)) memmove(dotptr, dotptr + 1, strlen(dotptr)); else *dotptr = '\0'; /* dot at end of name */ printf(" is %s\n", f.ff_name); } else { printf(" has no label\n"); } setdisk(currDisk); if ((rv = incline()) == 0) { /* print the volume serial number if the return was successful */ if (!r.x.cflag) { printf(" Volume Serial Number is %04X-%04X\n", media.serial2, media.serial1); rv = incline(); } } /* Added to exactly match DOS's formatting. */ if ( (optS) && (rv == 0) ) { printf("\n"); rv = incline(); } return rv; }
/* * dir_print_header * * print the header for the dir command */ int dir_print_header(int drive) { #pragma -a- struct media_id { int info_level; int serial1; int serial2; char vol_id[11]; char file_sys[8]; } media; #pragma -a. struct REGPACK r; struct ffblk f; int disk; int rv; if (cbreak) return E_CBreak; if (optB) return 0; disk = getdisk(); if(changeDrive(drive + 1) != 0) return 1; /* get the media ID of the drive */ /* Format of disk info: Offset Size Description (Table 01766) 00h WORD 0000h (info level) 02h DWORD disk serial number (binary) 06h 11 BYTEs volume label or "NO NAME " if none present 11h 8 BYTEs (AL=00h only) filesystem type (see #01767) */ r.r_ax = 0x6900; r.r_bx = 0; r.r_ds = FP_SEG(&media); r.r_dx = FP_OFF(&media); intr(0x21, &r); /* print drive info */ printf("\n Volume in drive %c", drive + 'A'); if (FINDFIRST("\\*.*", &f, FA_LABEL) == 0) { printf(" is %s\n", f.ff_name); } else { printf(" has no label\n"); } setdisk(disk); if ((rv = incline()) == 0) { /* print the volume serial number if the return was successful */ if (!r.r_flags & 1) { printf(" Volume Serial Number is %04X-%04X\n" , media.serial2, media.serial1); rv = incline(); } } return rv; }