hA@%[ #A Z # zwZ # {Z #*+ |Z #,-.d}Z #/0Z #12Z #3Z #45678$Z #9:;<=>?AZ #DES Z #FGHZ #IJ Z #KLMNZ #O Z #PQRSZ #Th Z #UVWA9\ #XA\ #Y4i[ #Z[ #[\]^_`acʯ[ #][ #}4\ #m6\ #7\ # !]:\ #"#p\ #$%&'()*rt\ #+,-./01-x\ #2345 |\ #678~\ #9\ #:\ #;<6\ #=>. \ #?@A\ #BC\ #DE\ #FG\ #HIJp \ #KLM\ #N"\ #Ou\ #Pu\ #Q \ #RST}\ #UV\ #WXYZ[\\ #]^_`a\ #b\ #c...commandslib...sort.csplit.cstty.csu.csum.csync.c tail.c tar.c tee.c time.c touch.ctr.cumount.cuniq.cupdate.cwc.c/* sort - sort a file of lines Author: Michiel Huisjes */ /* SYNOPSIS: * sort [-funbirdcmt'x'] [+beg_pos[opts] [-end_pos]] [-o outfile] [file] .. * * [opts] can be any of * -f : Fold upper case to lower. * -n : Sort to numeric value (optional decimal point) implies -b * -b : Skip leading blanks * -i : Ignore chars outside ASCII range (040 - 0176) * -r : Reverse the sense of comparisons. * -d : Sort to dictionary order. Only letters, digits, comma's and points * are compared. * If any of these flags are used in [opts], then they override all global * ordering for this field. * * I/O control flags are: * -u : Print uniq lines only once. * -c : Check if files are sorted in order. * -m : Merge already sorted files. * -o outfile : Name of output file. (Can be one of the input files). * Default is stdout. * - : Take stdin as input. * * Fields: * -t'x' : Field separating character is 'x' * +a.b : Start comparing at field 'a' with offset 'b'. A missing 'b' is * taken to be 0. * -a.b : Stop comparing at field 'a' with offset 'b'. A missing 'b' is * taken to be 0. * A missing -a.b means the rest of the line. */ #include "stat.h" #include "signal.h" #define OPEN_FILES 16 /* Nr of open files per process */ #define MEMORY_SIZE (20 * 1024) /* Total mem_size */ #define LINE_SIZE (1024 >> 1) /* Max length of a line */ #define IO_SIZE (2 * 1024) /* Size of buffered output */ #define STD_OUT 1 /* Fd of terminal */ /* Return status of functions */ #define OK 0 #define ERROR -1 #define NIL_PTR ((char *) 0) /* Compare return values */ #define LOWER -1 #define SAME 0 #define HIGHER 1 /* * Table definitions. */ #define DICT 0x001 /* Alpha, numeric, letters and . */ #define ASCII 0x002 /* All between ' ' and '~' */ #define BLANK 0x004 /* ' ' and '\t' */ #define DIGIT 0x008 /* 0-9 */ #define UPPER 0x010 /* A-Z */ typedef enum { /* Boolean types */ FALSE = 0, TRUE } BOOL; typedef struct { int fd; /* Fd of file */ char *buffer; /* Buffer for reads */ int read_chars; /* Nr of chars actually read in buffer*/ int cnt; /* Nr of chars taken out of buffer */ char *line; /* Contains line currently used */ } MERGE ; #define NIL_MERGE ((MERGE *) 0) MERGE merge_f[OPEN_FILES]; /* Merge structs */ int buf_size; /* Size of core available for each struct */ #define FIELDS_LIMIT 10 /* 1 global + 9 user */ #define GLOBAL 0 typedef struct { int beg_field, beg_pos; /* Begin field + offset */ int end_field, end_pos; /* End field + offset. ERROR == EOLN */ BOOL reverse; /* TRUE if rev. flag set on this field*/ BOOL blanks; BOOL dictionary; BOOL fold_case; BOOL ascii; BOOL numeric; } FIELD; /* Field declarations. A total of FILEDS_LIMIT is allowed */ FIELD fields[FIELDS_LIMIT]; int field_cnt; /* Nr of field actually assigned */ /* Various output control flags */ BOOL check = FALSE; BOOL only_merge = FALSE; BOOL uniq = FALSE; char *mem_top; /* Mem_top points to lowest pos of memory. */ char *cur_pos; /* First free position in mem */ char **line_table; /* Pointer to the internal line table */ BOOL in_core = TRUE; /* Set if input cannot all be sorted in core */ /* Place where temp_files should be made */ char temp_files[] = "/tmp/sort.XXXXX.XX"; char *output_file; /* Name of output file */ int out_fd; /* Fd to output file (could be STD_OUT) */ char out_buffer[IO_SIZE]; /* For buffered output */ char **argptr; /* Pointer to argv structure */ int args_offset; /* Nr of args spilled on options */ int args_limit; /* Nr of args given */ char separator; /* Char that separates fields */ int nr_of_files = 0; /* Nr_of_files to be merged */ int disabled; /* Nr of files done */ char USAGE[] = "Usage: sort [-funbirdcmt'x'] [+beg_pos [-end_pos]] [-o outfile] [file] .."; /* Forward declarations */ char *file_name (), *skip_fields (); MERGE *skip_lines (), *print (); extern char *msbrk (), *mbrk (); /* * Table of all chars. 0 means no special meaning. */ char table[256] = { /* '^@' to space */ 0, 0, 0, 0, 0, 0, 0, 0, 0, BLANK | DICT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* space to '0' */ BLANK | DICT | ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* '0' until '9' */ DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, DIGIT | DICT | ASCII, /* ASCII from ':' to '@' */ ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* Upper case letters 'A' to 'Z' */ UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, UPPER | DICT | ASCII, /* ASCII from '[' to '`' */ ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, /* Lower case letters from 'a' to 'z' */ DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, DICT | ASCII, /* ASCII from '{' to '~' */ ASCII, ASCII, ASCII, ASCII, /* Stuff from -1 to -177 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* * Get_opts () assigns the options into the field structure as described in ptr. * This field structure could be the GLOBAL one. */ get_opts(ptr, field) register char *ptr; register FIELD *field; { switch (*ptr) { case 'b' : /* Skip leading blanks */ field->blanks = TRUE; break; case 'd' : /* Dictionary order */ field->dictionary = TRUE; break; case 'f' : /* Fold upper case to lower */ field->fold_case = TRUE; break; case 'i' : /* Skip chars outside ' ' '~' */ field->ascii = TRUE; break; case 'n' : /* Sort on numeric */ field->numeric = TRUE; field->blanks = TRUE; break; case 'r' : /* Reverse comparisons */ field->reverse = TRUE; break; default : /* Illegal options */ error(TRUE, USAGE, NIL_PTR); } } /* * Atoi() converts a string to an int. */ atoi(ptr) register char *ptr; { register int num = 0; /* Accumulator */ while (table[*ptr] & DIGIT) num = num * 10 + *ptr++ - '0'; return num; } /* * New_field () assigns a new field as described by the arguments. * A field description is of the form: +a.b[opts] -c.d, where b and d, as well * as -c.d and [opts] are optional. Nr before digit is field nr. Nr after digit * is offset from field. */ new_field(field, offset, beg_fl) register FIELD *field; /* Field to assign */ int *offset; /* Offset in argv structure */ BOOL beg_fl; /* Assign beg or end of field */ { register char *ptr; ptr = argptr[*offset]; *offset += 1; /* Incr offset to next arg */ ptr++; if (beg_fl) field->beg_field = atoi(ptr); /* Assign int of first field */ else field->end_field = atoi(ptr); while (table[*ptr] & DIGIT) /* Skip all digits */ ptr++; if (*ptr == '.') { /* Check for offset */ ptr++; if (beg_fl) field->beg_pos = atoi(ptr); else field->end_pos = atoi(ptr); while (table[*ptr] & DIGIT) /* Skip digits */ ptr++; } if (beg_fl) { while (*ptr != '\0') /* Check options after field */ get_opts(ptr++, field); } if (beg_fl) { /* Ch !"#$%&'()eck for end pos */ ptr = argptr[*offset]; if (*ptr == '-' && table[*(ptr + 1)] & DIGIT) { new_field(field, offset, FALSE); if (field->beg_field > field->end_field) error(TRUE, "End field is before start field!",NIL_PTR); } else /* No end pos. */ field->end_field = ERROR; } } catch() { register short i; signal (SIGINT, SIG_IGN); only_merge = FALSE; for (i = 0; i < 26; i++) (void) unlink (file_name (i)); exit (2); } main(argc, argv) int argc; char *argv[]; { int arg_count = 1; /* Offset in argv */ struct stat st; register char *ptr; /* Ptr to *argv in use */ register int fd; int pid, pow; argptr = argv; cur_pos = mem_top = msbrk(MEMORY_SIZE); /* Find lowest mem. location */ while (argc > 1 && ((ptr = argv[arg_count])[0] == '-' || *ptr == '+')) { if (*ptr == '-' && *(ptr + 1) == '\0') /* "-" means stdin */ break; if (*ptr == '+') { /* Assign field. */ if (++field_cnt == FIELDS_LIMIT) error(TRUE, "Too many fields", NIL_PTR); new_field (&fields[field_cnt], &arg_count, TRUE); } else { /* Get output options */ while (*++ptr) { switch (*ptr) { case 'c' : /* Only check file */ check = TRUE; break; case 'm' : /* Merge (sorted) files */ only_merge = TRUE; break; case 'u' : /* Only give uniq lines */ uniq = TRUE; break; case 'o' : /* Name of output file */ output_file = argv[++arg_count]; break; case 't' : /* Field separator */ ptr++; separator = *ptr; break; default : /* Sort options */ get_opts(ptr, &fields[GLOBAL]); } } arg_count++; } } for (fd = 1; fd <= field_cnt; fd++) adjust_options (&fields[fd]); /* Create name of tem_files 'sort.pid.aa' */ ptr = &temp_files[10]; pid = getpid(); pow = 10000; while (pow != 0) { *ptr++ = pid / pow + '0'; pid %= pow; pow /= 10; } signal (SIGINT, catch); /* Only merge files. Set up */ if (only_merge) { args_limit = args_offset = arg_count; while (argv[args_limit] != NIL_PTR) args_limit++; /* Find nr of args */ files_merge(args_limit - arg_count); exit (0); } if (arg_count == argc) { /* No args left. Use stdin */ if (check) check_file(0, NIL_PTR); else get_file(0, 0L); } else while (arg_count < argc) { /* Sort or check args */ if (strcmp(argv[arg_count], "-") == 0) fd = 0; else if (stat(argv[arg_count], &st) < 0) { error(FALSE, "Cannot find ", argv[arg_count++]); continue; } /* Open files */ else if ((fd = open(argv[arg_count], 0)) < 0) { error(FALSE, "Cannot open ", argv[arg_count++]); continue; } if (check) check_file(fd, argv[arg_count]); else /* Get_file reads whole file */ get_file(fd, st.st_size); arg_count++; } if (check) exit(0); sort(); /* Sort whatever is left */ if (nr_of_files == 1) /* Only one file sorted -> don't merge*/ exit(0); files_merge(nr_of_files); exit(0); } /* * Adjust_options() assigns all global variables set also in the fields * assigned. */ adjust_options(field) register FIELD *field; { register FIELD *gfield = &fields[GLOBAL]; if (gfield->reverse) field->reverse = TRUE; if (gfield->blanks) field->blanks = TRUE; if (gfield->dictionary) field->dictionary = TRUE; if (gfield->fold_case) field->fold_case = TRUE; if (gfield->ascii) field->ascii = TRUE; if (gfield->numeric) field->numeric = TRUE; } /* * Error () prints the error message on stderr and exits if quit == TRUE. */ error(quit, message, arg) register BOOL quit; register char *message, *arg; { write(2, message, strlen(message)); if (arg != NIL_PTR) write(2, arg, strlen(arg)); write(2, ".\n", 2); if (quit) exit(1); } /* * Open_outfile () assigns to out_fd the fd where the output must go when all * the sorting is done. */ open_outfile() { if (output_file == NIL_PTR) out_fd = STD_OUT; else if ((out_fd = creat(output_file, 0644)) < 0) error(TRUE, "Cannot creat ", output_file); } /* * Get_file reads the whole file of filedescriptor fd. If the file is too big * to keep in core, a partial sort is done, and the output is stashed somewhere. */ get_file(fd, size) int fd; /* Fd of file to read */ register long size; /* Size of file */ { register int i; long rest; /* Rest in memory */ char save_ch; /* Used in stdin readings */ rest = MEMORY_SIZE - (cur_pos - mem_top); if (fd == 0) { /* We're reding stdin */ while ((i = read(0, cur_pos, rest)) > 0) { if ((cur_pos - mem_top) + i == MEMORY_SIZE) { in_core = FALSE; i = last_line(); /* End of last line */ save_ch = mem_top[i]; mem_top[i] = '\0'; sort (); /* Sort core */ mem_top[i] = save_ch; /* Restore erased char */ /* Restore last (half read) line */ for (size = 0; i + size != MEMORY_SIZE; size++) mem_top[size] = mem_top[i + size]; /* Assign current pos. in memory */ cur_pos = &mem_top[size]; } else { /* Fits, just assign position in mem. */ cur_pos = cur_pos + i; *cur_pos = '\0'; } /* Calculate rest of mem */ rest = MEMORY_SIZE - (cur_pos - mem_top); } } /* Reading file. Check size */ else if (size > rest) { /* Won't fit */ mread(fd, cur_pos, rest); in_core = FALSE; i = last_line(); /* Get pos. of last line */ mem_top[i] = '\0'; /* Truncate */ (void) lseek(fd, i - MEMORY_SIZE, 1); /* Do this next time */ rest = size - rest - i + MEMORY_SIZE;/* Calculate rest */ cur_pos = mem_top; /* Reset mem */ sort(); /* Sort core */ get_file(fd, rest); /* Get rest of file */ } else { /* Fits. Just read in */ mread(fd, cur_pos, size); cur_pos = cur_pos + size; /* Reassign cur_pos */ *cur_pos = '\0'; (void)close (fd); /* File completed */ } } /* * Last_line () find the last line in core and retuns the offset from the top * of the memory. */ last_line() { register int i; for (i = MEMORY_SIZE - 1; i > 0; i--) if (mem_top[i] == '\n') break; return i + 1; } /* * Print_table prints the line table in the given file_descriptor. If the fd * equals ERROR, it opens a temp_file itself. */ print_table(fd) int fd; { register char **line_ptr; /* Ptr in line_table */ register char *ptr; /* Ptr to line */ int index = 0; /* Index in output buffer */ if (fd == ERROR) { if ((fd = creat(file_name (nr_of_files), 0644)) < 0) error(TRUE, "Cannot creat ", file_name (nr_of_files)); } for (line_ptr = line_table; *line_ptr != NIL_PTR; line_ptr++) { ptr = *line_ptr; /* Skip all same lines if uniq is set */ if (uniq && *(line_ptr + 1) != NIL_PTR) { if (compare(ptr, *(line_ptr + 1)) == SAME) continue; } do { /* Print line in a buffered way */ out_buffer[index++] = *ptr; if (index == IO_SIZE) { mwrite(fd, out_buffer, IO_SIZE); index = 0; } } while (*ptr++ != '\n'); } mwrite(fd, out_buffer, index); /* Flush buffer */ (void) close(fd); /* Close file */ nr_of_files++; /* Increment nr_of_files to merge */ } /* * File_name () returns the nr argument from the argument list, or a uniq * filename if the nr is too high, or the arguments were not merge files. */ char *file_name(nr) register int nr; { if (only_merge) { if (args_offset + nr < args_limit) return argptr[args_offset + nr]; } temp_files[16] = nr / 26 + 'a'; temp_files[17] = nr % 26 + 'a'; return temp_files; } /* * Mread () performs a normal read (), but checks the return value. */ mread(fd, address, bytes) int fd; char *address; register int bytes; { if (read(fd, address, bytes) < 0 && bytes != 0) error(TRUE, "Read error", NIL_PTR); } /* * Mwrite () performs a normal write (), but checks the return value. */ mwrite(fd, address, bytes) int fd; char *address; register int bytes; { if (write(fd, address, bytes) != bytes && bytes != 0) error(TRUE, "Write error", NIL_PTR); } /* * Sort () sorts the input in memory starting at mem_top. */ sort() { register char *ptr = mem_top; register int count = 0; /* Count number of lines in memory */ while (*ptr) { if (*ptr++ == '\n') count++; } /* Set up the line table */ line_table = (char **) msbrk(count * sizeof (char *)+sizeof (char *)); count = 1; ptr = line_table[0] = mem_top; while (*ptr) { if (*ptr++ == '\n') line_table[count++] = ptr; } line_table[count - 1] = NIL_PTR; /* Sort the line table */ sort_table(count - 1); /* Stash output somewhere */ if (in_core) { open_outfile(); print_table(out_fd); } else print_table(ERROR); /* Free line table */ mbrk(line_table); } /* * Sort_table () sorts the line table consisting of nel elements. */ sort_table(nel) register int nel; { char *tmp; register int i; /* Make heap */ for (i = (nel >> 1); i >= 1; i--) incr(i, nel); /* Sort from heap */ for (i = nel; i > 1; i--) { tmp = line_table[0]; line_table[0] = line_table[i - 1]; line_table[i - 1] = tmp; incr(1, i - 1); } } /* * Incr () increments the heap. */ incr(si, ei) register int si, ei; { char *tmp; while (si <= (ei >> 1)) { si <<= 1; if (si + 1 <= ei && compare(line_table[si - 1], line_table[si]) <= 0) si++; if (compare(line_table[(si >> 1) - 1],line_table[si - 1]) >= 0) return; tmp = line_table[(si >> 1) - 1]; line_table[(si >> 1) - 1] = line_table[si - 1]; line_table[si - 1] = tmp; } } /* * Cmp_fields builds new lines out of the lines pointed to by el1 and el2 and * puts it into the line1 and line2 arrays. It then calls the cmp () routine * with the field describing the arguments. */ cmp_fields(el1, el2) register char *el1, *el2; { int i, ret; char line1[LINE_SIZE], line2[LINE_SIZE]; for (i = 0; i < field_cnt; i++) { /* Setup line parts */ build_field(line1, &fields[i + 1], el1); build_field(line2, &fields[i + 1], el2); if ((ret = cmp(line1, line2, &fields[i + 1])) != SAME) break; /* If equal, try next field */ } /* Check for reverse flag */ if (i != field_cnt && fields[i + 1].reverse) return -ret; /* Else return the last return value of cmp () */ return ret; } /* * Build_field builds a new line from the src as described by the field. * The result is put in dest. */ build_field(dest, field, src) char *dest; /* Holds result */ register FIELD *field; /* Field description */ register char *src; /* Source line */ { char *begin = src; /* Remember start location */ char *last; /* Pointer to end location */ int i; /* Skip begin fields */ src = skip_fields(src, field->beg_field); /* Skip begin positions */ for (i = 0; i < field->beg_pos && *src != '\n'; i++) src++; /* Copy whatever is left */ copy(dest, src); /* If end field is assigned truncate (perhaps) the part copied */ if (field->end_field != ERROR) { /* Find last field */ last = skip_fields(begin, field->end_field); /* Skip positions as given by end fields description */ for (i = 0; i < field->end_pos && *last != '\n'; i++) last++; dest[last - src] = '\n'; /* Truncate line */ } } /* * Skip_fields () skips nf fields of the line pointed to by str. */ char *skip_fields(str, nf) register char *str; int nf; { while (nf-- > 0) { if (separator == '\0') { /* Means ' ' or '\t' */ while (*str != ' ' && *str != '\t' && *str != '\n') str++; while (table[*str] & BLANK) str++; } else { while (*str != separator && *str != '\n') str++; str++; } } return str; /* Return pointer to indicated field */ } /* * Compare is called by all sorting routines. It checks if fields assignments * has been made. if so, it calls cmp_fields (). If not, it calls cmp () and * reversed the return value if the (global) reverse flag is set. */ compare(el1, el2) register char *el1, *el2; { int ret; if (field_cnt > GLOBAL) return cmp_fields(el1, el2); ret = cmp(el1, el2, &fields[GLOBAL]); return (fields[GLOBAL].reverse) ? -ret : ret; } /* * Cmp () is the actual compare routine. It compares according to the * description given in the field pointer. */ cmp(el1, el2, field) register char *el1, *el2; FIELD *field; { int c1, c2; if (field->blanks) { /* Skip leading blanks */ while (table[*el1] & BLANK) el1++; while (table[*el2] & BLANK) el2++; } if (field->numeric) /* Compare numeric */ return digits(el1, el2, TRUE); for (; ;) { while (*el1 == *el2) { if (*el1++ == '\n') /* EOLN on both strings */ return SAME; el2++; } if (*el1 == '\n') /* EOLN on string one */ return LOWER; if (*el2 == '\n') return HIGHER; if (field->ascii) {/* Skip chars outside 040 - 0177 */ if ((table[*el1] & ASCII) == 0) { do { el1++; } while ((table[*el1] & ASCII) == 0); continue; } if ((table[*el2] & ASCII) == 0) { do { el2++; } while ((table[*el2] & ASCII) == 0); continue; } } if (field->dictionary) {/* Skip non-dict chars */ if ((table[*el1] & DICT) == 0) { do { el1++; } while ((table[*el1] & DICT) == 0); continue; } if ((table[*el2] & DICT) == 0) { do { el2++; } while ((table[*el2] & DICT) == 0); continue; } } if (field->fold_case) { /* Fold upper case to lower */ if (table[c1 = *el1++] & UPPER) c1 += 'a' - 'A'; if (table[c2 = *el2++] & UPPER) c2 += 'a' - 'A'; if (c1 == c2) continue; return c1 - c2; } return *el1 - *el2; } /* NOTREACHED */ } /* * Digits compares () the two strings that point to a number of digits followed * by an optional decimal point. */ digits(str1, str2, check_sign) register char *str1, *str2; BOOL check_sign; /* True if sign must be checked */ { BOOL negative = FALSE; /* True if negative numbers */ int diff, pow, ret; /* Check for optional minus or plus sign */ if (check_sign) { if (*str1 == '-') { negative = TRUE; str1++; } else if (*str1 == '+') str1++; if (*str2 == '-') { if (negative == FALSE) return HIGHER; str2++; } else if (negative) return LOWER; else if (*str2 == '+') str2++; } /* Keep incrementing as long as digits are available and equal */ while ((table[*str1] & DIGIT) && table[*str2] & DIGIT) { if (*str1 != *str2) break; str1++; str2++; } /* First check for the decimal point. */ if (*str1 == '.' || *str2 == '.') { if (*str1 == '.') { if (*str2 == '.') /* Both. Check decimal part */ ret = digits(str1 + 1, str2 + 1, FALSE); else ret = (table[*str2] & DIGIT) ? LOWER : HIGHER; } else ret = (table[*str1] & DIGIT) ? HIGHER : LOWER; } /* Now either two digits differ, or unknown char is seen (e.g. end of string) */ else if ((table[*str1] & DIGIT) && (table[*str2] & DIGIT)) { diff = *str1 - *str2; /* Basic difference */ pow = 0; /* Check power of numbers */ while (table[*str1++] & DIGIT) pow++; while (table[*str2++] & DIGIT) pow--; ret = (pow == 0) ? diff : pow; } /* Unknown char. Check on which string it occurred */ else { if ((table[*str1] & DIGIT) == 0) ret = (table[*str2] & DIGIT) ? LOWER : SAME; else ret = HIGHER; } /* Reverse sense of comparisons if negative is true. (-1000 < -1) */ return (negative) ? -ret : ret; } /* * Files_merge () merges all files as indicated by nr_of_files. Merging goes * in numbers of files that can be opened at the same time. (OPEN_FILES) */ files_merge(file_cnt) register int file_cnt; /* Nr_of_files to merge */ { register int i; int limit; for (i = 0; i < file_cnt; i += OPEN_FILES) { /* Merge last files and store in output file */ if ((limit = i + OPEN_FILES) >= file_cnt) { open_outfile(); limit = file_cnt; } else { /* Merge OPEN_FILES files and store in temp file */ temp_files[16] = file_cnt / 26 + 'a'; temp_files[17] = file_cnt % 26 + 'a'; if ((out_fd = creat(temp_files, 0644)) < 0) error(TRUE, "Cannot creat ", temp_files); file_cnt++; } merge(i, limit); } /* Cleanup mess */ i = (only_merge) ? args_limit - args_offset : 0; while (i < file_cnt) (void) unlink(file_name(i++)); } /* * Merge () merges the files between start_file and limit_file. */ merge(start_file, limit_file) int start_file, limit_file; { register MERGE *smallest; /* Keeps track of smallest line */ register int i; int file_cnt = limit_file - start_file;/* Nr of files to merge */ /* Calculate size in core available for file_cnt merge structs */ buf_size = MEMORY_SIZE / file_cnt - LINE_SIZE; mbrk(mem_top); /* First reset mem to lowest loc. */ disabled = 0; /* All files not done yet */ /* Set up merge structures. */ for (i = start_file; i < limit_file; i++) { smallest = &merge_f[i - start_file]; if (!strcmp(file_name(i), "-")) /* File is stdin */ smallest->fd = 0; else if ((smallest->fd = open(file_name(i), 0)) < 0) { smallest->fd = ERROR; error(FALSE, "Cannot open ", file_name(i)); disabled++; /* Done this file */ continue; } smallest->buffer = msbrk(buf_size); smallest->line = msbrk(LINE_SIZE); smallest->cnt = smallest->read_chars = 0; (void) read_line(smallest); /* Read first line */ } if (disabled == file_cnt) { /* Couldn't open files */ (void) close(out_fd); return; } /* Find a merg struct to assign smallest. */ for (i = 0; i < file_cnt; i++) { if (merge_f[i].fd != ERROR) { smallest = &merge_f[i]; break; } } /* Loop until all files minus one are done */ while (disabled < file_cnt - 1) { if (uniq) /* Skip all same lines */ smallest = skip_lines(smallest, file_cnt); else { /* Find smallest line */ for (i = 0; i < file_cnt; i++) { if (merge_f[i].fd == ERROR) continue;/* We've had this one */ if (compare(merge_f[i].line,smallest->line) < 0) smallest = &merge_f[i]; } } /* Print line and read next */ smallest = print(smallest, file_cnt); } if (only_merge && uniq) uniq_lines(smallest); /* Print only uniq lines */ else /* Print rest of file */ while (print(smallest, file_cnt) != NIL_MERGE) ; put_line(NIL_PTR); /* Flush output buffer */ } /* * Put_line () prints the line into the out_fd filedescriptor. If line equals * NIL_PTR, the out_fd is flushed and closed. */ put_line(line) register char *line; { static int index = 0; /* Index in out_buffer */ if (line == NIL_PTR) { /* Flush and close */ mwrite(out_fd, out_buffer, index); index = 0; (void) close(out_fd); return; } do { /* Fill out_buffer with line */ out_buffer[index++] = *line; if (index == IO_SIZE) { mwrite(out_fd, out_buffer, IO_SIZE); index = 0; } } while (*line++ != '\n'); } /* * Print () prints the line of the merg structure and tries to read another one. * If this fails, it returns the next merg structure which file_descriptor is * still open. If none could be found, a NIL structure is returned. */ MERGE *print(merg, file_cnt) register MERGE *merg; int file_cnt; /* Nr of files that are being merged */ { register int i; put_line(merg->line); /* Print the line */ if (read_line(merg) == ERROR) {/* Read next line */ for (i = 0; i < file_cnt; i++) { if (merge_f[i].fd != ERROR) { merg = &merge_f[i]; break; } } if (i == file_cnt) /* No more files left */ return NIL_MERGE; } return merg; } /* * Read_line () reads a line from the fd from the merg struct. If the read * failed, disabled is incremented and the file is closed. Readings are * done in buf_size bytes. * Lines longer than LINE_SIZE are silently truncated. */ read_line(merg) register MERGE *merg; { register char *ptr = merg->line - 1; /* Ptr buf that will hold line*/ do { ptr++; if (merg->cnt == merg->read_chars) {/* Read new buffer */ if ((merg->read_chars = read(merg->fd, merg->buffer, buf_size)) <= 0) { (void) close(merg->fd);/* OOPS */ merg->fd = ERROR; disabled++; return ERROR; } merg->cnt = 0; } *ptr = merg->buffer[merg->cnt++];/* Assign next char of line */ if (ptr - merg->line == LINE_SIZE - 1) *ptr = '\n'; /* Truncate very long lines */ } while (*ptr != '\n' && *ptr != '\0'); if (*ptr == '\0') /* Add '\n' to last line */ *ptr = '\n'; *++ptr = '\0'; /* Add '\0' */ return OK; } /* * Skip_lines () skips all same lines in all the files currently being merged. * It returns a pointer to the merge struct containing the smallest line. */ MERGE *skip_lines(smallest, file_cnt) register MERGE *smallest; int file_cnt; { register int i; int ret; if (disabled == file_cnt - 1) /* We've had all */ return smallest; for (i = 0; i < file_cnt; i++) { if (merge_f[i].fd == ERROR || smallest == &merge_f[i]) continue; /* Don't check same file */ while ((ret = compare(merge_f[i].line, smallest->line)) == 0) { if (read_line(&merge_f[i]) == ERROR) break; /* EOF */ } if (ret < 0) /* Line wasn't smallest. Try again */ return skip_lines(&merge_f[i], file_cnt); } return smallest; } /* * Uniq_lines () prints only the uniq lines out of the fd of the merg struct. */ uniq_lines(merg) register MERGE *merg; { char lastline[LINE_SIZE]; /* Buffer to hold last line */ for (; ;) { put_line(merg->line); /* Print this line */ copy(lastline, merg->line); /* and save it */ if (read_line(merg) == ERROR) /* Read the next */ return; /* Keep reading until lines duffer */ while (compare(lastline, merg->line) == SAME) if (read_line(merg) == ERROR) return; } /* NOTREACHED */ } /* * Check_file () checks if a file is sorted in order according to the arguments * given in main (). */ check_file(fd, file) int fd; char *file; { register MERGE *merg; /* 1 file only */ char lastline[LINE_SIZE]; /* Save last line */ register int ret; /* ret status of compare */ if (fd == 0) file = "stdin"; merg = (MERGE *) mem_top; /* Assign MERGE structure */ merg->buffer = mem_top + sizeof(MERGE); merg->line = msbrk(LINE_SIZE); merg->cnt = merg->read_chars = 0; merg->fd = fd; buf_size = MEMORY_SIZE - sizeof(MERGE); if (read_line(merg) == ERROR) /* Read first line */ return; copy (lastline, merg->line); /* and save it */ for (; ;) { if (read_line(merg) == ERROR) /* EOF reached */ break; if ((ret = compare(lastline, merg->line)) > 0) { error(FALSE, "Disorder in file ", file); write(2, merg->line, length(merg->line)); break; } else if (ret < 0) /* Copy if lines not equal */ copy(lastline, merg->line); else if (uniq) { error(FALSE, "Non uniq line in file ", file); write(2, merg->line, length(merg->line)); break; } } mbrk(mem_top); /* Reset mem */ } /* * Length () returns the length of the argument line including the linefeed. */ length(line) register char *line; { register int i = 1; /* Add linefeed */ while (*line++ != '\n') i++; return i; } /* * Copy () copies the src line into the dest line including linefeed. */ copy(dest, src) register char *dest, *src; { while ((*dest++ = *src++) != '\n') ; } /* * Msbrk() does a sbrk() and checks the return value. */ char *msbrk(size) register unsigned size; { extern char *sbrk(); register char *address; if ((address = sbrk(size)) < 0) error(TRUE, "Not enough memory. Use chmem to allocate more", NIL_PTR); return address; } /* * Mbrk() does a brk() and checks the return value. */ char *mbrk(size) register unsigned size; { extern char *brk(); register char *address; if ((address = brk(size)) < 0) error(TRUE, "Cannot reset memory", NIL_PTR); return address; } /* split - split a file Author: Michiel Huisjes */ #include "blocksize.h" int cut_line = 1000; int infile; char out_file[100]; char *suffix; main(argc, argv) int argc; char **argv; { unsigned short i; out_file[0] = 'x'; infile = -1; if (argc > 4) usage(); for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { if (argv[i][1] >= '0' && argv[i][1] <= '9' && cut_line == 1000) cut_line = atoi(argv[i]); else if (argv[i][1] == '\0' && infile == -1) infile = 0; else usage(); } else if (infile == -1) { if ((infile = open(argv[i], 0)) < 0) { std_err("Cannot open input file.\n"); exit (1); } } else strcpy(out_file, argv[i]); } if (infile == -1) infile = 0; strcat(out_file, "aa"); for (suffix = out_file; *suffix; suffix++) ; suffix--; /* Appendix now points to last `a' of "aa". We have to decrement it by one */ *suffix = 'a' - 1; split(); exit(0); } split() { char buf[BLOCK_SIZE]; register char *index, *base; register int n; int fd; long lines = 0L; fd = newfile(); while ((n = read(infile, buf, BLOCK_SIZE)) > 0) { base = index = buf; while (--n >= 0) { if (*index++ == '\n') if (++lines % cut_line == 0) { if (write(fd,base,(int)(index-base)) != (int)(index-base)) quit(); base = index; close(fd); fd = newfile(); } } if (write(fd, base, (int) (index-base)) != (int) (index-base)) quit(); } } newfile() { int fd; if (++*suffix > 'z') { /* Increment letter */ *suffix = 'a'; /* Reset last letter */ ++*(suffix - 1); /* Previous letter must be incremented*/ /* E.g. was `filename.az' */ /* Now `filename.ba' */ } if ((fd = creat(out_file, 0644)) < 0) { std_err("Cannot create new file.\n"); exit(2); } return fd; } usage () { std_err("Usage: split [-n] [file [name]].\n"); exit(1); } quit() { std_err("split: write error\n"); exit(1); } /* stty - set terminal mode Author: Andy Tanenbaum */ #include "sgtty.h" char *on[] = {"tabs", "cbreak", "raw", "-nl", "echo"}; char *off[]= {"-tabs", "", "", "nl", "-echo"}; int k; struct sgttyb args; struct tchars tch; #define STARTC 021 /* CTRL-Q */ #define STOPC 023 /* CTRL-S */ #define QUITC 034 /* CTRL-\ */ #define EOFC 004 /* CTRL-D */ #define DELC 0177 /* DEL */ main(argc, argv) int argc; char *argv[]; { /* stty with no arguments just reports on current status. */ ioctl(0, TIOCGETP, &args); ioctl(0, TIOCGETC, &tch); if (argc == 1) { report(); exit(0); } /* Process the options specified. */ k = 1; while (k < argc) { option(argv[k], argv[k+1]); k++; } ioctl(0, TIOCSETP, &args); ioctl(0, TIOCSETC, &tch); exit(0); } report() { int mode; mode = args.sg_flags; pr(mode&XTABS, 0); pr(mode&CBREAK, 1); pr(mode&RAW, 2); pr(mode&CRMOD,3); pr(mode&ECHO,4); prints("\nkill = "); prctl(args.sg_kill); prints("\nerase = "); prctl(args.sg_erase); prints("\nint = "); prctl(tch.t_intrc); prints("\nquit = "); prctl(tch.t_quitc); prints("\n"); } pr(f, n) int f,n; { if (f) prints("%s ",on[n]); else prints("%s ",off[n]); } option(opt, next) char *opt, *next; { if (match(opt, "-tabs")) {args.sg_flags &= ~XTABS; return;} if (match(opt, "-raw")) {args.sg_flags &= ~RAW; return;} if (match(opt, "-cbreak")) {args.sg_flags &= ~CBREAK; return;} if (match(opt, "-echo")) {args.sg_flags &= ~ECHO; return;} if (match(opt, "-nl")) {args.sg_flags |= CRMOD; return;} if (match(opt, "tabs")) {args.sg_flags |= XTABS; return;} if (match(opt, "raw")) {args.sg_flags |= RAW; return;} if (match(opt, "cbreak")) {args.sg_flags |= CBREAK; return;} if (match(opt, "echo")) {args.sg_flags |= ECHO; return;} if (match(opt, "nl")) {args.sg_flags &= ~CRMOD; return;} if (match(opt, "kill")) {args.sg_kill = *next; k++; return;} if (match(opt, "erase")) {args.sg_erase = *next; k++; return;} if (match(opt, "int")) {tch.t_intrc = *next; k++; return;} if (match(opt, "quit")) {tch.t_quitc = *next; k++; return;} if (match(opt, "default")) { args.sg_flags = ECHO | CRMOD | XTABS; args.sg_kill = '@'; args.sg_erase = '\b'; tch.t_intrc = DELC; tch.t_quitc = QUITC; tch.t_startc = STARTC; tch.t_stopc = STOPC; tch.t_eofc = EOFC; return; } std_err("unknown mode: "); std_err(opt); std_err("\n"); } int match(s1, s2) char *s1, *s2; { while (1) { if (*s1 == 0 && *s2 == 0) return(1); if (*s1 == 0 || *s2 == 0) return(0); if (*s1 != *s2) return(0); s1++; s2++; } } prctl(c) char c; { if (c < ' ') prints("^%c", 'A' + c - 1); else if (c == 0177) prints("DEL"); else prints("%c", c); } /* su - become super-user Author: Patrick van Kleef */ #include "sgtty.h" #include "stdio.h" #include "pwd.h" main (argc, argv) int argc; char *argv[]; { register char *name; char *crypt (); char *shell = "/bin/sh"; int nr; char password[14]; struct sgttyb args; register struct passwd *pwd; struct passwd *getpwnam (); if (argc > 1) name = argv[1]; else name = "root"; if ((pwd = getpwnam (name)) == 0) { std_err("Unknown id: "); std_err(name); std_err("\n"); exit (1); } if (pwd->pw_passwd[0] != '\0' && getuid()!= 0) { std_err("Password: "); ioctl (0, TIOCGETP, &args); /* get parameters */ args.sg_flags = args.sg_flags & (~ECHO); ioctl (0, TIOCSETP, &args); nr = read (0, password, 14); password[nr - 1] = 0; putc('\n',stderr); args.sg_flags = args.sg_flags | ECHO; ioctl (0, TIOCSETP, &args); if (strcmp (pwd->pw_passwd, crypt (password, pwd->pw_passwd))) { std_err("Sorry\n"); exit (2); } } setgid (pwd->pw_gid); setuid (pwd->pw_uid); if (pwd->pw_shell[0]) shell = pwd->pw_shell; execn (shell); std_err("No shell\n"); exit (3); } /* sum - checksum a file Author: Martin C. Atkins */ /* * This program was written by: * Martin C. Atkins, * University of York, * Heslington, * York. Y01 5DD * England * and is released into the public domain, on the condition * that this comment is always included without alteration. */ #define BUFSIZ (512) int rc = 0; char *defargv[] = { "-", 0 }; main(argc,argv) int argc; char *argv[]; { int fd; if (*++argv == 0) argv = defargv; for (; *argv; argv++) { if (argv[0][0] == '-' && argv[0][1] == '\0') fd = 0; else fd = open(*argv, 0); if (fd == -1) { error("can't open ",*argv); rc = 1; continue; } sum(fd, (argc > 2) ? *argv : (char *)0); if (fd != 0) close(fd); } exit(rc); } error(s,f) char *s,*f; { std_err("sum: "); std_err(s); if (f) std_err(f); std_err("\n"); } sum(fd,fname) int fd; char *fname; { char buf[BUFSIZ]; int i,n; int size = 0; unsigned crc = 0; unsigned tmp; while((n = read(fd,buf,BUFSIZ)) > 0) { for (i = 0; i < n; i++) { crc = (crc>>1) + ((crc&1) ? 0x8000 : 0); tmp = buf[i] & 0377; crc += tmp; crc &= 0xffff; size++; } } if (n < 0) { if (fname) error("read error on ", fname); else error("read error", (char *)0); rc = 1; return; } putd(crc,5,1); putd((size+BUFSIZ-1)/BUFSIZ, 6, 0); if (fname) prints(" %s", fname); prints("\n"); } putd(number, fw, zeros) int number,fw,zeros; { /* Put a decimal number, in a field width, to stdout. */ char buf[10]; int n; unsigned num; num = (unsigned) number; for (n = 0; n < fw; n++) { if (num || n == 0) { buf[fw-n-1] = '0' + num%10; num /= 10; } else buf[fw-n-1] = zeros ? '0' : ' '; } buf[fw] = 0; prints("%s", buf); } /* sync - flush the file system buffers. Author: Andy Tanenbaum */ main() {sync();} /* First prize in shortest useful program contest. */ /* tail - print the end of a file */ #include "stdio.h" #define TRUE 1 #define FALSE 0 #define BLANK ' ' #define TAB '\t' #define NEWL '\n' int lines, chars ; char buff[BUFSIZ]; main(argc, argv) int argc ; char *argv[] ; { char *s ; FILE *input , *fopen(); int count ; setbuf(stdout, buff); argc-- ; argv++ ; lines = TRUE ; chars = FALSE ; count = -10 ; if (argc == 0 ) { tail(stdin, count); done(0) ; } s = *argv ; if (*s == '-' || *s == '+' ) { s++ ; if (*s >= '0' && *s <= '9' ) { count = stoi(*argv); s++ ; while (*s >= '0' && *s <= '9' ) s++ ; } if (*s == 'c' ) { chars = TRUE ; lines = FALSE ; } else if (*s != 'l' && *s != NULL ) { fprintf(stderr, "tail: unknown option %c\n", *s); argc = 0 ; } argc-- ; argv++ ; } if (argc < 0 ) { fprintf(stderr, "Usage: tail [+/-[number][lc]] [files]\n"); done(1) ; } if (argc == 0 ) tail(stdin, count); else if ((input=fopen(*argv,"r")) == NULL ) { fprintf(stderr, "tail: can't open %s\n", *argv) ; done(1) ; } else { tail(input, count); fclose(input); } done(0) ; } /* stoi - convert string to integer */ stoi(s) char *s ; { int n, sign ; while (*s == BLANK || *s == NEWL || *s == TAB ) s++ ; sign = 1 ; if (*s == '+' ) s++ ; else if (*s == '-' ) { sign = -1 ; s++ ; } for(n=0 ; *s >= '0' && *s <= '9' ; s++ ) n = 10 * n + *s - '0' ; return(sign * n); } /* tail - print 'count' lines/chars */ #define INCR(p) if (p >= end) p=cbuf ; else p++ #define BUF_SIZE 4098 char cbuf[ BUF_SIZE ] ; tail(in, goal ) FILE *in ; int goal ; { int c, count ; char *start, *finish, *end ; count = 0 ; if (goal > 0 ) { /* skip */ if (lines ) /* lines */ while ((c=getc(in)) != EOF ) { if (c == NEWL ) count++ ; if (count >= goal ) break ; } else /* chars */ while (getc(in) != EOF ) { count++ ; if (count >= goal ) break ; } if (count >= goal ) while ((c=getc(in)) != EOF ) putc(c, stdout); } else { /* tail */ goal = -goal ; start = finish = cbuf ; end = &cbuf[ BUF_SIZE - 1 ] ; while ((c=getc(in)) != EOF ) { *finish = c ; INCR(finish); if (start == finish ) INCR(start); if (!lines || c == NEWL ) count++ ; if (count > goal ) { count = goal ; if (lines ) while (*start != NEWL ) INCR(start); INCR(start); } } /* end while */ while (start != finish ) { putc(*start, stdout); INCR(start); } } /* end else */ } /* end tail */ done(n) int n; { _cleanup(); /* flush stdio's internal buffers */ exit(n); } /* tar - tape archiver Author: Michiel Huisjes */ /* Usage: tar [cxt][v] tapefile [files] * * Bugs: * This tape archiver should only be used as a program to read or make * simple tape archives. Its basic goal is to read (or build) UNIX V7 tape * archives and extract the named files. It is not wise to use it on * raw magnetic tapes. It doesn't know anything about linked files, * except when the involved fields are filled in. */ #include "stat.h" struct direct { unsigned short d_ino; char d_name[14]; }; typedef char BOOL; #define TRUE 1 #define FALSE 0 #define HEADER_SIZE 512 #define NAME_SIZE 100 #define BLOCK_BOUNDARY 20 typedef union { char hdr_block[HEADER_SIZE]; struct m { char m_name[NAME_SIZE]; char m_mode[8]; char m_uid[8]; char m_gid[8]; char m_size[12]; char m_time[12]; char m_checksum[8]; char m_linked; char m_link[NAME_SIZE]; } member; } HEADER; HEADER header; #define INT_TYPE (sizeof(header.member.m_uid)) #define LONG_TYPE (sizeof(header.member.m_size)) #define MKDIR "/bin/mkdir" #define NIL_HEADER ((HEADER *) 0) #define NIL_PTR ((char *) 0) #define BLOCK_SIZE 512 #define flush() print(NIL_PTR) BOOL show_fl, creat_fl, ext_fl; int tar_fd; char usage[] = "Usage: tar [cxt] tarfile [files]."; char io_buffer[BLOCK_SIZE]; char path[NAME_SIZE]; char pathname[NAME_SIZE]; int total_blocks; long convert(); #define block_size() (int) ((convert(header.member.m_size, LONG_TYPE) \ + (long) BLOCK_SIZE - 1) / (long) BLOCK_SIZE) error(s1, s2) char *s1, *s2; { string_print(NIL_PTR, "%s %s\n", s1, s2 ? s2 : ""); flush(); exit(1); } main(argc, argv) int argc; register char *argv[]; { register char *ptr; int i; if (argc < 3) error(usage, NIL_PTR); for (ptr = argv[1]; *ptr; ptr++) { switch (*ptr) { case 'c' : creat_fl = TRUE; break; case 'x' : ext_fl = TRUE; break; case 't' : show_fl = TRUE; break; default : error(usage, NIL_PTR); } } if (creat_fl + ext_fl + show_fl != 1) error(usage, NIL_PTR); tar_fd = creat_fl ? creat(argv[2], 0644) : open(argv[2], 0); if (tar_fd < 0) error("Cannot open ", argv[2]); if (creat_fl) { for (i = 3; i < argc; i++) { add_file(argv[i]); path[0] = '\0'; } adjust_boundary(); } else tarfile(); flush(); exit(0); } BOOL get_header() { register int check; mread(tar_fd, &header, sizeof(header)); if (header.member.m_name[0] == '\0') return FALSE; check = (int) convert(header.member.m_checksum, INT_TYPE); if (check != checksum()) error("Tar: header checksum error.", NIL_PTR); return TRUE; } tarfile() { register char *ptr; register char *mem_name; while (get_header()) { mem_name = header.member.m_name; if (ext_fl) { if (is_dir(mem_name)) { for (ptr = mem_name; *ptr; ptr++) ; *(ptr - 1) = '\0'; mkdir(mem_name); } else extract(mem_name); } else { string_print(NIL_PTR, "%s ", mem_name); if (header.member.m_linked == '1') string_print(NIL_PTR, "linked to %s\n", header.member.m_link); else { string_print(NIL_PTR, "%d tape blocks\n", block_size()); skip_entry(); } } flush(); } } skip_entry() { register int blocks = block_size(); while (blocks--) (void) read(tar_fd, io_buffer, BLOCK_SIZE); } extract(file) register char *file; { register int fd; if (header.member.m_linked == '1') { if (link(header.member.m_link, file) < 0) string_print(NIL_PTR, "Cannot link %s to %s\n", header.member.m_link, file); else string_print(NIL_PTR, "Linked %s to %s\n", header.member.m_link, file); return; } if ((fd = creat(file, 0644)) < 0) { string_print(NIL_PTR, "Cannot create %s\n", file); return; } copy(file, tar_fd, fd, convert(header.member.m_size, LONG_TYPE)); (void) close(fd); chmod(file, convert(header.member.m_mode, INT_TYPE)); flush(); } copy(file, from, to, bytes) char *file; int from, to; register long bytes; { register int rest; int blocks = (int) ((bytes + (long) BLOCK_SIZE - 1) / (long) BLOCK_SIZE); string_print(NIL_PTR, "%s, %d tape blocks\n", file, blocks); while (blocks--) { (void) read(from, io_buffer, BLOCK_SIZE); rest = (bytes > (long) BLOCK_SIZE) ? BLOCK_SIZE : (int) bytes; mwrite(to, io_buffer, (to == tar_fd) ? BLOCK_SIZE : rest); bytes -= (long) rest; } } long convert(str, type) char str[]; int type; { register long ac = 0L; register int i; for (i = 0; i < type; i++) { if (str[i] >= '0' && str[i] <= '7') { ac <<= 3; ac += (long) (str[i] - '0'); } } return ac; } mkdir(dir_name) char *dir_name; { register int pid, w; if ((pid = fork()) < 0) error("Cannot fork().", NIL_PTR); if (pid == 0) { execl(MKDIR, "mkdir", dir_name, (char *) 0); error("Cannot find mkdir.", NIL_PTR); } do { w = wait((int *) 0); } while (w != -1 && w != pid); } checksum() { register char *ptr = header.member.m_checksum; register int ac = 0; while (ptr < &header.member.m_checksum[INT_TYPE]) *ptr++ = ' '; ptr = header.hdr_block; while (ptr < &header.hdr_block[BLOCK_SIZE]) ac += *ptr++; return ac; } is_dir(file) register char *file; { while (*file++ != '\0') ; return (*(file - 2) == '/'); } char *path_name(file) register char *file; { string_print(pathname, "%s%s", path, file); return pathname; } add_path(name) register char *name; { register char *path_ptr = path; while (*path_ptr) path_ptr++; if (name == NIL_PTR) { while (*path_ptr-- != '/') ; while (*path_ptr != '/' && path_ptr != path) path_ptr--; if (*path_ptr == '/') path_ptr++; *path_ptr = '\0'; } else { while (*name) { if (path_ptr == &path[NAME_SIZE]) error("Pathname too long", NIL_PTR); *path_ptr++ = *name++; } *path_ptr++ = '/'; *path_ptr = '\0'; } } add_file(file) register char *file; { struct stat st; struct direct dir; register int fd; if (stat(file, &st) < 0) { string_print(NIL_PTR, "Cannot find %s\n", file); return; } if ((fd = open(file, 0)) < 0) { string_print(NIL_PTR, "Cannot open %s\n", file); return; } make_header(path_name(file), &st); mwrite(tar_fd, &header, sizeof(header)); if (st.st_mode & S_IFREG) copy(path_name(file), fd, tar_fd, st.st_size); else if (st.st_mode & S_IFDIR) { if (chdir(file) < 0) string_print(NIL_PTR, "Cannot chdir to %s\n", file); else { add_path(file); mread(fd, &dir, sizeof(dir)); /* "." */ mread(fd, &dir, sizeof(dir)); /* ".." */ while (read(fd, &dir, sizeof(dir)) == sizeof(dir)) if (dir.d_ino) add_file(dir.d_name); chdir(".."); add_path(NIL_PTR); } } else print(" Tar: unknown file type. Not added.\n"); (void) close(fd); } make_header(file, st) char *file; register struct stat *st; { register char *ptr = header.member.m_name; clear_header(); while (*ptr++ = *file++) ; if (st->st_mode & S_IFDIR) { *(ptr - 1) = '/'; st->st_size = 0L; } string_print(header.member.m_mode, "%I ", st->st_mode & 07777); string_print(header.member.m_uid, "%I ", st->st_uid); string_print(header.member.m_gid, "%I ", st->st_gid); string_print(header.member.m_size, "%L ", st->st_size); string_print(header.member.m_time, "%L ", st->st_mtime); header.member.m_linked = ' '; string_print(header.member.m_checksum, "%I", checksum()); } clear_header() { register char *ptr = header.hdr_block; while (ptr < &header.hdr_block[BLOCK_SIZE]) *ptr++ = '\0'; } adjust_boundary() { clear_header(); mwrite(tar_fd, &header, sizeof(header)); while (total_blocks++ < BLOCK_BOUNDARY) mwrite(tar_fd, &header, sizeof(header)); (void) close(tar_fd); } mread(fd, address, bytes) int fd, bytes; char *address; { if (read(fd, address, bytes) != bytes) error("Tar: read error.", NIL_PTR); } mwrite(fd, address, bytes) int fd, bytes; char *address; { if (write(fd, address, bytes) != bytes) error("Tar: write error.", NIL_PTR); total_blocks++; } char output[BLOCK_SIZE]; print(str) register char *str; { static int index = 0; if (str == NIL_PTR) { write(1, output, index); index = 0; return; } while (*str) { output[index++] = *str++; if (index == BLOCK_SIZE) { write(1, output, BLOCK_SIZE); index =@BC 0; } } } char *num_out(number) register long number; { static char num_buf[13]; char temp[13]; register int i; for (i = 0; i < 11; i++) { temp[i] = (number & 07) + '0'; number >>= 3; } for (i = 0; i < 11; i++) num_buf[i] = temp[10 - i]; return num_buf; } /* VARARGS */ string_print(buffer, fmt, args) char *buffer; register char *fmt; int args; { register char *buf_ptr; char *scan_ptr; char buf[NAME_SIZE]; int *argptr = &args; BOOL pr_fl, i; if (pr_fl = (buffer == NIL_PTR)) buffer = buf; buf_ptr = buffer; while (*fmt) { if (*fmt == '%') { fmt++; switch (*fmt++) { case 's': scan_ptr = (char *) *argptr; break; case 'I': scan_ptr = num_out((long) *argptr); for (i = 0; i < 5; i++) scan_ptr++; break; case 'L': scan_ptr = num_out(*((long *) argptr)); argptr++; break; case 'd' : scan_ptr = num_out((long) *argptr); while (*scan_ptr == '0') scan_ptr++; scan_ptr--; break; default: scan_ptr = ""; } while (*buf_ptr++ = *scan_ptr++) ; buf_ptr--; argptr++; } else *buf_ptr++ = *fmt++; } *buf_ptr = '\0'; if (pr_fl) print(buffer); } /* tee - pipe fitting Author: Paul Polderman */ #include "blocksize.h" #include "signal.h" #define MAXFD 18 int fd[MAXFD]; main(argc, argv) int argc; char **argv; { char iflag = 0, aflag = 0; char buf[BLOCK_SIZE]; int i, s, n; argv++; --argc; while (argc > 0 && argv[0][0] == '-') { switch (argv[0][1]) { case 'i': /* Interrupt turned off. */ iflag++; break; case 'a': /* Append to outputfile(s), * instead of overwriting them. */ aflag++; break; default: std_err("Usage: tee [-i] [-a] [files].\n"); exit(1); } argv++; --argc; } fd[0] = 1; /* Always output to stdout. */ for (s = 1; s < MAXFD && argc > 0; --argc, argv++) { if ((fd[s] = open(*argv, 2)) < 0 && (fd[s] = creat(*argv, 0666)) < 0) { std_err("Cannot open output file: "); std_err(*argv); std_err("\n"); exit(2); } s++; } if (iflag) signal(SIGINT, SIG_IGN); for (i = 1; i < s; i++) { /* Don't lseek stdout. */ if (aflag) lseek(fd[i], 0L, 2); } while ((n = read(0, buf, BLOCK_SIZE)) > 0) { for (i = 0; i < s; i++) write(fd[i], buf, n); } for (i = 0; i < s; i++) /* Close all fd's */ close(fd[i]); exit(0); } /* time - time a command Authors: Andy Tanenbaum & Michiel Huisjes */ #include "signal.h" #include "../h/const.h" char **args; char *name; struct time_buf { long user, sys; long childu, childs; }; int digit_seen; char a[12] = {" . \n"}; main(argc, argv) int argc; char *argv[]; { struct time_buf pre_buf, post_buf; int status, pid; long start_time, end_time; if (argc == 1) exit(0); args = &argv[1]; name = argv[1]; /* Get real time at start of run. */ (void) time(&start_time); /* Fork off child. */ if ((pid = fork()) < 0) { std_err("Cannot fork\n"); exit(1); } if (pid == 0) execute(); /* Parent is the time program. Disable interrupts and wait. */ signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); do { times(&pre_buf); } while (wait(&status) != pid); (void) time(&end_time); if ((status & 0377) != 0) std_err("Command terminated abnormally.\n"); times(&post_buf); /* Print results. */ print_time("real ", (end_time - start_time) * HZ); print_time("user ", post_buf.childu - pre_buf.childu); print_time("sys ", post_buf.childs - pre_buf.childs); exit(status >> 8); } print_time(mess, t) char *mess; register long t; { /* Print the time 't' in hours: minutes: seconds. 't' is in ticks. */ int hours, minutes, seconds, tenths, i; digit_seen = 0; for (i = 0; i < 8; i++) a[i] = ' '; hours = (int) (t / (3600L * (long) HZ)); t -= (long) hours * 3600L * (long) HZ; minutes = (int) (t / (60L * (long) HZ)); t -= (long) minutes * 60L * (long) HZ; seconds = (int) (t / (long) HZ); t -= (long) seconds * (long) HZ; tenths = (int) (t / ((long) HZ / 10L)); std_err(mess); if (hours) { twin(hours, &a[0]); a[2] = ':'; } if (minutes || digit_seen) { twin(minutes, &a[3]); a[5] = ':'; } if (seconds || digit_seen) twin(seconds, &a[6]); else a[7] = '0'; a[9] = tenths + '0'; std_err(a); } twin(n, p) int n; char *p; { char c1, c2; c1 = (n/10) + '0'; c2 = (n%10) + '0'; if (digit_seen==0 && c1 == '0') c1 = ' '; *p++ = c1; *p++ = c2; if (n > 0) digit_seen = 1; } char *newargs[MAX_ISTACK_BYTES >> 2] = { "/bin/sh" }; /* 256 args */ execute() { register int i; try(""); /* try local directory */ try("/bin/"); try("/usr/bin/"); for (i = 0; newargs[i + 1] = args[i]; i++) ; execv("/bin/sh", newargs); std_err("Cannot execute /bin/sh\n"); exit(-1); } char pathname[200]; try(path) char *path; { register char *p1, *p2; p1 = path; p2 = pathname; while (*p1 != 0) *p2++ = *p1++; p1 = name; while (*p1 != 0) *p2++ = *p1++; *p2 = 0; execv(pathname, args); } #include "stat.h" #include "errno.h" int no_creat = 0; main(argc,argv) int argc; char *argv[]; { char *path; int i =1; if (argc == 1) usage(); while ( i < argc ) { if (argv[i][0] == '-') { if (argv[i][1] == 'f') { i+=1; } else if (argv[i][1] == 'c') { no_creat = 1; i+=1; } else { usage(); } } else { path=argv[i]; i+=1; if (doit(path) > 0) { std_err("touch: cannot touch "); std_err(path); std_err("\n"); } } } exit(0); } doit(name) char *name; { int fd; long *t, tim; struct stat buf; unsigned short tmp; long tvp[2]; extern long time(); if (!access(name,0)) { /* change date if possible */ stat(name, &buf); tmp = (buf.st_mode & S_IFREG); if (tmp != S_IFREG) return(1); tim = time(0L); tvp[0] = tim; tvp[1] = tim; if (!utime(name,tvp)) return(0); else return(1); } else { /* file does not exist */ if (no_creat == 1) return(0); else if ( (fd = creat(name, 0777)) < 0) { return(1); } else { close(fd); return(0); } } } usage() { std_err("Usage: touch [-c] file...\n"); exit(1); } std_err(s) { prints("%s",s); } /* tr - translate characters Author: Michiel Huisjes */ /* Usage: tr [-cds] [string1 [string2]] * c: take complement of string1 * d: delete input characters coded string1 * s: squeeze multiple output characters of string2 into one character */ #define BUFFER_SIZE 1024 #define ASCII 0377 typedef char BOOL; #define TRUE 1 #define FALSE 0 #define NIL_PTR ((char *) 0) BOOL com_fl, del_fl, sq_fl; unsigned char output[BUFFER_SIZE], input[BUFFER_SIZE]; unsigned char vector[ASCII + 1]; BOOL invec[ASCII + 1], outvec[ASCII + 1]; short in_index, out_index; main(argc, argv) int argc; char *argv[]; { register unsigned char *ptr; int index = 1; short i; if (argc > 1 && argv[index][0] == '-') { for (ptr = &argv[index][1]; *ptr; ptr++) { switch (*ptr) { case 'c' : com_fl = TRUE; break; case 'd' : del_fl = TRUE; break; case 's' : sq_fl = TRUE; break; default : write(2, "Usage: tr [-cds] [string1 [string2]].\n", 38); exit(1); } } index++; } for (i = 0; i <= ASCII; i++) { vector[i] = i; invec[i] = outvec[i] = FALSE; } if (argv[index] != NIL_PTR) { expand(argv[index++], input); if (com_fl) complement(input); if (argv[index] != NIL_PTR) expand(argv[index], output); if (argv[index] != NIL_PTR) map(input, output); for (ptr = input; *ptr; ptr++) invec[*ptr] = TRUE; for (ptr = output; *ptr; ptr++) outvec[*ptr] = TRUE; } convert(); } convert() { short read_chars = 0; short c, coded; short last = -1; for (; ;) { if (in_index == read_chars) { if ((read_chars = read(0, input, BUFFER_SIZE)) <= 0) { if (write(1, output, out_index) != out_index) write(2, "Bad write\n", 10); exit(0); } in_index = 0; } c = input[in_index++]; coded = vector[c]; if (del_fl && invec[c]) continue; if (sq_fl && last == coded && outvec[coded]) continue; output[out_index++] = last = coded; if (out_index == BUFFER_SIZE) { if (write(1, output, out_index) != out_index) { write(2, "Bad write\n", 10); exit(1); } out_index = 0; } } /* NOTREACHED */ } map(string1, string2) register unsigned char *string1, *string2; { unsigned char last; while (*string1) { if (*string2 == '\0') vector[*string1] = last; else vector[*string1] = last = *string2++; string1++; } } expand(arg, buffer) register char *arg; register unsigned char *buffer; { int i, ac; while (*arg) { if (*arg == '\\') { arg++; i = ac = 0; if (*arg >= '0' && *arg <= '7') { do { ac = (ac << 3) + *arg++ - '0'; i++; } while (i < 4 && *arg >= '0' && *arg <= '7'); *buffer++ = ac; } else if (*arg != '\0') *buffer++ = *arg; } else if (*arg == '[') { arg++; i = *arg++; if (*arg++ != '-') { *buffer++ = '['; *buffer++ = i; *buffer++ = '-'; continue; } ac = *arg++; while (i <= ac) *buffer++ = i++; arg++; /* Skip ']' */ } else *buffer++ = *arg++; } } complement(buffer) unsigned char *buffer; { register unsigned char *ptr; register short i, index; unsigned char conv[ASCII + 2]; index = 0; for (i = 1; i <= ASCII; i++) { for (ptr = buffer; *ptr; ptr++) if (*ptr == i) break; if (*ptr == '\0') conv[index++] = i & ASCII; } conv[index] = '\0'; strcpy(buffer, conv); } /* umount - unmount a file system Author: Andy Tanenbaum */ #include "errno.h" extern int errno; main(argc, argv) int argc; char *argv[]; { if (argc != 2) usage(); if (umount(argv[1]) < 0) { if (errno == EINVAL) std_err("Device not mounted\n"); else perror("umount"); exit(1); } std_err(argv[1]); std_err(" unmounted\n"); exit(0); } usage() { std_err("Usage: umount special\n"); exit(1); } /* uniq - compact repeated lines Author: John Woods */ /* * uniq [-udc] [-n] [+n] [infile [outfile]] * * Written 02/08/86 by John Woods, placed into public domain. Enjoy. * */ /* If the symbol WRITE_ERROR is defined, uniq will exit(1) if it gets a * write error on the output. This is not (of course) how V7 uniq does it, * so undefine the symbol if you want to lose your output to a full disk */ #define WRITE_ERROR 1 #define isdigit(c) (c >= '0' && c <= '9') #include "stdio.h" FILE *fopen(); char buffer [BUFSIZ]; int uflag = 1; /* default is union of -d and -u outputs */ int dflag = 1; /* flags are mutually exclusive */ int cflag = 0; int fields = 0; int chars = 0; FILE *xfopen(fn, mode) char *fn, *mode; { FILE *p; extern int errno; extern char *sys_errlist[]; if ((p = fopen(fn,mode)) == NULL) { perror("uniq"); fflush(stdout); exit(1); } return (p); } main(argc,argv) char *argv[]; { char *p; int inf = -1, outf; setbuf(stdout, buffer); for (--argc, ++argv; argc > 0 && (**argv == '-' || **argv == '+'); --argc, ++argv) { if (**argv == '+') chars = atoi(*argv + 1); else if (isdigit(argv[0][1])) fields = atoi(*argv + 1); else if (argv[0][1] == '\0') inf = 0; /* - is stdin */ else for (p = *argv+1; *p; p++) { switch(*p) { case 'd': dflag = 1; uflag = 0; break; case 'u': uflag = 1; dflag = 0; break; case 'c': cflag = 1; break; default: usage(); } } } /* input file */ if (argc == 0) inf = 0; else if (inf == -1) { /* if - was not given */ fclose(stdin); xfopen(*argv++, "r"); argc--; } if (argc == 0) outf = 1; else { fclose(stdout); xfopen(*argv++, "w"); argc--; } uniq(); fflush(stdout); exit(0); } char *skip(s) char *s; { int n; /* skip fields */ for (n = fields; n > 0; --n) { /* skip blanks */ while (*s && (*s == ' ' || *s == '\t')) s++; if (!*s) return s; while (*s && (*s != ' ' && *s != '\t')) s++; if (!*s) return s; } /* skip characters */ for (n = chars; n > 0; --n) { if (!*s) return s; s++; } return s; } int equal(s1, s2) char *s1, *s2; { return !strcmp( skip(s1), skip(s2)); } show(line,count) char *line; { if (cflag) printf("%4d %s", count,line); else { if ((uflag && count == 1) || (dflag && count != 1)) printf("%s", line); } } /* * The meat of the whole affair */ char *nowline, *prevline, buf1[1024], buf2[1024]; uniq() { char *p; int seen; /* setup */ prevline = buf1; if (getline(prevline, 1024) < 0) return(0); seen = 1; nowline = buf2; /* get nowline and compare * if not equal, dump prevline and swap pointers * else continue, bumping seen count */ while (getline(nowline, 1024) > 0) { if (!equal(prevline, nowline)) { show(prevline, seen); seen = 1; p = nowline; nowline = prevline; prevline = p; } else seen += 1; } show(prevline, seen); return 0; } usage() { std_err("Usage: uniq [-udc] [+n] [-n] [input [output]]\n"); } int getline(buf,count) char *buf; int count; { char c; int ct= 0; while (ct++ < count) { c = getc(stdin); if (c <= 0) return(-1); *buf++ = c; if (c == '\n') { *buf++ = 0; return(ct); } } return(ct); } /* update - do sync periodically Author: Andy Tanenbaum */ #include "signal.h" main() { int fd, buf[2]; /* Disable SIGTERM */ signal(SIGTERM, SIG_IGN); /* Open some files to hold their inodes in core. */ close(0); close(1); close(2); open("/bin", 0); open("/lib", 0); open("/etc", 0); open("/tmp", 0); /* Flush the cache every 30 seconds. */ while (1) { sync(); sleep(30); } } /* wc - count lines, words and characters Author: David Messer */ #include "stdio.h" #define isdigit(c) (c >= '0' && c <= '9) #define isspace(c) (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r') /* * * Usage: wc [-lwc] [names] * * Flags: * l - count lines. * w - count words. * c - count characters. * * Flags l, w, and c are default. * Words are delimited by any non-alphabetic character. * * Released into the PUBLIC-DOMAIN 02/10/86 * * If you find this program to be of use to you, a donation of * whatever you think it is worth will be cheerfully accepted. * * Written by: David L. Messer * P.O. Box 19130, Mpls, MN, 55119 * Program (heavily) modified by Andy Tanenbaum */ int lflag; /* Count lines */ int wflag; /* Count words */ int cflag; /* Count characters */ long lcount; /* Count of lines */ long wcount; /* Count of words */ long ccount; /* Count of characters */ long ltotal; /* Total count of lines */ long wtotal; /* Total count of words */ long ctotal; /* Total count of characters */ main(argc, argv) int argc; char *argv[]; { int k; char *cp; int tflag, files; int i; /* Get flags. */ files = argc - 1; k = 1; cp = argv[1]; if (argc >1 && *cp++ == '-') { files--; k++; /* points to first file */ while (*cp != 0) { switch (*cp) { case 'l': lflag++; break; case 'w': wflag++; break; case 'c': cflag++; break; default: usage(); } cp++; } } /* If no flags are set, treat as wc -lwc. */ if(!lflag && !wflag && !cflag) { lflag = 1; wflag = 1; cflag = 1; } /* Process files. */ tflag = files >= 2; /* set if # files > 1 */ /* Check to see if input comes from std input. */ if (k >= argc) { count(); if(lflag) printf(" %6D", lcount); if(wflag) printf(" %6D", wcount); if(cflag) printf(" %6D", ccount); printf(" \n"); fflush(stdout); exit(0); } /* There is an explicit list of files. Loop on files. */ while (k < argc) { fclose(stdin); if (fopen(argv[k], "r") == NULL) { std_err("wc: cannot open "); std_err(argv[k]); std_err("\n"); k++; continue; } else { /* Next file has been opened as std input. */ count(); if(lflag) printf(" %6D", lcount); if(wflag) printf(" %6D", wcount); if(cflag) printf(" %6D", ccount); printf(" %s\n", argv[k]); } k++; } if(tflag) { if(lflag) printf(" %6D", ltotal); if(wflag) printf(" %6D", wtotal); if(cflag) printf(" %6D", ctotal); printf(" total\n"); } fflush(stdout); exit(0); } count() { register int c; register int word = 0; lcount = 0; wcount = 0; ccount = 0L; while((c = getc(stdin)) > 0) { ccount++; if(isspace(c)) { if(word) wcount++; word = 0; } else { word = 1; } if (c == '\n' || c == '\f') lcount++; } ltotal += lcount; wtotal += wcount; ctotal += ccount; } usage() { std_err("Usage: wc [-lwc] [name ...]\n"); exit(1); } ...newstuffREAD_MElibc.aliboldc.aliboldsrc.arunrebuildorderorig.order...crypt.ccrypt.sctime.c ctime.s!getenv.c"getenv.s#getpwent.c$getpwent.s%malloc.c&malloc.s'popen.c(popen.s)printk.c*printk.s+putc.c,putc.s-puts.c.puts.s/qsort.c0qsort.s1scanf.c2scanf.s3system.c4system.sThe sources to the library are contained in an archive to save disk space. Since MINIX uses a minimum of 1K for each file, no matter how small, the sources take up less space when packed together in an archive. To extract them, make sure there is at least 120K of free disk space, and type: ar xv libsrc.a egetpwent.s #v6_getpwent _setpwent _getpwnam _getpwuid _endpwent __pw_file: 25903 25460 28719 29537 30579 100 __pw: _setpwent -1 _setpwent: __pw jl I0013 __pw _lseek ,#8 I0014 __pw_file _open __pw, I0014: __bufcnt __pw _endpwent _endpwent: __pw jl I0023 __pw _close I0023: __pw,#-1 __bufcnt _getline: __pw jge I0033 _setpwent jge I0033 I0031 I0033: __buf,#__pwbuf I0038: __bufcnt jg I003A 024 __buffer __pw _read __bufcnt, __bufcnt jg I003D I0031 I003D: __pnt,#__buffer I003A: __pnt __pnt,#1 mov __buf (),al __buf,#1 __pnt cmpb ,#10 I0038 __pnt,#1 __bufcnt __buf __buf,#__pwbuf I0031: _skip_period: I0043: __buf cmpb ,#58 je I0042 __buf,#1 I0043 I0042: __buf __buf,#1 _getpwent _getpwent: _getline I0053 I0051 I0053: __buf _pwd, _skip_period __buf _pwd+2, _skip_period __buf _atoi _pwd+4, _skip_period __buf _atoi _pwd+6, _skip_period __buf _pwd+8, _skip_period __buf _pwd+10, _skip_period __buf _pwd+12, _pwd I0051: _getpwnam _getpwnam: _setpwent I0063: _getpwent je I0062 _strcmp I0063 I0062: _endpwent je I0069 I0061 I0069: I0061: _getpwuid _getpwuid: _setpwent I0073: _getpwent je I0072 4, I0073 I0072: _endpwent je I0079 I0071 I0079: I0071: _pwd: .zerow 14/2 __bufcnt: .zerow 2/2 __buf: .zerow 2/2 __pnt: .zerow 2/2 __buffer: .zerow 1024/2 __pwbuf: .zerow 256/2 qsort.s.s #v}_qsort _qsort _qsort: 10() _qcompar, mul _qsort1 _qsort1: ,#14 I0025: , ja I0027 I0027: sal 1 cwd iv mul , , I002B: , jae I00212 _qcompar -10(), -10() jg I00212 -10() jge I002F , I002B I002F: , _qexchange I002B I00212: , jbe I00211 _qcompar -10(), cmp -10() jge I00215 , jae I00218 _qexchange , , I002B I00218: , _q3exchange ,#8 , I00212 I00215: -10() I0021B , _qexchange I00212 I0021B: , I00212 I00211: , jae I0021E , _q3exchange ,#8 , I002B I0021E: _qsort1 , I0025 _qexchange: I0033: jle I0032 (),al ,#1 I0033 I0032: _q3exchange: I0043: 10() 10() jle I0042 (),al (),al ,#1 ,#1 I0043 I0042: _qcompar: .zerow 2/2 popen.s.s #v_popen _pclose _popen _popen: ,#10 cmpb ,#114 I0013 I0014 cmpb ,#119 I0016 I0014 I0014: ,#2 je I0018 _pipe jl I0018 _fork , jge I0019 I0018: I0019: I001E -10(),#_pids I00113: -10(),#_pids+40 jae I00110 -10() je I00111 -10() _pids cwd iv _close I00111: -10(),#2 3 I00110: sal 1 -4(_) _close je I00117 9 I00117: I00119: je I0011A C I0011A: I0011C: sal 1 _dup2 ax, je I0011D F I0011D: I0011F: sal 1 _close _3 _2 _1 _execl ,#10 27 __exit I001E: sal 1 -4(_) sal 1 _pids, 0 I00122 I00120: I00122: sal 1 _close sal 1 -4(_) _fdopen _pclose _pclose: ,#10 _gnal , 3 _gnal -10(), _fclose I0023: -4() _wait , ,#-1 je I0022 sal 1 _pids , I0023 I0022: ,#-1 I0029 ,#-1 I0029: _gnal -10() 3 _gnal sal 1 _pids _pids: .zerow 40/2 _1: 25135 28265 29487 104 _2: 26739 _3: 25389 scanf.s.s #v_scanf __doscanf _sscanf _fscanf _scanf _scanf: __io_table __doscanf ,#8 _fscanf _fscanf: __doscanf ,#8 _sscanf _sscanf: __doscanf ,#8 _rnc: _rnc_code je I0043 _rnc_arg _rnc_arg,#1 _ic, _ic I0044 _ic,#-1 I0044 I0043: _rnc_arg _getc _ic, I0044: _ugc: _rnc_code je I0053 _rnc_arg,#-1 I0054 I0053: _rnc_arg _ic _ungetc I0054: _scnindex: I0063: ,#1 xorb ah,ah al, je I0062 cmpb I0063 I0061 I0062: I0061: _iswhite: ,#32 je I0072 ,#9 je I0072 ,#10 je I0072 ,#13 je I0072 I0071 I0072: I0071: _isgit: ,#48 jl I0083 ,#57 jg I0083 I0081 I0083: I0081: _tolower: ,#65 jl I0093 ,#90 jg I0093 ,#32 I0093: __doscanf __doscanf: ,#26 _1: I00A32 7 91 I00A86 99 I00A63 100 I00A36 111 I00A33 115 I00A74 117 I00A36 120 I00A37 _rnc_arg, _rnc_code, _rnc _ic,#-1 I00AA ,#-1 I00A5 I00AA: _iswhite je I00A9 ,#1 I00AA I00A9: cmpb I00AD I00AF I00AD: _ic jge I00A11 I00A5 I00A11: cmpb ,#37 je I00A14 I00A17: _ic _iswhite je I00A16 _rnc I00A17 I00A16: _ic, je I00A1A I00AF I00A1A: ,#1 _rnc I00AA I00A14: ,#1 -12(),#1 cmpb ,#42 I00A1D ,#1 -12() I00A1D: _isgit je I00A20 -1,#1 -1 I00A25: _isgit je I00A21 ,#1 0 mul -1 48 -1, I00A25 I00A20: -1 I00A21: _tolower 108 je I00A29 I00A2A I00A29: I00A2A: -1 -1 je I00A27 ,#1 I00A27: cmpb ,#99 je I00A2C I00A2F: _ic _iswhite je I00A2C _rnc I00A2F I00A2C: -20() I00A31 I00A33: ,#8 I00A34 I00A36: ,#10 I00A34 I00A37: , -1 je I00A3B -1,#2 jb I00A34 I00A3B: _ic,#48 I00A34 _rnc _ic _tolower 120 I00A3E -1 2 -1, -20(),#1 _rnc I00A34 I00A3E: _ugc _ic,#48 I00A34: -10() -1 I00A41 -1,#65535 I00A41: -1 je I00A44 _ic,#43 I00A44 _rnc I00A4C I00A44: -1 je I00A4C _ic,#45 I00A4C -10(),#1 _rnc I00A4C: -1 1 -1 -1, je I00A4B _ic _isgit je I00A4F _ic 48 , jle I00A4F _ic 48 _ic, I00A50 I00A4F: , I00A4B _ic _tolower 97 jl I00A4B _ic _tolower 102 jg I00A4B _ic _tolower -87 _ic, I00A50: cwd .mli4 _ic cwd adc , , _rnc -20(),#1 I00A4C I00A4B: -12() je I00A58 -10() je I00A5B sbb 0 , , I00A5B: -1 je I00A5E 4 4 10() 10(),#2 2, I00A58 I00A5E: 10() 10(),#2 I00A58: -20() je I00AF I00A32 I00A63: -1 I00A68 -1,#1 I00A68: -1 1 -1 -1, je I00A67 _ic jl I00A67 -12() je I00A6C 10() -2, 10() -2 _ic (), I00A6C: _rnc -20(),#1 I00A68 I00A67: -12() je I00A6F 10(),#2 I00A6F: -20() je I00A32 I00A32 I00A74: -1 I00A79 -1,#65535 I00A79: -1 1 -1 -1, je I00A78 _ic _iswhite I00A78 _ic jle I00A78 -12() je I00A7E 10() -2, 10() -2 _ic (), I00A7E: _rnc -20(),#1 I00A79 I00A78: -12() je I00A81 push 10() 10(),#2 I00A81: -20() je I00AF I00A32 I00A86: -1 I00A88 -1,#65535 I00A88: ,#1 cmpb ,#94 I00A8B -22(),#1 ,#1 I00A8C I00A8B: -22() I00A8C: -2, I00A8E: -2 cmpb ,#93 je I00A8D -2 cmpb je I00A8D -2,#1 I00A8E I00A8D: -2 cmpb I00A92 I00A5 I00A92: -2 I00A95: -1 1 -1 -1, je I00A94 _ic _iswhite I00A94 _ic jle I00A94 _ic _scnindex -22() je I00A94 -12() je I00A9B 10() -2, 10() -2 _ic (), I00A9B: _rnc -20(),#1 I00A95 I00A94: -2 , ,#93 -12() je I00A9E 10() 10(),#2 I00A9E: -20() je I00AF I00A32 I00A31: #_1 .csb2 I00A32: ,#1 I00AA I00AF: _ic jl I00A5 _ugc I00A5: _rnc_code: .zerow 2/2 _rnc_arg: .zerow 2/2 _ic: .zerow 2/2 system.ss #vbdefghijklmnopqrstuvwxyz{|}~_system _system _system: ,#6 _fork I0016 _3 _2 _1 _execl ,#10 27 _exit _wait , , je I0015 ,#-1 je I0015 I0016 I0015: ,#-1 I001A ,#-1 I001A: _1: 25135 28265 29487 104 _2: 26739 _3: 25389 fgets.ss #u_fgets _fgets _fgets: 1 , jbe I0012 _getc ,#-1 ,#1 ,#10 I0013 ,#-1 I001a , I001a I001a: fprintf.s #u_printf _fprintf _fprintf _fprintf: __doprintf testb 4,#64 je I0013 _fflush _printf _printf: __io_table+2 __doprintf __io_table+2 testb 4,#64 je I0023 __io_table+2 _fflush I0023: puts.s.s #vu_puts _puts _puts: __io_table+2 _fputs -1(),al __io_table+2 0 _putc al,-1() fputs.s #uQ_fputs _fputs _fputs: _putc fread.s #u_fread _fread _fread: ,#6 je I0013 , jae I0013 , I001a: 10() _getc ,#-1 je I001c I0019 I001c: I0019: 1 , I001a 1 I0016 freopen.s #ua_freopen _freopen _freopen: _fclose je I0013 _fopen fclose.s #u#_fclose _fclose _fclose: I0015: ,#20 jge I0012 sal 1 __io_table , I0013 sal 1 __io_table I0012 I0015 ,#20 jl I001a -1 I001a: _fflush _close testb 4,#32 je I001d 6 je I001d 6 _free I001d: _free fopen.s #u_fopen _fopen _fopen: ,#10 _1: I00117 3 97 I001f 114 I00113 119 I001b I0015: sal 1 __io_table ,#20 jl I0013 I0015 I0019 I001b: or ,#2 420 _creat , jge I001a I001f: or ,#2 _open , jge I00111 I00111: _lseek ,#8 I001a I00113: or ,#1 _open , jge I001a I00117: I0019: #_1 .csb2 I001a: 0 _malloc I00119 I00119: 2 4, 024 _malloc 6, 6 I0011c 4 -10(), or 4 d I0011c: 4 -10(), or 32 I0011d: 6 8(), sal 1 __io_table, fseek.s #u_fseek _fseek _fseek: ,#8 4 , -25 testb 4,#1 je I0013 10(),#2 jge I0016 6 je I0016 testb 4,#4 I0016 2 , 10() I001b cwd _lseek ,#8 sbb 1 sbb 0 adc , , I001c I001b: cwd sbb , , I001c: jle I0016 cwd sbb 1f je 1f 1: or jg I0016 6 8() cwd sbb 1f je 1f 1: or jl I0016 8 , , 2 , 10() _lseek ,#8 , , 2 I0014 testb 4,#2 je I0014 _fflush 10() _lseek ,#8 , , I0014: 65535 sbb -1 1f or 1: or I00116 -1 I00116: ftell.s #u^_ftell _ftell _ftell: ,#6 testb 4,#1 je I0013 2 , I0014 testb 4,#2 je I0016 6 je I0016 testb 4,#4 I0016 8 6() , I0014 -1 65535 I0014: _lseek ,#8 , 0 sbb 0 1f je 1f 1: or jge I001b I001b: cwd adc , fwrite.s #u_fwrite _fwrite _fwrite: je I0013 , jae I0013 I001a: 10() _putc 10() testb 4, je I0019 I0019: 1 I001a 1 I0016 gets.s #u_gets _gets _gets: __io_table _getc ,#-1 ,#10 ,#1 ,#-1 I0017 , I0017 I0017: getc.s #u_getc _getc _getc: testb 4,#24 je I0013 -1 testb 4,#1 I0016 -1 2 , jg I0019 testb 4,#4 je I001c _read 2, I001d I001c: 024 6 () _read 2, I001d: 2 jg I001f 2 I00112 4 , or 8 3 I00112: 4 , or 16 I00113: -1 I001f: 6 8(), I0019: testb 4,#4 je I00115 I00115: 8 , (),#1 printdat.s #uX___stn ___stdout __io_table __stderr __stdout __stn __stn __stn: 1 ___stn ___stn __stdout __stdout: 1 66 ___stdout ___stdout __stderr __stderr: 2 6 __io_table __io_table: __stn __stdout __stderr ___stdout ___stdout: .zerow 1024/2 ___stn ___stn: .zerow 1024/2 setbuf.ss #u_setbuf _setbuf _setbuf: 6 je I0013 testb 4,#32 je I0013 6 _free 4 , -101 6, 6 I0017 4 , or 4 I0017: 6 8(), 2 ctime.ss #v _localtime _tzset ___timezone ___daylight _ctime _gmtime ___tzname _ctime _ctime: _localtime _asctime _monthze: 31 28 31 30 31 30 31 31 30 31 30 _gmtime 31 _gmtime: ,#20 _1: .zerow 18/2 2 -1,#_1 -1,#_monthze -1,#1970 0864 .rmi4 , , 0864 .dvi4 -12(), -10(), 60 .rmi4 -1 , 3600 .rmi4 60 call .dvi4 -1 2, 3600 .dvi4 -1 4, -12() -10() 4 adc 0 7 .rmi4 -1 12, I0023: 4 -1 cwd iv -10() -12() or je I0026 365 I0027 I0026: 366 I0027: cwd sbb 1f je 1f 1: or jl I0022 4 -1 cwd iv -10() -12() or je I0029 365 I002A I0029: 366 I002A: cwd sbb -12(), -10(), -1 I0023 I0022: -1 1900 -1 10, -1 -12() 14, -1 16 4 -1 cwd iv or je I002F 365 I00210 I002F: 366 I00210: 366 I00212 _monthze+2,#29 I00212: -1 cwd -12() -10() sbb 0 sbb 0 1f je 1f 1: or jl I00211 -10() -12() -1 -1,#2 cwd sbb -12(), -10(), I00212 I00211: -12() -10() 1 adc 0 -1 6, -1 _monthze cwd iv -1 8, _monthze+2,#28 -1 _last_sunday: 14 12() 420 7 cwd iv , ,#58 jl I0033 4 10 cwd iv or je I0037 365 I0038 I0037: 366 I0038: je I0033 I0033: , jge I003A I0031 I003A: ax, 7 cwd iv I0031: _localtime _localtime: ,#14 _tzset 2 ___timezone sbb ___timezone+2 , , _gmtime ___daylight je I0043 89 _last_sunday , 72 _last_sunday -10(), 14, jg I0048 14, I0043 4,#2 jl I0043 I0048: -10() 14, jl I0045 -10() 14, I0043 4,#3 jge I0043 I0045: 3600 adc 0 , , _gmtime 16 -1, I0043: mov ___timezone ___timezone: -60,-1 ___daylight ___daylight: ___tzname 1 ___tzname: _2 _3 _tzset _tzset: ,#22 -10() _ftime cwd #60 .mli4 ___timezone, ___timezone+2, ___daylight, _4 _getenv -12(), -12() je I0053 -12() cmpb je I0053 -1 -1,#1 3 -12() ___tzname _strncpy -12(),#3 -12(),#3 -12() cmpb ,#45 I005A -1,#-1 -12(),#1 I005A: -12() 48 jl I0059 -12() 57 jg I0059 -12() -12(),#1 48 0 mul -1 -1, I005A I0059: ,-1 mul -1 -1, 60 mul -1 cwd #60 .mli4 ___timezone, ___timezone+2, -12() cmpb I005D I005E I005D: I005E: ___daylight 3 -12() ___tzname+2 _strncpy I0053: _2: 17741 84 _3: 17485 84 _4: 23124 sprintf.s #u_rintf _rintf _rintf: ,#10 -10(),#-1 ,#130 -10() __doprintf -10() _putc doprintf.s #u} __doprintf __doprintf __doprintf: ,#50 _1: I0012A 9 68 I00125 79 I00126 88 I00127 99 I00128 100 I0011B 111 I0011D 115 I00129 117 I0011C 120 I00121 37 je I0016 ,#1 _putc -10(),#1 -19(),#32 ,#1 45 I0019 -10(),#-1 ,#1 I0019: 48 I001F -19(),#48 ,#1 I001F: 48 jl I001E 57 jg I001E ah,ah 48 mul -10() 0 mul , ,#1 I001F I001E: 46 I00113 ,#1 I00116: 48 jl I00113 57 jg I00113 48 0 mul , ,#1 6 I00113: 9 I0011B: ,#2 -2 cwd -1, -12(), ,#10 A I0011C: ,#2 -2 cwd -1, -12(), 4 4 -1 -12() 65535 0 4 4 -1, -12() ,#10 A I0011D: ,#2 -2 cwd -1, -12(), -1 -12() 0 sbb 0 1f je 1f 1: or jge I0011F 4 4 -1 -12() 65535 0 4 4 -1, -12() I0011F: ,#8 A I00121: ,#2 -2 cwd -1, -12(), -1 -12() 0 sbb 0 1f je 1f 1: or jge I00123 4 4 -1 -12() 65535 0 4 4 -1, -12() I00123: , A I00125: ,#4 -4 -2 -1, -12() ,#10 A I00126: ,#4 -4 -2 -1, -12() ,#8 A I00127: ,#4 -4 -2 -1, -12() , A I00128: ,#2 ,-2 -15(),al al,-15() _putc ,#1 I00129: ,#2 -2 -1, -1 _strlen al,-19() -1 __printit ,#12 ,#1 I0012A: 37 _putc ,#1 _putc I00119: #_1 .csb2 I0011A: -31() -12() -1 __bintoascii ,#8 -31() _strlen al,-19() -31() __printit ,#12 ,#1 __bintoascii: ,#22 -1 0 sbb 0 1f or 1: or I0023 10() ,#48 10() I0023: ,#10 I0026 0 sbb 0 1f je 1f 1: or jge I0026 sbb 0 , , -1 I0026: -1 I002E: -1,#12 jge I002B -1 -12(_) -1 I002E I002B: -1 I00211: ,#10 I00213 0 .rmi4 -1 -12(_),dl -1 al,-12(_) cwd sbb 0 .dvi4 , , I00213: ,#8 I00216 4 4 7 0 -1 -12(_),al 3 2: sar 1 rcr 1 1: 65535 8191 , , I00216: , I00219 4 4 15 0 -1 -12(_),al 4 2: sar 1 rcr 1 1: 65535 4095 , , I00219: -1 0 sbb 0 1f or 1: or I00211 -1 -1 -20(), I0021E: -20() jl I0021B -20() al,-12(_) I00220 -1 I00220 -20() -12(_),#32 I0021C I00220: -20() al,-12(_) 10 jge I00224 -20() -12(_) -22(), -22() 48 I00225 I00224: -20() -12(_) -22(), -22() 55 I00225: -1 I0021C: -20() I0021E I0021B: -1 je I00227 45 -12() -1 -1 I00227: -1 -20(), I0022C: -20() jl I00229 -20() 10() al,-12(_) 10(),#1 -20() I0022C I00229: 10() __printit: 12() jle I0033 12(), jle I0033 I0033: jle I003D I003A: , jle I003D al,10() 1 _putc I003A I003D: je I003C je I003C 1 _putc I003D I003C: jge I00317 al,10() xorb ah,ah 48 I00317 1 46 _putc I00317: , jge I00316 al,10() 1 _putc I00317 I00316: putc.sf.s #v"_putc _putc _putc: ,#6 testb 4,#24 je I0013 -1 testb 4,#2 I0016 -1 testb 4,#4 je I0019 _write 2,#1 I001A I0019: 8 , al, (),#1 2 , ,#1024 jl I001A testb 4,#128 I001A 2 6() () _write 6 8(), I001A: je I00110 jle I00112 2, je I00113 I00112: jge I00117 add 4 , or 16 8 I00117: 4 , or 8 I00118: -1 I00113: 2 I00110: al, ungetc.s #u_ungetc _ungetc _ungetc: jl I0012 testb 4,#1 testb 4,#4 je I0013 -1 2,#1024 jl I0018 -1 I0018: 6() 8, I001b 8 , ,#1 I001b: 2 , 8 , ,#-1 strcmp.s #u_strcmp _strcmp _strcmp: ,#1 I0012 I0013 ,#-1 access.s #uE_access _access _access: 33 _callm3 ,#8 chdir.s #u?_chr _chr _chr: 2 _callm3 ,#8 chmod.s #u@_chmod _chmod _chmod: 5 _callm3 ,#8 chown.s #uF_chown _chown _chown: 6 chroot.s #uG_chroot _chroot _chroot: 61 _callm3 ,#8 creat.s #uA_creat _creat _creat: 8 _callm3 ,#8 dup.s #u;_dup _dup _dup: 41 dup2.s #uM_dup2 _dup2 _dup2: 64 41 exec.s #u/_execl _execle _execv _execn _nullptr _execl _execl: _nullptr _execle _execle: , I0023: ,#2 je I0022 I0023 I0022: _execv _execv: _nullptr : ,#1046 -103 -1040() -102, -102, I0043: -102 -102,#2 je I0046 -103 I0043 I0046: -102 -102,#2 je I0045 -1040() I0046 I0045: -104,#2 -1040() -103 3 mul -104 -1024(_) -1030(), -103 -1030() -1040() 0() jb I0049 -7 I0041 I0049: -102 -1032(), -103 -1032(),#2 -103 I004e: -103 -103, jge I004b -102 -1030() -104, -104 -1032() -1032(),#2 ,#2 -103, I00410: -103 je I004f -103 -103,#1 -1030() (),al -1030(),#1 0() -1030(), jb I00410 -7 I0041 I004f: -1030() -1030(),#1 -103 I004e I004b: -1032() -1032(),#2 -103 I00418: -1040() -103, jge I00415 -102 -1030() -104, -104 -1032() -1032(),#2 ,#2 -103, I0041a: -103 je I00419 -103 -103,#1 -1030() (),al -1030(),#1 0() -1030(), jb I0041a -7 I0041 I00419: -1030() -1030(),#1 -103 I00418 I00415: -1032() -1032(),#2 -102 -1030() -104 cwd iv -104 mul -104 -1042(), -102 -1042() 59 I0041: _execn _execn: -3() -1() 4 59 _nullptr _nullptr: .zerow 2/2 exit.s #u;_exit _exit _exit: cleanup.s #u__cleanup __cleanup __cleanup: I0015: ,#20 jge I0012 sal 1 __io_table je I0013 sal 1 __io_table _fflush I0015 fflush.s #u_fflush _fflush _fflush: testb 4,#4 I0012 testb 4,#2 I0013 2 jg I0017 I0017: 2 6() () _write 2 , I001a 2 6 8(), I001a: 4 , or 16 -1 fork.ss #u;_fork _fork _fork: isatty.s #us_isatty _isatty _isatty: ,#30 -30() _fstat -2 61440 8192 I0013 fstat.s #uE_fstat _fstat _fstat: 8 getegid.s #ui_getegid _getegid _getegid: 47 jge I0013 _M+4 getenv.s #v_getenv _getenv _getenv: ,#6 _environ , ,#2 , cmpb je I0015 ,#1 ,#1 I0015 I0016 I0015: cmpb I0013 cmpb ,#61 je I001A I001A: geteuid.s #ug_geteuid _geteuid _geteuid: 4 jge I0013 _M+4 getgid.s #uJ_getgid _getgid _getgid: 47 getpass.s #ub_getpass _getpass _getpass: ,#8 _1: 10 _prints 9704 _ioctl ,#3088 9705 _ioctl 9 _pwdbuf _read al,_pwdbuf 10 _pwdbuf _read _pwdbuf ,#3096 9705 _ioctl _1 _prints _pwdbuf _pwdbuf: .zerow 10/2 close.ss #u@_close _close _close: 6 getuid.s #uH_getuid _getuid _getuid: 4 ioctl.s #u_ioctl _ioctl _ioctl: ,#34 _1: I0018 4 29704 I0016 29705 I0014 29713 I0015 29714 I0017 _M+8, _M+4, I0012 I0014: al,2 , , al,3 -10(), , 8 2: sal 1 rcl 1 1: or -10() or , +2, 4 cwd _M+14, _M+14+2, 54 I0015: -1, -12(), -1, -1, al,2 -22(), -20(), al,3 -2, -2, al,4 -30(), -2, al,5 -3, -32(), 16 -1 -1 2: sal 1 rcl 1 1: 4 -1 -12() 2: sal #1 rcl #1 1: or or 8 -22() -20() 2: sal 1 rcl 1 1: or or -2 -2 2: sal #1 rcl #1 1: or or , +2, -3 -32() 2: sal 1 rcl 1 1: 8 -30() -2 2: sal #1 rcl #1 1: or or _M+14, _M+14+2, 54 54 8 +2 2: sar #1 rcr 1 1: 4 4 0 2,al +2 2: sar #1 rcr 1 1: 4 4 0 3,al _M+14 4, I0017: 54 4 +2 2: sar #1 rcr 1 1: 4 4 0 16 +2 2: sar #1 rcr 1 1: 4 4 0 8 +2 2: sar #1 rcr 1 1: 4 4 0 2,al +2 2: sar #1 rcr 1 1: 4 4 0 3,al 8 _M+14 _M+14+2 2: sar #1 rcr 1 1: 4 4 0 4,al 8 _M+14 _M+14+2 2: sar #1 rcr 1 1: 4 4 0 5,al I0018: ,#-1 _errno,#22 #_1 .csb2 abort.s #u4_abort _abort _abort: 99 _exit kill.s #u>_kill _kill _kill: 37 link.s #uI_link _link _link: 9 lseek.s #u_lseek _lseek _lseek: _M+4, , +2, 10() _M+6, 9 je I0013 cwd +2 malloc.s #v_calloc _malloc _free _realloc _grow: _top 2 15 65520 -2 , _top , jb I0012 _brk jge I0013 _top, _bottom , I0019: je I0016 65534 I0019 _top (), _top _malloc _malloc: ,#8 1 65534 2 , _bottom , _bottom I0026 _sbrk _bottom, _top, I0026: () 0 je I0025 testb ,#1 je I002C and 65534 I0026 I002C: () , 0 je I002B testb ,#1 I002B I002C I002B: , ja I00210 mul , , jae I00213 I00213: or 1 2 I0021 I00210: I0026 I0025: _grow je I00216 _malloc I0021 I00216: I0021: _realloc _realloc: ,#12 -2 , 1 65534 2 , 65534 -10(), I0033: () , 0 je I0032 testb ,#1 I0032 I0033 I0032: , ja I0037 mul , , jae I003A or 1 I003B I003A: or 1 I003B: I0031 I0037: _malloc , I003D I0031 I003D: -10() _bcopy -12(), -12() 65534 I0031: _calloc _calloc: ,#6 mul _malloc I0043 push I0041 I0043: , I0048: je I0045 ,#1 I0048 I0045: I0041: _free _free: -2 , 65534 _top: .zerow 2/2 _bottom: .zerow 2/2 brk.s.s #u_brk _sbrk _brk _brk: 7 I0013 _M+18 _brkze, -1 _sbrk _sbrk: _brkze , _brkze , _brk 0 I0023 I0021 I0023: -1 I0021: brk2.ss #uK_brk2 _brk2 _brk2: get_ze 66 brksize.s #u-_brkze endbss, _brkze _brkze: endbss mknod.ss #uF_mknod _mknod _mknod: 4 mktemp.s #u_mktemp _mktemp _mktemp: ,#6 _getpid , ,#1 ,#-1 ,#-1 88 I0015 10 cwd iv #48 ,dl 10 cwd iv I0016 I0015: getpid.s #uB_getpid _getpid _getpid: 0 mount.s #uL_mount _mount _mount: 1 open.s #u>_open _open _open: 5 _callm3 ,#8 perror.s #u _perror error_message error_message: _1 _2 _3 _4 _5 _6 _7 _8 _9 _10 _11 _12 _13 _14 _15 _16 _17 _18 _19 _20 _21 _22 _23 _24 _25 _26 _27 _28 _29 _30 _31 _32 _33 _34 _35 _35: 25938 30067 29804 29728 28527 27680 29281 25959 _34: 24909 26740 24864 26482 28021 28261 116 _33: 29250 27503 28261 28704 28777 101 _32: 28500 8303 24941 31086 27680 28265 29547 _31: 25938 25697 28461 27758 8313 26982 25964 29472 29561 25972 109 _30: 27721 25964 24935 8300 25971 27493 _29: 29472 24944 25955 27680 26213 8308 28271 25632 30309 25449 101 _28: 26950 25964 29728 28527 27680 29281 25959 _27: 25940 29816 26144 27753 8293 30050 31091 _26: 8308 8289 31092 25968 29303 29801 29285 _25: 28500 8303 24941 31086 28448 25968 8302 26982 25964 115 _24: 26950 25964 29728 25185 25964 28448 25974 26226 28524 119 _23: 28233 24950 26988 8292 29281 30055 25965 29806 _22: 29513 24864 25632 29289 25445 28532 31090 _21: 8308 8289 26980 25970 29795 29295 121 _20: 29472 25461 8296 25956 26998 25955 _19: 29251 29551 11635 25956 26998 25955 27680 28265 107 _18: 26950 25964 25888 27000 29811 115 _17: 28493 28277 8308 25956 26998 25955 25120 29557 121 _16: 27714 25455 8299 25956 26998 25955 29216 29029 26997 25970 100 _15: 24898 8292 25697 29284 29541 115 _14: 25936 28018 29545 26995 28271 25632 28261 25961 100 _13: 8308 28261 30063 26727 25376 29295 101 _12: 27936 29295 8293 29296 25455 29541 25971 115 _11: 25376 26984 08 25970 110 _10: 24898 8292 26982 25964 28192 28021 25954 114 _9: 30789 25445 26144 29295 24941 8308 29285 28530 114 _8: 29249 8295 26988 29811 29728 28527 27680 28271 103 _7: 29472 25461 8296 25956 26998 25955 28448 8306 25697 29284 29541 115 _6: 12105 8271 29285 28530 114 _5: 28233 25972 29298 28789 25972 8292 31091 29811 28005 25376 27745 108 _4: 29472 25461 8296 29296 25455 29541 115 _3: 29472 25461 8296 26982 25964 28448 8306 26980 25970 29795 29295 121 _2: 8308 30575 25966 114 _1: 29253 28530 8306 _perror 48 _perror: _36: 28233 24950 26988 8292 29285 28274 2671 _37: 8250 _38: 10 _errno jl I0012 _errno,#34 jle I0013 4 _36 _write I0014 _slen _write _37 _write _errno sal 1 error_message _slen _errno sal 1 error_message _write _38 _write I0014: _slen: I0023: je I0022 I0023 I0022: pipe.ss #u~_pipe _pipe _pipe: 42 jl I0013 _M+4 (), _M+6 2, prints.s #u3_prints _Bufp _Buf _prints _Buf _Bufp _prints: ,#14 _1: I00119 2 99 I001e 115 I001f _Bufp,#_Buf , 37 je I0016 _put I0019: 48 jl I0018 57 jg I0018 48 0 mul , I0019 I0018: I001c I001e: ,#2 _put I001f: ,#2 -10(), -10() -12(), I00111: -10() -10(),#1 -13(),al je I00110 al,-13() _put 1 I00110: -10() -12() jle I0013 I00117: je I0013 32 _put 7 I00119: 37 _put _put I001c: #_1 .csb2 _Bufp _Buf _Buf _write _put: _Bufp,#_Buf+128 jae I0023 _Bufp al, _Bufp,#1 I0023: _Bufp: .zerow 2/2 _Buf: .zerow 128/2 read.ss #uD_read _read _read: 3 setgid.s #uD_setgid _setgid _setgid: 46 setuid.s #uB_setuid _setuid _setuid: 3 sleep.s #uf_sleep _alfun: _sleep _sleep: _alfun 4 _gnal _alarm _pause alarm.s #uI_alarm _alarm _alarm: 7 pause.s #u?_pause _pause _pause: 9 signal.s #u_gnal _vectab _gnal _gnal: sal 1 2 _vectab sal 1 2 _vectab, _M+4, ,#1 I0013 I0014 _begg I0014: _M+14 48 jge I0017 I0017: _vectab _vectab: .zerow 32/2 catchsig.s #u_begg _begg, _vectab, _M mtype = 2 _begg: ds es 18 _vectab _M+mtype back: _M+mtype es ds dummy i dummy: stat.sg.s #uH_stat _stat _stat: 8 stime.s.s #uG_stime _stime _stime: 2 , +2 5 strcat.ss #u}_strcat _strcat _strcat: ,#-1 ,#1 je I0015 I0016 I0015: strcpy.ss #uO_strcpy _strcpy _strcpy: ,#1 strlen.ss #uF_strlen _strlen _strlen: strncat.s #u_strncat _strncat _strncat: je I0013 je I0015 I0016 I0015: ,#-1 I001a: ,#1 I0019 I0018 I0019: I001a I0018: ,#-1 strncmp.s #u_strncmp _strncmp _strncmp: jl I0012 ,#1 I0012 I0013 jge I001a I001a: ,#-1 strncpy.s #u_strncpy _strncpy _strncpy: I0015: , jge I0012 ,#1 I0013 I001a: , jge I0019 I001a I0019: I0015 sync.s.s #u>_sync _sync _sync: 36 time.s.s #u_time _time _time: ,#6 3 _M+2 jl I0012 je I0013 _M+2 _errno, -1 65535 , +2 , je I0017 2, I0017: times.ss #u_times _times _times: 43 _M+4 _M+4+2 , 2, _M+8 _M+8+2 4, 6, _M+12 _M+12+2 8, 10, _M+16 _M+16+2 12, 14, umask.ss #uA_umask _umask _umask: 60 umount.s #uE_umount _umount _umount: 2 _callm3 ,#8 unlink.s #uE_unlink _unlink _unlink: 0 _callm3 ,#8 utime.s #u}_utime _utime _utime: _M+4, 2 , +2 4 6 _M+14, _M+14+2 _M+18, 30 wait.s #uU_wait _wait _wait: 7 _M+4 (), stderr.s #u`_std_err _std_err _std_err: ,#1 _write write.s #uA_write _write _write: 4 syslib.s #u_sys_newmap _tell_fs _sys_times _sys_abort _sys_exec _sys_get _sys_g _sys_fork _sys_copy _sys_xit _sys_xit _sys_xit: -2 _sys_get _sys_get: -2 (), _sys_g _sys_g: _M+4, _M+6, _M+14, 3 -2 _sys_fork _sys_fork: 4 -2 _sys_exec _sys_exec: 7 -2 _sys_newmap _sys_newmap: 5 -2 _sys_copy _sys_copy: _1: 31091 24435 28515 31088 25376 28257 29735 29472 28261 100 2,#6 -2 _sendrec je I0073 32768 _1 _panic I0073: _sys_times _sys_times: 8 -2 _M+4 _M+4+2 , 2, _M+8 _M+8+2 4, 6, _M+12 _M+12+2 8, 10, _M+16 _M+16+2 12, 14, _sys_abort _sys_abort: 9 -2 _tell_fs _tell_fs: 10() call.ss #u_ _callm3 _callx _len _errno : _M+4, 10() _M+6, 12() _M+8, 1 , 1 _M+12, 1 _M+14, _callm3 _callm3: 10() _M+4, _M+6, 10() _M+8, ,# ,#14 jg I0023 I0026: je I0023 10() 10(),#1 (),al ,#1 I0026 I0023: _callx _callx: _M+2, _M _sendrec je I0033 I0031 I0033: _M+2 jge I0036 _M+2 _errno, -1 I0031 I0036: _M+2 I0031: _len _len: I0043: je I0042 I0043 I0042: _errno _errno: .zerow 2/2 atoi.ss #u]_atoi _atoi _atoi: ,#6 __c_, __c_,#32 je I0014 __c_,#9 je I0014 __c_,#13 je I0014 __c_,#10 je I0014 __c_,#12 I0012 I0014: 45 I001d ,#1 I001d: 48 ,#10 jae I001c 0 mul , I001d I001c: je I00110 I00110: __c_: .zerow 2/2 message.s #u_M _M _M: .zerow 24/2 sendrec.s #u_send, _receive, _sendrec SEND = 1 RECEIVE = 2 BOTH = 3 SYSVEC = 32 _send, _receive, _sendrec _send: *SEND L0 _receive: *RECEIVE L0 _sendrec: *BOTH L0 L0: int SYSVEC printk.s #vp _printk _printk _printk: ,#36 _1: I0011F 8 68 I00111 79 I00112 88 I00113 99 I00114 100 I001E 111 I001F 115 I00115 120 I00110 , cmpb cmpb ,#37 je I0016 _putc I0019: 48 jl I0018 57 jg I0018 48 0 mul , I0019 I0018: -1, -12(), I001C I001E: ,#2 cwd -1, -14(bp), ,#10 I001D I001F: ,#2 -10(), -10() -1, -1, ,#8 I001D I00110: ,#2 -10(), -10() -1, -1, , I001D I00111: -1 -1,#4 2 -1, -1 ,#10 -1 , I001D I00112: -1 -1,#4 2 -1, -1 ,#8 -1 , I001D I00113: -1 -1,#4 2 -1, -1 , -1 , I001D I00114: ,#2 _putc I00115: -12() add -12(),#2 -32(), -12() , -32() -3, I00117: -32() -32(),#1 -35(),al je I00116 al,-35() _putc 7 I00116: -32() -3 jle I0013 I0011D: je I0013 32 _putc D I0011F: 37 _putc _putc I001C: #_1 .csb2 I001D: -30() -1 -1 _bintoascii ,#8 , jle I00121 I00124: 1 32 _putc I00124 I00121: , I00129: jl I00126 al,-30(_) _putc I00129 I00126: _bintoascii: ,#10 0 sbb 0 1f or 1: or I0023 10() ,#48 I0021 I0023: 0 sbb 0 1f je 1f 1: or jge I0026 ,#10 I0026 sbb 0 , , I0026: I002C: ,#12 jge I0029 10() I002C I0029: I002F: ,#10 I00211 0 .rmi4 10() ,dl 10() cwd sbb 0 .dvi4 , , I00211: ,#8 I00214 4 4 7 0 10() 3 2: sar 1 rcr 1 1: 65535 8191 , , I00214: , I00217 4 4 15 0 10() 4 2: sar 1 rcr 1 1: 65535 4095 , , I00217: 0 sbb 0 1f or 1: or I002F I0021C: jl I00219 10() cmpb I0021E I0021E 10() ,#32 I0021A I0021E: 10() 10 jge I00222 ,10() -10(), -10() 48 I00223 I00222: 10() -10(), -10() 55 I00223: I0021A: I0021C I00219: je I00225 45 10() I00225: I0021: itoa.ss #u_itoa _itoa _itoa: ,#6 _next jge I0013 45 _qbuf _next _next I0016 48 _qbuf _next _next I0017 ,#10000 I0019: jle I0017 cwd iv I001b jle I001c I001b: 48 _qbuf _next _next ,#1 I001c: mul , 10 cwd iv I0019 I0017: _next _qbuf _qbuf _qbuf: .zerow 8/2 _next: .zerow 2/2 abs.ss #u=_abs _abs _abs: jge I0013 atol.ss #u>_atol _atol _atol: ,#8 al,__ctype_+1 testb al,#8 45 I0019 ,#1 I0019: 48 , ,#10 jae I0018 #10 .mli4 , adc , , I0019 I0018: je I001c sbb 0 I001c: ctype.s #u__ctype_ __ctype_ __ctype_: 8192 2056 2056 8200 2080 1040 1028 1028 1028 1028 4100 16705 16705 16705 16962 16962 16962 32 index.s #uo_index _index _index: I0014: al, I0013 I0014 bcopy.s #uP_bcopy _bcopy _bcopy: (),al ,#1 getutil.s #u_get_base, _get_ze, _get_tot_mem _get_base, _get_ze, _get_tot_mem, endbss _get_base: ds _get_ze: endbss _get_tot_mem: cli es 8192 L1: es, seg es ()xA5A4 seg es () 0xA5A4 L2 4096 0xA000 L1 L2: es sti rand.s #u_rand _seed: 1,0 _rand _rand: #20077 838 _seed _seed+2 .mli4 12345 adc #0 65535 #32767 _seed, _seed+2, 4 4 _seed _seed+2 32767 0 rindex.s #up_rindex _rindex _rindex: I0014: al, I0013 I0014 setjmp.s #u_setjmp _longjmp _setjmp, _longjmp _setjmp: *2 , *2, *4, _longjmp: * * L1 L1: L2: *0() je L3 *0() or L2 hlt L3: *0() ,*2 *4 , adi.s.s #ud.a .a: 2 L1 L1: 4 L9 adc L9: .trpvz and.s.s #u9.and .and: sar 1 L1: () stow L1 cii.s.s #u.cii .cii: je L8 2 je L1 4 L7 2 L9 L8: () L7: 1 L9 2 L9 L8 L1: 4 L9 cwd () L9: .trpilin cms.s.s #uV.cms .cms: sar 1 repe cmps je L1 L1: , cmu4.ss #uj.cmu4 .cmu4: ja L1 jb L2 ja L1 je L3 L2: L3: L1: com.s #u6.com .com: sar 1 L1: not () L1 csa2.s #uz.csa2 .csa2: () 2() 4() ja L1 sal 1 6(_) test jnz L2 L1: test jnz L2 .trpcase L2: csb2.s #u}.csb2 .csb2: lodw xchg lodw xchg L1: jl L2 lodw lodw L1 xchg L2: test jnz L3 .trpcase L3: cuu.s #u.ciu .cui .ciu: .cui: : je L8 2 je L1 4 L9 2 L9 L8: () L1: 4 L9 () L9: .trpilin .dup.s #u.define .dup | #bytes in cx .dup: pop bx | return address mov si,sp sub sp,cx mov di,sp sar cx,#1 rep movw jmp (bx) dvi.s #u.dvi .dvi: 2 L1 cwd iv L1: 4 L9 .dvi4 L9: .trpvz dvi4.s #u.dvi4 .dvi4 xl=6 xh=4 yl=10 yh=8 .dvi4: yl() yh() xl() xh() test jns L1 sbb *0 not L1:test jns L2 sbb *0 not L2:L4 test je L3 sbb *0 L3: 8 L4:test L5 v xchg v L5: testb bh,bh L6 bh,bl bl,ch ch,cl subb cl,cl ch,al subb cl,cl al,ah ah,dl dl,dh subb dh,dh jb L7 0xffff j L8 L6: L7:v L8: mul adc *0 mul adc *0 adc *0 L9:jns L10 adc adc 0 j L9 L10: test je L11 cl,ch ch,bl bl,bh bh,al L11: dvu.s #u.dvu .dvu: 2 L1 v L1: 4 L9 .dvu4 L9: .trpvz dvu4.s #u .dvu4 yl=2 yh=4 xl=6 xh=8 .dvu4: yl() yh() or L7 xl() xh() v xchg v L9: 8 L7: xl() xh() 16 L1: shl 1 rcl #1 rcl 1 ja L3 jb L2 yl(), jbe L2 L3: L1 L9 L2: yl() sbb L1 L9 exg.s #uf.exg .exg: , rep movw sar 1 rep movw , fakfp.s #u.mlf,.dvf,.ngf,.adf,.sbf,.cmf,.zrf,.fif,.fef .mlf8,.dvf8,.ngf8,.adf8,.sbf8,.cmf8,.zrf8,.fif8,.fef8 .mlf4,.dvf4,.ngf4,.adf4,.sbf4,.cmf4,.zrf4,.fif4,.fef4 .cif,.cfi,.cuf,.cfu,.cff .mlf: .dvf: .ngf: .adf: .sbf: .cmf: .zrf: .fif: .fef: .mlf4: .dvf4: .ngf4: .adf4: .sbf4: .cmf4: .zrf4: .fif4: .fef4: .mlf8: .dvf8: .ngf8: .adf8: .sbf8: .cmf8: .zrf8: .fif8: .fef8: .cif: .cfi: .cuf: .cfu: .cff: .trpnofp gto.ss #u .gto .gto: #4 ,#2 iaar.s #uP.iaar .iaar: #2 .unknown () mul 4() ilar.s #uC.ilar .ilar: #2 .unknown .lar2 inn.s #u.inn .inn: #8 v xchg xchg jae L1 dl,bits() testb (),dl jz L1 L1: , bits: .byte 1,2,4,8,16,32,64,128 ior.s #u;.ior .ior: sar 1 L1: or () stow L1 isar.s #uC.isar .isar: #2 .unknown .sar2 lar2.s #uv.lar2 .larL2: () 4() imul sar 1 jnb L1 ah,ah lodb L1: ,4() rep movw loi.s #uX.loi .loi: sar 1 jnb L1 ah,ah lodb L1: , rep movw mli.s #up.mli .mli: 2 L1 mul L1: 4 L9 .mli4 L9: .trpvz mli4.s #uD.mli4 .mli4: mul mul mul ngi.s #ul.ngi .ngi: 2 L1 L1: 4 L9 sbb 0 L9: .trpvz nop.s #u.nop rck.s #u?.rck .rck: () jl L2 2() jg L2 L2: .trprang rmi.s #u.rmi .rmi: 2 L1 cwd iv L1: 4 L9 .rmi4 () L9: .trpvz rmi4.s #u.rmi4 yl=2 yh=4 xl=6 xh=8 .rmi4: yl() yh() cwd L7 jge L1 je L7 L1: xl() xh() jge L2 sbb L2: v xchg v L9: xh() jge L1a sbb 0 L1a: 8 L7: jge L1b yl() sbb L1b: xl() xh() jge L1c sbb L1c: 16 L1d: shl 1 rcl #1 rcl 1 ja L3 jb L2 yl(), jbe L2a L3: L1d L9 L2a: yl() sbb L1d L1e: L9 rmu.s #u.rmu .rmu: 2 L1 iv L1: 4 L9 .rmu4 () L9: .trpvz rmu4.s #u%.rmu4 yl=2 yh=4 xl=6 xh=8 .rmu4: yl() yh() or L7 L1: xl() xh() L2: v xchg v L9: 8 L7: xl() xh() 16 L1a: shl 1 rcl #1 rcl 1 ja L3 jb L2 yl(), jbe L2 L3: L1a L9 L2a: yl() sbb L1a L1c: L9 rol.s #u.rol .rol: 2 L1 rol cl () L1: 4 L9 L2 L3: sal 1 rcl 1 adc 0 L3 L2: () L9: .trpvz ror.s #u.ror .ror: 2 L1 ror cl () L1: 4 L9 L2 32 L3: sar 1 rcr 1 L3 L2: () L9: .trpvz sar2.s #uj.sar2 .sar2: () 4() imul sar 1 jnb L1 stob L1: rep movw , sbi.s #uo.sbi .sbi: 2 L1 L1: 4 L9 sbc L9: .trpvz set.s #u.set .set: L1: , ja L1 #8 v jae L2 dl,bits() orb (),dl L2: .trpset bits: .byte 1,2,4,8,16,32,64,128 sli.s #u.sli .sli: 2 L1 sal cl () L1: 4 L9 L2 L3: sal 1 rcl 1 L3 L2: () L9: .trpvz sri.s #u.sri .sri: 2 L1 sar cl () L1: 4 L9 L2 L3: sar 1 rcr 1 L3 L2: () L9: .trpvz sti.s #uL.sti .sti: sar 1 jnb L1 stob L1: rep movw , xor.s #u9.xor .xor: sar 1 L1: () stow L1 error.s #u.error ! is trap number ! all registers must be saved ! because urn is posble ! May only be called with error no's <16 .error: 1 sal cl test (.ignmask) 2f .trp 2: unknown.s #u.unknown .unknown: .trpilin trp.sn.s #u.trpvz .trpilin .trpcase .trprang .trpset .trpnofp .trpheap .M: .zerow 24/2 .trpvz .trpilin .trpcase .trprang .trpset .trpnofp .trpheap .trpvz: .Mvz .Trp .trpilin: .Milin .Trp .trpcase: .Mcase .Trp .trprang: .Mrang .Trp .trpset: .Mset .Trp .trpnofp: .Mnofp .Trp .trpheap: .Mheap .Trp .Trp: 2 .Write _exit .Write: .M+2,#4 .M+4, .M+6, .M+10, .M .M 3 int 32 .Mvz: .asciz "Error: Divion by 0 \n" .Milin: .asciz "Illegal EM instruct'n\n" .Mcase: .asciz "Err in EM case instr \n" .Mrang: .asciz "Variable out of range\n" .Mset: .asciz "Err in EM set instr \n" .Mnofp: .asciz "Floating pt not impl.\n" .Mheap: .asciz "Heap overflow \n" stb.s #uc___stb ___stb ___stb: jle I0013 I0017: ,#1 (),al ,#1 I0017 crypt.s #vr_setkey _encrypt _crypt _InitialTr: 12858 8746 4634 522 13372 9260 8 1036 13886 9774 5662 1550 14400 10288 6176 2064 12601 8489 4377 265 13115 9003 4891 779 13629 9517 5405 1293 14143 10031 5919 1807 _FinalTr: 2088 4144 6200 8256 1831 3887 5943 7999 1574 3630 5686 7742 1317 3373 5429 7485 1060 3116 5172 7228 803 2859 4915 6971 546 2602 4658 6714 289 2345 4401 6457 _swap: 8737 9251 9765 10279 10793 11307 11821 12335 12849 13363 13877 14391 14905 15419 15933 16447 513 1027 1541 2055 .word 2569 3083 3597 4111 4625 5139 5653 6167 6681 7195 7709 8223 _KeyTr1: 12601 8489 4377 265 12858 8746 4634 522 13115 9003 4891 779 13372 9260 14143 10031 5919 1807 13886 9774 5662 1550 13629 9517 5405 1293 8 1036 _KeyTr2: 4366 6155 1281 7171 1551 2581 4887 1036 2074 1808 7 525 13353 9503 14127 10270 11571 12321 12588 14375 13602 10798 9266 8221 _etr: 288 770 1284 1284 1798 2312 2312 2826 3340 3340 3854 4368 4368 4882 5396 5396 5910 .word 6424 6424 6938 7452 7452 7966 288 _ptr: 1808 5396 3101 4380 3841 6679 4613 2591 2050 3608 6944 2307 3347 1566 2838 6404 _s_boxes: 1038 269 3842 2059 2563 3078 2309 1792 3840 1031 526 269 1546 2828 1289 2051 260 2062 1549 2818 3087 1801 2563 5 3087 520 2308 1793 2821 3587 10 3334 271 3592 2822 1027 1801 3330 12 2565 3331 1796 527 3592 12 2561 2310 1291 3584 2823 1034 269 2053 .word 1548 777 3842 2061 266 3843 516 1547 3079 1280 2318 10 3593 774 1295 3329 1804 1035 2050 1805 2304 1027 2566 2050 3589 2828 271 1549 2308 3848 3 267 3074 2565 1806 2561 13 2310 1800 3844 782 1291 3074 3335 782 1536 2569 513 1288 3083 3844 2061 1291 3846 768 1796 3074 2561 2318 1546 9 2828 3335 271 3587 517 1032 3843 1536 266 2061 1033 2821 1804 3586 3074 260 2567 1547 1288 3843 13 2318 2830 3074 1796 269 5 5 2307 1544 516 2817 3338 2055 2319 1292 774 3584 2059 1804 3585 3330 3846 2304 1034 773 268 3850 521 2054 3328 1027 1806 2821 3850 516 3079 1289 262 3597 2816 2051 3593 1295 2050 780 7 2564 3329 1547 772 3074 1289 5 3595 1793 6 3336 2820 3586 15 3336 3075 1801 2565 262 13 1803 2308 2561 782 3077 3842 1544 1025 3339 780 3591 3850 2054 1280 521 2822 2061 1025 1802 1289 3840 526 3075 525 1032 3846 267 2314 3587 5 1804 3841 2061 778 1031 1292 2822 3584 521 2823 260 3081 526 1536 3338 783 2053 258 1806 2564 3336 3087 9 1283 2822 _rots: 1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1 _tranose: ,#64 ,#-62 62 64 ___stb -6 2 64 ___stb ,#70 jle I0012 1 al,-64(_) _rotate: ,#8 55 , , al,28 , I0023: push ,#1 jae I0022 (),al I0023 I0022: 27,al 55,al _EP: _etr _f: ,#214 ,#-62 62 64 ___stb -6 2 64 ___stb ,#70 48 _EP -6 _tranose sal 1 _rots -19, I0035: -19 je I0032 _rotate -19 I0035 I0032: ,#-62 62 64 ___stb -12 2 64 ___stb ,#70 48 _KeyTr2 -12 _tranose -14 -19, -1 -19, -80() -200(), I0037: -192() -19, jbe I0036 -200(),#-1 -200() -19,#-1 -19 -19,#-1 -19 (),bl I0037 I0036: 10() -19, -19 I003C: -19,#8 jge I0039 -19 -19,#1 5 sal cl -20, -20 -19 -19,#1 3 sal cl -20, -20 -19 -19,#1 sal cl call -20, -20 -19 -19,#1 1 sal cl -20, -20 -19 -19,#1 -20, -20 -19 -19,#1 4 sal cl -20, 6 -19 sal cl -20 al,_s_boxes -202(), 3 -202() sar cl 1 -19 -19,#1 -202() sar cl 1 -19 -198(bp),#1 -202() sar 1 1 -19 -19,#1 -202() 1 -19 -19,#1 -19 I003C I0039: 32 _ptr 10() _tranose _setkey _setkey: ,#-62 62 64 ___stb _key 2 64 ___stb ,#70 56 _KeyTr1 _key _tranose _encrypt _encrypt: ,#136 64 _InitialTr _tranose ,#15 I0055: jl I0052 je I0057 I0058 I0057: 5 I0058: -2() ,#-62 62 64 ___stb -72() 2 64 ___stb ,#70 ,#31 I005C: jl I0059 32 al,-72(_) I005C I0059: -13 _key _f ,#8 ,#31 I00510: jl I0053 al,-72(_) bl,-136(_) bh,bh #32 (),bl I00510 I0053: I0055 I0052: 64 _swap _tranose 64 _FinalTr _tranose _crypt _crypt: ,#148 _1: .zerow 16/2 -6 -6, I0063: cmpb je I006A bx, -6, jae I006A -13,#7 I0067: -13 -13 je I0066 -13 sar cl 1 -6 -6,#1 I0067 I0066: -6 -6,#1 I0063 I006A: -6, jae I0069 -6 -6,#1 I006A I0069: -6 -6, -6 _setkey I006D: 0() -6, jae I006C -6 -6,#1 I006D I006C: _etr ,#-62 62 64 ___stb -132() 2 64 ___stb ,#70 -132() _EP, -13 I00612: -13,#2 jge I006F ,#1 -135(),al -13 al,-135() _1,al al,-135() 90 jle I00614 al,-135() 59 -135(),al I00615 I00614: al,-135() 57 jle I00617 al,-135() 53 -135(),al I00615 I00617: al,-135() 46 -135(),al I00615: -13 I0061C: -13,#6 jge I00610 al,-135() -13 sar cl testb al,#1 je I0061A 6 mul -13 -13 -14, -14 al,-132(_) -14, -14 24 -14 al,-132(_) -132(_),al -14 -14 24 -132(_),al I0061A: -13 I0061C I00610: -13 I00612 I006F: cmpb _1+1 I00621 cl,_1 _1+1,cl I00621: -13 I00626: -13,#25 jge I00623 -6 _encrypt -13 I00626 I00623: _EP,#_etr -6 -6, ,#_1+2 I00628: 0() -6, jae I00627 -13 -13,#6 I0062B: -13 -13 je I0062A -13 sal 1 -13, -13 -6 -6,#1 or -13, I0062B I0062A: -13,#46 -13,#57 jle I0062E -13,#7 I0062E: -13,#90 jle I00631 -13,#6 I00631: -13 I00628 I00627: _1 _key: .zerow 64/2 ecleanup.s __cleanup __cleanup __cleanup: I0015: ,#20 jge I0012 sal 1 __io_table je I0013 sal 1 __io_table _fflush I0015 fgets.s _fgets _fgets _fgets: 1 , jbe I0012 _getc ,#-1 ,#1 ,#10 I0013 ,#-1 I001a , I001a I001a: fprintf.s _printf _fprintf _fprintf _fprintf: __doprintf testb 4,#64 je I0013 _fflush _printf _printf: __io_table+2 __doprintf __io_table+2 testb 4,#64 je I0023 __io_table+2 _fflush I0023: fputs.s Q_fputs _fputs _fputs: _putc 6fread.s _fread _fread _fread: ,#6 je I0013 , jae I0013 , I001a: 10() _getc ,#-1 je I001c I0019 I001c: I0019: 1 , I001a 1 I0016 freopen.s a_freopen _freopen _freopen: _fclose je I0013 _fopen (fclose.s #_fclose _fclose _fclose: I0015: ,#20 jge I0012 sal 1 __io_table , I0013 sal 1 __io_table I0012 I0015 ,#20 jl I001a -1 I001a: _fflush _close testb 4,#32 je I001d 6 je I001d 6 _free I001d: _free fopen.s _fopen _fopen _fopen: ,#10 _1: I00117 3 97 I001f 114 I00113 119 I001b I0015: sal 1 __io_table ,#20 jl I0013 I0015 I0019 I001b: or ,#2 420 _creat , jge I001a I001f: or ,#2 _open , jge I00111 I00111: _lseek ,#8 I001a I00113: or ,#1 _open , jge I001a I00117: I0019: #_1 .csb2 I001a: 0 _malloc I00119 I00119: 2 4, 024 _malloc 6, 6 I0011c 4 -10(), or 4 d I0011c: 4 -10(), or 32 I0011d: 6 8(), sal 1 __io_table, fseek.s _fseek _fseek _fseek: ,#8 4 , -25 testb 4,#1 je I0013 10(),#2 jge I0016 6 je I0016 testb 4,#4 I0016 2 , 10() I001b cwd _lseek ,#8 sbb 1 sbb 0 adc , , I001c I001b: cwd sbb , , I001c: jle I0016 cwd sbb 1f je 1f 1: or jg I0016 6 8() cwd sbb 1f je 1f 1: or jl I0016 8 , , 2 , 10() _lseek ,#8 , , 2 I0014 testb 4,#2 je I0014 _fflush 10() _lseek ,#8 , , I0014: 65535 sbb -1 1f or 1: or I00116 -1 I00116: fflush.s _fflush _fflush _fflush: testb 4,#4 I0012 testb 4,#2 I0013 2 jg I0017 I0017: 2 6() () _write 2 , I001a 2 6 8(), I001a: 4 , or 16 -1 ftell.s ^_ftell _ftell _ftell: ,#6 testb 4,#1 je I0013 2 , I0014 testb 4,#2 je I0016 6 je I0016 testb 4,#4 I0016 8 6() , I0014 -1 65535 I0014: _lseek ,#8 , 0 sbb 0 1f je 1f 1: or jge I001b I001b: cwd adc , fwrite.s _fwrite _fwrite _fwrite: je I0013 , jae I0013 I001a: 10() _putc 10() testb 4, je I0019 I0019: 1 I001a 1 I0016 lgets.s _gets _gets _gets: __io_table _getc ,#-1 ,#10 ,#1 ,#-1 I0017 , I0017 I0017: getc.s _getc _getc _getc: testb 4,#24 je I0013 -1 testb 4,#1 I0016 -1 2 , jg I0019 testb 4,#4 je I001c _read 2, I001d I001c: 024 6 () _read 2, I001d: 2 jg I001f 2 I00112 4 , or 8 3 I00112: 4 , or 16 I00113: -1 I001f: 6 8(), I0019: testb 4,#4 je I00115 I00115: 8 , (),#1 printdat.s X___stn ___stdout __io_table __stderr __stdout __stn __stn __stn: 1 ___stn ___stn __stdout __stdout: 1 66 ___stdout ___stdout __stderr __stderr: 2 6 __io_table __io_table: __stn __stdout __stderr ___stdout ___stdout: .zerow 1024/2 ___stn ___stn: .zerow 1024/2 setbuf.s _setbuf _setbuf _setbuf: 6 je I0013 testb 4,#32 je I0013 6 _free 4 , -101 6, 6 I0017 4 , or 4 I0017: 6 8(), 2 sprintf.s _rintf _rintf _rintf: ,#10 -10(),#-1 ,#130 -10() __doprintf -10() _putc 0doprintf.sk } __doprintf __doprintf __doprintf: ,#50 _1: I0012A 9 68 I00125 79 I00126 88 I00127 99 I00128 100 I0011B 111 I0011D 115 I00129 117 I0011C 120 I00121 37 je I0016 ,#1 _putc -10(),#1 -19(),#32 ,#1 45 I0019 -10(),#-1 ,#1 I0019: 48 I001F -19(),#48 ,#1 I001F: 48 jl I001E 57 jg I001E ah,ah 48 mul -10() 0 mul , ,#1 I001F I001E: 46 I00113 ,#1 I00116: 48 jl I00113 57 jg I00113 48 0 mul , ,#1 6 I00113: 9 I0011B: ,#2 -2 cwd -1, -12(), ,#10 A I0011C: ,#2 -2 cwd -1, -12(), 4 4 -1 -12() 65535 0 4 4 -1, -12() ,#10 A I0011D: ,#2 -2 cwd -1, -12(), -1 -12() 0 sbb 0 1f je 1f 1: or jge I0011F 4 4 -1 -12() 65535 0 4 4 -1, -12() I0011F: ,#8 A I00121: ,#2 -2 cwd -1, -12(), -1 -12() 0 sbb 0 1f je 1f 1: or jge I00123 4 4 -1 -12() 65535 0 4 4 -1, -12() I00123: , A I00125: ,#4 -4 -2 -1, -12() ,#10 A I00126: ,#4 -4 -2 -1, -12() ,#8 A I00127: ,#4 -4 -2 -1, -12() , A I00128: ,#2 ,-2 -15(),al al,-15() _putc ,#1 I00129: ,#2 -2 -1, -1 _strlen al,-19() -1 __printit ,#12 ,#1 I0012A: 37 _putc ,#1 _putc I00119: #_1 .csb2 I0011A: -31() -12() -1 __bintoascii ,#8 -31() _strlen al,-19() -31() __printit ,#12 ,#1 __bintoascii: ,#22 -1 0 sbb 0 1f or 1: or I0023 10() ,#48 10() I0023: ,#10 I0026 0 sbb 0 1f je 1f 1: or jge I0026 sbb 0 , , -1 I0026: -1 I002E: -1,#12 jge I002B -1 -12(_) -1 I002E I002B: -1 I00211: ,#10 I00213 0 .rmi4 -1 -12(_),dl -1 al,-12(_) cwd sbb 0 .dvi4 , , I00213: ,#8 I00216 4 4 7 0 -1 -12(_),al 3 2: sar 1 rcr 1 1: 65535 8191 , , I00216: , I00219 4 4 15 0 -1 -12(_),al 4 2: sar 1 rcr 1 1: 65535 4095 , , I00219: -1 0 sbb 0 1f or 1: or I00211 -1 -1 -20(), I0021E: -20() jl I0021B -20() al,-12(_) I00220 -1 I00220 -20() -12(_),#32 I0021C I00220: -20() al,-12(_) 10 jge I00224 -20() -12(_) -22(), -22() 48 I00225 I00224: -20() -12(_) -22(), -22() 55 I00225: -1 I0021C: -20() I0021E I0021B: -1 je I00227 45 -12() -1 -1 I00227: -1 -20(), I0022C: -20() jl I00229 -20() 10() al,-12(_) 10(),#1 -20() I0022C I00229: 10() __printit: 12() jle I0033 12(), jle I0033 I0033: jle I003D I003A: , jle I003D al,10() 1 _putc I003A I003D: je I003C je I003C 1 _putc I003D I003C: jge I00317 al,10() xorb ah,ah 48 I00317 1 46 _putc I00317: , jge I00316 al,10() 1 _putc I00317 I00316: putc.s _putc _putc _putc: ,#6 testb 4,#24 je I0013 -1 testb 4,#2 I0016 -1 testb 4,#4 je I0019 _write 2,#1 I001a I0019: 8 , al, (),#1 2 , ,#1024 jl I001a testb 4,#128 I001a 2 6() () _write 6 8(), I001a: je I00110 jle I00112 2, je I00113 I00112: jge I00117 4 , or 16 8 I00117: 4 , or 8 I00118: -1 I00113: 2 I00110: tscanf.s"D _scanf _fscanf _sscanf _scanf _scanf: __io_table __doscanf ,#8 _fscanf _fscanf: __doscanf ,#8 _sscanf _sscanf: __doscanf ,#8 _rnc: _rnc_code je I0043 _rnc_arg _rnc_arg,#1 _ic, _ic I0044 _ic,#-1 I0044 I0043: _rnc_arg _getc _ic, I0044: _ugc: _rnc_code je I0053 _rnc_arg,#-1 I0054 I0053: _rnc_arg _ic _ungetc I0054: _index: I0063: ,#1 al, je I0062 cmpb I0063 I0061 I0062: I0061: _iswhite: ,#32 je I0072 ,#9 je I0072 ,#10 je I0072 ,#13 je I0072 I0071 I0072: I0071: _isgit: ,#48 jl I0083 ,#57 jg I0083 I0081 I0083: I0081: _tolower: ,#65 jl I0093 ,#90 jg I0093 ,#32 I0093: __doscanf __doscanf: ,#26 _1: I00A32 7 91 I00A86 99 I00A63 100 I00A36 111 I00A33 115 I00A74 117 I00A36 120 I00A37 _rnc_arg, _rnc_code, _rnc _ic,#-1 I00AA ,#-1 I00A5 I00AA: _iswhite je I00A9 ,#1 I00AA I00A9: cmpb I00AD I00AF I00AD: _ic jge I00A11 I00A5 I00A11: cmpb ,#37 je I00A14 I00A17: _ic _iswhite je I00A16 _rnc I00A17 I00A16: _ic, je I00A1A I00AF I00A1A: ,#1 _rnc I00AA I00A14: ,#1 -12(),#1 cmpb ,#42 I00A1D ,#1 -12() I00A1D: _isgit je I00A20 -1,#1 -1 I00A25: _isgit je I00A21 ,#1 0 mul -1 48 -1, I00A25 I00A20: -1 I00A21: _tolower 108 je I00A29 I00A2A I00A29: I00A2A: -1 -1 je I00A27 ,#1 I00A27: cmpb ,#99 je I00A2C I00A2F: _ic _iswhite je I00A2C _rnc I00A2F I00A2C: -20() I00A31 I00A33: ,#8 I00A34 I00A36: ,#10 I00A34 I00A37: , -1 je I00A3B -1,#2 jb I00A34 I00A3B: _ic,#48 I00A34 _rnc _ic _tolower 120 I00A3E -1 2 -1, -20(),#1 _rnc I00A34 I00A3E: _ugc _ic,#48 I00A34: -10() -1 I00A41 -1,#65535 I00A41: -1 je I00A44 _ic,#43 I00A44 _rnc I00A4C I00A44: -1 je I00A4C _ic,#45 I00A4C -10(),#1 _rnc I00A4C: -1 1 -1 -1, je I00A4B _ic _isgit je I00A4F _ic 48 , jle I00A4F _ic 48 _ic, I00A50 I00A4F: , I00A4B _ic _tolower 97 jl I00A4B _ic _tolower 102 jg I00A4B _ic _tolower -87 _ic, I00A50: cwd .mli4 _ic cwd adc , , _rnc -20(),#1 I00A4C I00A4B: -12() je I00A58 -10() je I00A5B sbb 0 , , I00A5B: -1 je I00A5E 4 4 10() 10(),#2 2, I00A58 I00A5E: 10() 10(),#2 I00A58: -20() je I00AF I00A32 I00A63: -1 I00A68 -1,#1 I00A68: -1 1 -1 -1, je I00A67 _ic jl I00A67 -12() je I00A6C 10() -2, 10() -2 _ic (), I00A6C: _rnc -20(),#1 I00A68 I00A67: -12() je I00A6F 10(),#2 I00A6F: -20() je I00A32 I00A32 I00A74: -1 I00A79 -1,#65535 I00A79: -1 1 -1 -1, je I00A78 _ic _iswhite I00A78 _ic jle I00A78 -12() je I00A7E 10() -2, 10() -2 _ic (), I00A7E: _rnc -20(),#1 I00A79 I00A78: -12() je I00A81 10() 10(),#2 I00A81: -20() je I00AF I00A32 I00A86: -1 I00A88 -1,#65535 I00A88: ,#1 cmpb ,#94 I00A8B -22(),#1 ,#1 I00A8C I00A8B: -22() I00A8C: -2, I00A8E: -2 cmpb ,#93 je I00A8D -2 cmpb je I00A8D -2,#1 I00A8E I00A8D: -2 cmpb I00A92 I00A5 I00A92: -2 I00A95: -1 1 -1 -1, je I00A94 _ic _iswhite I00A94 _ic jle I00A94 _ic _index -22() je I00A94 -12() je I00A9B 10() -2, 10() -2 _ic (), I00A9B: _rnc -20(),#1 I00A95 I00A94: -2 , ,#93 -12() je I00A9E 10() 10(),#2 I00A9E: -20() je I00AF I00A32 I00A31: #_1 .csb2 I00A32: ,#1 I00AA I00AF: _ic jl I00A5 _ugc I00A5: _rnc_code: .zerow 2/2 _rnc_arg: .zerow 2/2 _ic: .zerow 2/2 ungetc.s _ungetc _ungetc _ungetc: jl I0012 testb 4,#1 testb 4,#4 je I0013 -1 2,#1024 jl I0018 -1 I0018: 6() 8, I001b 8 , ,#1 I001b: 2 , 8 , ,#-1 4strcmp.s _strcmp _strcmp _strcmp: ,#1 I0012 I0013 ,#-1 access.s E_access _access _access: 33 _callm3 ,#8 0chdir.s ?_chr _chr _chr: 2 _callm3 ,#8 chmod.s @_chmod _chmod _chmod: 5 _callm3 ,#8 chown.s F_chown _chown _chown: 6 chroot.s G_chroot _chroot _chroot: 61 _callm3 ,#8 1creat.s A_creat _creat _creat: 8 _callm3 ,#8 dup.s ;_dup _dup _dup: 41 dup2.s M_dup2 _dup2 _dup2: 64 41 exec.sML /_execl _execle _execv _execn _nullptr _execl _execl: _nullptr _execle _execle: , I0023: ,#2 je I0022 I0023 I0022: _execv _execv: _nullptr : ,#1046 -103 -1040() -102, -102, I0043: -102 -102,#2 je I0046 -103 I0043 I0046: -102 -102,#2 je I0045 -1040() I0046 I0045: -104,#2 -1040() -103 3 mul -104 -1024(_) -1030(), -103 -1030() -1040() 0() jb I0049 -7 I0041 I0049: -102 -1032(), -103 -1032(),#2 -103 I004e: -103 -103, jge I004b -102 -1030() -104, -104 -1032() -1032(),#2 ,#2 -103, I00410: -103 je I004f -103 -103,#1 -1030() (),al -1030(),#1 0() -1030(), jb I00410 -7 I0041 I004f: -1030() -1030(),#1 -103 I004e I004b: -1032() -1032(),#2 -103 I00418: -1040() -103, jge I00415 -102 -1030() -104, -104 -1032() -1032(),#2 ,#2 -103, I0041a: -103 je I00419 -103 -103,#1 -1030() (),al -1030(),#1 0() -1030(), jb I0041a -7 I0041 I00419: -1030() -1030(),#1 -103 I00418 I00415: -1032() -1032(),#2 -102 -1030() -104 cwd iv -104 mul -104 -1042(), -102 -1042() 59 I0041: _execn _execn: -3() -1() 4 59 _nullptr _nullptr: .zerow 2/2 exit.s ;_exit _exit _exit: fork.s ;_fork _fork _fork: isatty.s s_isatty _isatty _isatty: ,#30 -30() _fstat -2 61440 8192 I0013 fstat.s E_fstat _fstat _fstat: 8 getegid.s i_getegid _getegid _getegid: 47 jge I0013 _M+4 getenv.s _getenv _getenv _getenv: ,#6 _environ , () 0 , ,#1 I0015 ,#1 I0016 I0016 I0015: 61 je I001c I001c: geteuid.s g_geteuid _geteuid _geteuid: 4 jge I0013 _M+4 getgid.s J_getgid _getgid _getgid: 47 getpass.s b_getpass _getpass _getpass: ,#8 _1: 10 _prints 9704 _ioctl ,#3088 9705 _ioctl 9 _pwdbuf _read al,_pwdbuf 10 _pwdbuf _read _pwdbuf ,#3096 9705 _ioctl _1 _prints _pwdbuf _pwdbuf: .zerow 10/2 close.s @_close _close _close: 6 getuid.s H_getuid _getuid _getuid: 4 ioctl.s _ioctl _ioctl _ioctl: ,#34 _1: I0018 4 29704 I0016 29705 I0014 29713 I0015 29714 I0017 _M+8, _M+4, I0012 I0014: al,2 , , al,3 -10(), , 8 2: sal 1 rcl 1 1: or -10() or , +2, 4 cwd _M+14, _M+14+2, 54 I0015: -1, -12(), -1, -1, al,2 -22(), -20(), al,3 -2, -2, al,4 -30(), -2, al,5 -3, -32(), 16 -1 -1 2: sal 1 rcl 1 1: 4 -1 -12() 2: sal #1 rcl #1 1: or or 8 -22() -20() 2: sal 1 rcl 1 1: or or -2 -2 2: sal #1 rcl #1 1: or or , +2, -3 -32() 2: sal 1 rcl 1 1: 8 -30() -2 2: sal #1 rcl #1 1: or or _M+14, _M+14+2, 54 54 8 +2 2: sar #1 rcr 1 1: 4 4 0 2,al +2 2: sar #1 rcr 1 1: 4 4 0 3,al _M+14 4, I0017: 54 4 +2 2: sar #1 rcr 1 1: 4 4 0 16 +2 2: sar #1 rcr 1 1: 4 4 0 8 +2 2: sar #1 rcr 1 1: 4 4 0 2,al +2 2: sar #1 rcr 1 1: 4 4 0 3,al 8 _M+14 _M+14+2 2: sar #1 rcr 1 1: 4 4 0 4,al 8 _M+14 _M+14+2 2: sar #1 rcr 1 1: 4 4 0 5,al I0018: ,#-1 _errno,#22 #_1 .csb2 kill.s >_kill _kill _kill: 37 link.s I_link _link _link: 9 lseek.s _lseek _lseek _lseek: _M+4, , +2, 10() _M+6, 9 je I0013 cwd +2 malloc.sa _malloc _free _realloc _grow: _top 2 15 65520 -2 , _top , jb I0012 _brk jge I0013 _top, _bottom , I0019: je I0016 65534 I0019 _top (), _top _malloc _malloc: ,#8 1 65534 2 , _bottom , _bottom I0026 _sbrk _bottom, _top, I0026: () 0 je I0025 testb ,#1 je I002C 65534 I0026 I002C: () , 0 je I002B testb ,#1 I002B I002C I002B: , ja I00210 mul , , jae I00213 I00213: or 1 2 I0021 I00210: I0026 I0025: _grow je I00216 _malloc I0021 I00216: I0021: _realloc _realloc: ,#12 -2 , 1 65534 2 , 65534 -10(), I0033: () , 0 je I0032 testb ,#1 I0032 I0033 I0032: , ja I0037 mul , , jae I003A or 1 I003B I003A: or 1 I003B: I0031 I0037: _malloc , I003D I0031 I003D: -10() _bcopy -12(), -12() 65534 I0031: _free _free: -2 , 65534 _top: .zerow 2/2 _bottom: .zerow 2/2 brk.s _brk _sbrk _brk _brk: 7 I0013 _M+18 _brkze, -1 _sbrk _sbrk: _brkze , _brkze , _brk 0 I0023 I0021 I0023: -1 I0021: brk2.s K_brk2 _brk2 _brk2: get_ze 66 _brksize.sBy -_brkze endbss, _brkze _brkze: endbss smknod.s F_mknod _mknod _mknod: 4 mktemp.s _mktemp _mktemp _mktemp: ,#6 _getpid , ,#1 ,#-1 ,#-1 88 I0015 10 cwd iv #48 ,dl 10 cwd iv I0016 I0015: getpid.s B_getpid _getpid _getpid: 0 mount.s L_mount _mount _mount: 1 open.s >_open _open _open: 5 _callm3 ,#8 perror.srG _perror error_message error_message: _1 _2 _3 _4 _5 _6 _7 _8 _9 _10 _11 _12 _13 _14 _15 _16 _17 _18 _19 _20 _21 _22 _23 _24 _25 _26 _27 _28 _29 _30 _31 _32 _33 _34 _35 _35: 25938 30067 29804 29728 28527 27680 29281 25959 _34: 24909 26740 24864 26482 28021 28261 116 _33: 29250 27503 28261 28704 28777 101 _32: 28500 8303 24941 31086 27680 28265 29547 _31: 25938 25697 28461 27758 8313 26982 25964 29472 29561 25972 109 _30: 27721 25964 24935 8300 25971 27493 _29: 29472 24944 25955 27680 26213 8308 28271 25632 30309 25449 101 _28: 26950 25964 29728 28527 27680 29281 25959 _27: 25940 29816 26144 27753 8293 30050 31091 _26: 8308 8289 31092 25968 29303 29801 29285 _25: 28500 8303 24941 31086 28448 25968 8302 26982 25964 115 _24: 26950 25964 29728 25185 25964 28448 25974 26226 28524 119 _23: 28233 24950 26988 8292 29281 30055 25965 29806 _22: 29513 24864 25632 29289 25445 28532 31090 _21: 8308 8289 26980 25970 29795 29295 121 _20: 29472 25461 8296 25956 26998 25955 _19: 29251 29551 11635 25956 26998 25955 27680 28265 107 _18: 26950 25964 25888 27000 29811 115 _17: 28493 28277 8308 25956 26998 25955 25120 29557 121 _16: 27714 25455 8299 25956 26998 25955 29216 29029 26997 25970 100 _15: 24898 8292 25697 29284 29541 115 _14: 25936 28018 29545 26995 28271 25632 28261 25961 100 _13: 8308 28261 30063 26727 25376 29295 101 _12: 27936 29295 8293 29296 25455 29541 25971 115 _11: 25376 26984 08 25970 110 _10: 24898 8292 26982 25964 28192 28021 25954 114 _9: 30789 25445 26144 29295 24941 8308 29285 28530 114 _8: 29249 8295 26988 29811 29728 28527 27680 28271 103 _7: 29472 25461 8296 25956 26998 25955 28448 8306 25697 29284 29541 115 _6: 12105 8271 29285 28530 114 _5: 28233 25972 29298 28789 25972 8292 31091 29811 28005 25376 27745 108 _4: 29472 25461 8296 29296 25455 29541 115 _3: 29472 25461 8296 26982 25964 28448 8306 26980 25970 29795 29295 121 _2: 8308 30575 25966 114 _1: 29253 28530 8306 _perror 48 _perror: _36: 28233 24950 26988 8292 29285 28274 2671 _37: 8250 _38: 10 _errno jl I0012 _errno,#34 jle I0013 4 _36 _write I0014 _slen _write _37 _write _errno sal 1 error_message _slen _errno sal 1 error_message _write _38 _write I0014: _slen: I0023: je I0022 I0023 I0022: 2pipe.s ~_pipe _pipe _pipe: 42 jl I0013 _M+4 (), _M+6 2, prints.ssyG 3_prints _Bufp _Buf _prints _Buf _Bufp _prints: ,#14 _1: I00119 2 99 I001e 115 I001f _Bufp,#_Buf , 37 je I0016 _put I0019: 48 jl I0018 57 jg I0018 48 0 mul , I0019 I0018: I001c I001e: ,#2 _put I001f: ,#2 -10(), -10() -12(), I00111: -10() -10(),#1 -13(),al je I00110 al,-13() _put 1 I00110: -10() -12() jle I0013 I00117: je I0013 32 _put 7 I00119: 37 _put _put I001c: #_1 .csb2 _Bufp _Buf _Buf _write _put: _Bufp,#_Buf+128 jae I0023 _Bufp al, _Bufp,#1 I0023: _Bufp: .zerow 2/2 _Buf: .zerow 128/2 read.s D_read _read _read: 3 setgid.s D_setgid _setgid _setgid: 46 setuid.s B_setuid _setuid _setuid: 3 sleep.s f_sleep _alfun: _sleep _sleep: _alfun 4 _gnal _alarm _pause alarm.s I_alarm _alarm _alarm: 7 pause.s ?_pause _pause _pause: 9 signal.sM _gnal _vectab _gnal _gnal: sal 1 2 _vectab sal 1 2 _vectab, _M+4, ,#1 I0013 I0014 _begg I0014: _M+14 48 jge I0017 I0017: _vectab _vectab: .zerow 32/2 fcatchsig.sj _begg _begg, _vectab, _M mtype = 2 _begg: ds es 18 _vectab _M+mtype back: _M+mtype es ds dummy i dummy: stat.s H_stat _stat _stat: 8 stime.s G_stime _stime _stime: 2 , +2 5 strcat.s }_strcat _strcat _strcat: ,#-1 ,#1 je I0015 I0016 I0015: Mstrcpy.s O_strcpy _strcpy _strcpy: ,#1 strlen.s F_strlen _strlen _strlen: strncat.s _strncat _strncat _strncat: je I0013 je I0015 I0016 I0015: ,#-1 I001a: ,#1 I0019 I0018 I0019: I001a I0018: ,#-1 strncmp.s _strncmp _strncmp _strncmp: jl I0012 ,#1 I0012 I0013 jge I001a I001a: ,#-1 strncpy.s _strncpy _strncpy _strncpy: I0015: , jge I0012 ,#1 I0013 I001a: , jge I0019 I001a I0019: I0015 sync.s >_sync _sync _sync: 36 time.s _time _time _time: ,#6 3 _M+2 jl I0012 je I0013 _M+2 _errno, -1 65535 , +2 , je I0017 2, I0017: times.s _times _times _times: 43 _M+4 _M+4+2 , 2, _M+8 _M+8+2 4, 6, _M+12 _M+12+2 8, 10, _M+16 _M+16+2 12, 14, umask.s A_umask _umask _umask: 60 umount.s E_umount _umount _umount: 2 _callm3 ,#8 +unlink.s E_unlink _unlink _unlink: 0 _callm3 ,#8 +utime.s }_utime _utime _utime: _M+4, 2 , +2 4 6 _M+14, _M+14+2 _M+18, 30 wait.s U_wait _wait _wait: 7 _M+4 (), +stderr.s `_std_err _std_err _std_err: ,#1 _write write.s A_write _write _write: 4 syslib.sG5O _sys_newmap _tell_fs _sys_times _sys_abort _sys_exec _sys_get _sys_g _sys_fork _sys_copy _sys_xit _sys_xit _sys_xit: -2 _sys_get _sys_get: -2 (), _sys_g _sys_g: _M+4, _M+6, _M+14, 3 -2 _sys_fork _sys_fork: 4 -2 _sys_exec _sys_exec: 7 -2 _sys_newmap _sys_newmap: 5 -2 _sys_copy _sys_copy: _1: 31091 24435 28515 31088 25376 28257 29735 29472 28261 100 2,#6 -2 _sendrec je I0073 32768 _1 _panic I0073: _sys_times _sys_times: 8 -2 _M+4 _M+4+2 , 2, _M+8 _M+8+2 4, 6, _M+12 _M+12+2 8, 10, _M+16 _M+16+2 12, 14, _sys_abort _sys_abort: 9 -2 _tell_fs _tell_fs: 10() call.sM _ _callm3 _callx _len _errno : _M+4, 10() _M+6, 12() _M+8, 1 , 1 _M+12, 1 _M+14, _callm3 _callm3: 10() _M+4, _M+6, 10() _M+8, ,# ,#14 jg I0023 I0026: je I0023 10() 10(),#1 (),al ,#1 I0026 I0023: _callx _callx: _M+2, _M _sendrec je I0033 I0031 I0033: _M+2 jge I0036 _M+2 _errno, -1 I0031 I0036: _M+2 I0031: _len _len: I0043: je I0042 I0043 I0042: _errno _errno: .zerow 2/2 ,atoi.s ]_atoi _atoi _atoi: ,#6 __c_, __c_,#32 je I0014 __c_,#9 je I0014 __c_,#13 je I0014 __c_,#10 je I0014 __c_,#12 I0012 I0014: 45 I001d ,#1 I001d: 48 ,#10 jae I001c 0 mul , I001d I001c: je I00110 I00110: __c_: .zerow 2/2 message.s _M _M _M: .zerow 24/2 sendrec.s _send, _receive, _sendrec SEND = 1 RECEIVE = 2 BOTH = 3 SYSVEC = 32 _send, _receive, _sendrec _send: *SEND L0 _receive: *RECEIVE L0 _sendrec: *BOTH L0 L0: int SYSVEC printk.s T _printk _printk _printk: ,#34 _1: I0011f 8 68 I00111 79 I00112 88 I00113 99 I00114 100 I001e 111 I001f 115 I00115 120 I00110 , 37 je I0016 _putc I0019: 48 jl I0018 57 jg I0018 48 0 mul , I0019 I0018: -1, I001c I001e: ,#2 cwd -1, -12(), ,#10 I001d I001f: ,#2 -10(), -10() -1, -12(), ,#8 I001d I00110: ,#2 -10(), -10() -1, -12(), , I001d I00111: -1 -1,#4 2 -1, -12() ,#10 -1 , I001d I00112: -1 -1,#4 2 -1, -12() ,#8 -1 , I001d I00113: -1 -1,#4 2 -1, -12() , -1 , I001d I00114: ,#2 _putc I00115: ,#2 -30(), -30() -32(), I00117: -30() -30(),#1 -33(),al je I00116 al,-33() _putc 7 I00116: -30() -32() jle I0013 I0011d: je I0013 32 _putc d I0011f: 37 _putc _putc I001c: #_1 .csb2 I001d: -2 -12() -1 bintoascii ,#8 , jle I00121 I00124: 1 32 _putc I00124 I00121: , I00129: jl I00126 al,-28(_) _putc I00129 I00126: bintoascii: ,#10 0 sbb 0 1f or 1: or I0023 10() ,#48 I0021 I0023: 0 sbb 0 1f je 1f 1: or jge I0026 ,#10 I0026 sbb 0 , , I0026: I002c: ,#12 jge I0029 10() I002c I0029: I002f: ,#10 I00211 0 .rmi4 10() ,dl 10() cwd sbb 0 .dvi4 , , I00211: ,#8 I00214 4 4 7 0 10() 3 2: sar 1 rcr 1 1: 65535 8191 , , I00214: , I00217 4 4 15 0 10() 4 2: sar 1 rcr 1 1: 65535 4095 , , I00217: 0 sbb 0 1f or 1: or I002f I0021c: jl I00219 10() I0021e I0021e 10() ,#32 I0021a I0021e: 10() 10 jge I00222 10() -10(), -10() 48 I00223 I00222: 10() -10(), -10() 55 I00223: I0021a: I0021c I00219: je I00225 45 10() I00225: I0021: abort.s 4_abort _abort _abort: 99 _exit itoa.s8 _itoa _itoa _itoa: ,#6 _next jge I0013 45 _qbuf _next _next I0016 48 _qbuf _next _next I0017 ,#10000 I0019: jle I0017 cwd iv I001b jle I001c I001b: 48 _qbuf _next _next ,#1 I001c: mul , 10 cwd iv I0019 I0017: _next _qbuf _qbuf _qbuf: .zerow 8/2 _next: .zerow 2/2 stb.s c___stb ___stb ___stb: jle I0013 I0017: ,#1 (),al ,#1 I0017 abs.s =_abs _abs _abs: jge I0013 0atol.s >_atol _atol _atol: ,#8 al,__ctype_+1 testb al,#8 45 I0019 ,#1 I0019: 48 , ,#10 jae I0018 #10 .mli4 , adc , , I0019 I0018: je I001c sbb 0 I001c: ctype.sM __ctype_ __ctype_ __ctype_: 8192 2056 2056 8200 2080 1040 1028 1028 1028 1028 4100 16705 16705 16705 16962 16962 16962 32 index.s o_index _index _index: I0014: al, I0013 I0014 4bcopy.s P_bcopy _bcopy _bcopy: (),al ,#1 getutil.sBy _get_base, _get_ze, _get_tot_mem _get_base, _get_ze, _get_tot_mem, endbss _get_base: ds _get_ze: endbss _get_tot_mem: cli es 8192 L1: es, seg es ()xA5A4 seg es () 0xA5A4 L2 4096 0xA000 L1 L2: es sti rand.s _rand _seed: 1,0 _rand _rand: #20077 838 _seed _seed+2 .mli4 12345 adc #0 65535 #32767 _seed, _seed+2, 4 4 _seed _seed+2 32767 0 rindex.s p_rindex _rindex _rindex: I0014: al, I0013 I0014 adi.s d.a .a: 2 L1 L1: 4 L9 adc L9: .trpvz and.s 9.and .and: sar 1 L1: () stow L1 cii.s .cii .cii: je L8 2 je L1 4 L7 2 L9 L8: () L7: 1 L9 2 L9 L8 L1: 4 L9 cwd () L9: .trpilin ecms.s V.cms .cms: sar 1 repe cmps je L1 L1: , cmu4.s j.cmu4 .cmu4: ja L1 jb L2 ja L1 je L3 L2: L3: L1: com.s 6.com .com: sar 1 L1: not () L1 csa2.s z.csa2 .csa2: () 2() 4() ja L1 sal 1 6(_) test jnz L2 L1: test jnz L2 .trpcase L2: csb2.s }.csb2 .csb2: lodw xchg lodw xchg L1: jl L2 lodw lodw L1 xchg L2: test jnz L3 .trpcase L3: cuu.s .ciu .cui .ciu: .cui: : je L8 2 je L1 4 L9 2 L9 L8: () L1: 4 L9 () L9: .trpilin .dup.s .define .dup | #bytes in cx .dup: pop bx | return address mov si,sp sub sp,cx mov di,sp sar cx,#1 rep movw jmp (bx) dvi.s .dvi .dvi: 2 L1 cwd iv L1: 4 L9 .dvi4 L9: .trpvz dvi4.s .dvi4 .dvi4 xl=6 xh=4 yl=10 yh=8 .dvi4: yl() yh() xl() xh() test jns L1 sbb *0 not L1:test jns L2 sbb *0 not L2:L4 test je L3 sbb *0 L3: 8 L4:test L5 v xchg v L5: testb bh,bh L6 bh,bl bl,ch ch,cl subb cl,cl ch,al subb cl,cl al,ah ah,dl dl,dh subb dh,dh jb L7 0xffff j L8 L6: L7:v L8: mul adc *0 mul adc *0 adc *0 L9:jns L10 adc adc 0 j L9 L10: test je L11 cl,ch ch,bl bl,bh bh,al L11: sdvu.s .dvu .dvu: 2 L1 v L1: 4 L9 .dvu4 L9: .trpvz dvu4.s .dvu4 yl=2 yh=4 xl=6 xh=8 .dvu4: yl() yh() or L7 xl() xh() v xchg v L9: 8 L7: xl() xh() 16 L1: shl 1 rcl #1 rcl 1 ja L3 jb L2 yl(), jbe L2 L3: L1 L9 L2: yl() sbb L1 L9 exg.s f.exg .exg: , rep movw sar 1 rep movw , fakfp.s;t .mlf,.dvf,.ngf,.adf,.sbf,.cmf,.zrf,.fif,.fef .mlf8,.dvf8,.ngf8,.adf8,.sbf8,.cmf8,.zrf8,.fif8,.fef8 .mlf4,.dvf4,.ngf4,.adf4,.sbf4,.cmf4,.zrf4,.fif4,.fef4 .cif,.cfi,.cuf,.cfu,.cff .mlf: .dvf: .ngf: .adf: .sbf: .cmf: .zrf: .fif: .fef: .mlf4: .dvf4: .ngf4: .adf4: .sbf4: .cmf4: .zrf4: .fif4: .fef4: .mlf8: .dvf8: .ngf8: .adf8: .sbf8: .cmf8: .zrf8: .fif8: .fef8: .cif: .cfi: .cuf: .cfu: .cff: .trpnofp gto.s .gto .gto: #4 ,#2 iaar.s P.iaar .iaar: #2 .unknown () mul 4() ilar.s C.ilar .ilar: #2 .unknown .lar2 (inn.s .inn .inn: #8 v xchg xchg jae L1 dl,bits() testb (),dl jz L1 L1: , bits: .byte 1,2,4,8,16,32,64,128 .ior.s ;.ior .ior: sar 1 L1: or () stow L1 gisar.s C.isar .isar: #2 .unknown .sar2 glar2.s v.lar2 .larL2: () 4() imul sar 1 jnb L1 ah,ah lodb L1: ,4() rep movw loi.s X.loi .loi: sar 1 jnb L1 ah,ah lodb L1: , rep movw mli.s p.mli .mli: 2 L1 mul L1: 4 L9 .mli4 L9: .trpvz mli4.s D.mli4 .mli4: mul mul mul ngi.s l.ngi .ngi: 2 L1 L1: 4 L9 sbb 0 L9: .trpvz nop.s .nop rck.s ?.rck .rck: () jl L2 2() jg L2 L2: .trprang rmi.s .rmi .rmi: 2 L1 cwd iv L1: 4 L9 .rmi4 () L9: .trpvz rmi4.s! .rmi4 yl=2 yh=4 xl=6 xh=8 .rmi4: yl() yh() cwd L7 jge L1 je L7 L1: xl() xh() jge L2 sbb L2: v xchg v L9: xh() jge L1a sbb 0 L1a: 8 L7: jge L1b yl() sbb L1b: xl() xh() jge L1c sbb L1c: 16 L1d: shl 1 rcl #1 rcl 1 ja L3 jb L2 yl(), jbe L2a L3: L1d L9 L2a: yl() sbb L1d L1e: L9 rmu.s! .rmu .rmu: 2 L1 iv L1: 4 L9 .rmu4 () L9: .trpvz rmu4.s! %.rmu4 yl=2 yh=4 xl=6 xh=8 .rmu4: yl() yh() or L7 L1: xl() xh() L2: v xchg v L9: 8 L7: xl() xh() 16 L1a: shl 1 rcl #1 rcl 1 ja L3 jb L2 yl(), jbe L2 L3: L1a L9 L2a: yl() sbb L1a L1c: L9 )rol.s" .rol .rol: 2 L1 rol cl () L1: 4 L9 L2 L3: sal 1 rcl 1 adc 0 L3 L2: () L9: .trpvz ror.s" .ror .ror: 2 L1 ror cl () L1: 4 L9 L2 32 L3: sar 1 rcr 1 L3 L2: () L9: .trpvz sar2.s# j.sar2 .sar2: () 4() imul sar 1 jnb L1 stob L1: rep movw , sbi.s# o.sbi .sbi: 2 L1 L1: 4 L9 sbc L9: .trpvz set.s# .set .set: L1: , ja L1 #8 v jae L2 dl,bits() orb (),dl L2: .trpset bits: .byte 1,2,4,8,16,32,64,128 :sli.s# .sli .sli: 2 L1 sal cl () L1: 4 L9 L2 L3: sal 1 rcl 1 L3 L2: () L9: .trpvz sri.s$ .sri .sri: 2 L1 sar cl () L1: 4 L9 L2 L3: sar 1 rcr 1 L3 L2: () L9: .trpvz sti.s$ L.sti .sti: sar 1 jnb L1 stob L1: rep movw , xor.s$ 9.xor .xor: sar 1 L1: () stow L1 eerror.s$ .error ! is trap number ! all registers must be saved ! because urn is posble ! May only be called with error no's <16 .error: 1 sal cl test (.ignmask) 2f .trp 2: unknown.s% .unknown .unknown: .trpilin ltrp.s;p .trpvz .trpilin .trpcase .trprang .trpset .trpnofp .trpheap .M: .zerow 24/2 .trpvz .trpilin .trpcase .trprang .trpset .trpnofp .trpheap .trpvz: .Mvz .Trp .trpilin: .Milin .Trp .trpcase: .Mcase .Trp .trprang: .Mrang .Trp .trpset: .Mset .Trp .trpnofp: .Mnofp .Trp .trpheap: .Mheap .Trp .Trp: 2 .Write _exit .Write: .M+2,#4 .M+4, .M+6, .M+10, .M .M 3 int 32 .Mvz: .asciz "Error: Divion by 0 \n" .Milin: .asciz "Illegal EM instruct'n\n" .Mcase: .asciz "Err in EM case instr \n" .Mrang: .asciz "Variable out of range\n" .Mset: .asciz "Err in EM set instr \n" .Mnofp: .asciz "Floating pt not impl.\n" .Mheap: .asciz "Heap overflow \n" csetjmp.ss\ _setjmp _longjmp _setjmp, _longjmp _setjmp: *2 , *2, *4, _longjmp: * * L1 L1: L2: *0() je L3 *0() or L2 hlt L3: *0() ,*2 *4 , eabort.cB~ abort() { exit(99); } abs.cB~ #abs(i){ return i < 0 ? -i : i; } access.cB~ #include "../include/lib.h" PUBLIC int access(name, mode) char *name; int mode; { return callm3(FS, ACCESS, mode, name); } alarm.cB~ #include "../include/lib.h" PUBLIC int alarm(sec) unsigned sec; { return callm1(MM, ALARM, (int) sec, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } atoi.cB~ #define isascii(c) (((unsigned) (c) & 0xFF) < 0200) /* For all the following functions the parameter must be ASCII */ #define _between(a,b,c) ((unsigned) ((b) - (a)) < (c) - (a)) #define isupper(c) _between('A', c, 'Z') #define islower(c) _between('a', c, 'z') #define isdigit(c) _between('0', c, '9') #define isprint(c) _between(' ', c, '~') /* The others are problematic as the parameter may only be evaluated once */ static _c_; /* used to store the evaluated parameter */ #define isalpha(c) (isupper(_c_ = (c)) || islower(_c_)) #define isalnum(c) (isalpha(c) || isdigit(_c_)) #define _isblank(c) ((_c_ = (c)) == ' ' || _c_ == '\t') #define isspace(c) (_isblank(c) || _c_=='\r' || _c_=='\n' || _c_=='\f') #define iscntrl(c) ((_c_ = (c)) == 0177 || _c_ < ' ') atoi(s) register char *s; { register int total = 0; register unsigned digit; register minus = 0; while (isspace(*s)) s++; if (*s == '-') { s++; minus = 1; } while ((digit = *s++ - '0') < 10) { total *= 10; total += digit; } return(minus ? -total : total); } atol.cB~ ?#include "../include/ctype.h" long atol(s) register char *s; { register long total = 0; register unsigned digit; register minus = 0; while (isspace(*s)) s++; if (*s == '-') { s++; minus = 1; } while ((digit = *s++ - '0') < 10) { total *= 10; total += digit; } return(minus ? -total : total); } tbcopy.cB~ tbcopy(old, new, n) register char *old, *new; int n; { /* Copy a block of data. */ while (n--) *new++ = *old++; } brk.cB~ #include "../include/lib.h" extern char *brksize; PUBLIC char *brk(addr) char *addr; { int k; k = callm1(MM, BRK, 0, 0, 0, addr, NIL_PTR, NIL_PTR); if (k == OK) { brksize = M.m2_p1; return(NIL_PTR); } else { return( (char*) -1 ); } } PUBLIC char *sbrk(incr) char *incr; { char *newsize, *oldsize; extern int endv, dorgv; oldsize = brksize; newsize = brksize + (int) incr; if (brk(newsize) == 0) return(oldsize); else return( (char *) -1 ); } brk2.cB~ #include "../include/lib.h" PUBLIC brk2() { char *p1, *p2; p1 = (char *) get_size(); callm1(MM, BRK2, 0, 0, 0, p1, p2, NIL_PTR); } _call.cB~ '#include "../include/lib.h" PUBLIC int errno; /* place where error numbers go */ PUBLIC int callm1(proc, syscallnr, int1, int2, int3, ptr1, ptr2, ptr3) int proc; /* FS or MM */ int syscallnr; /* which system call */ int int1; /* first integer parameter */ int int2; /* second integer parameter */ int int3; /* third integer parameter */ char *ptr1; /* pointer parameter */ char *ptr2; /* pointer parameter */ char *ptr3; /* pointer parameter */ { /* Send a message and get the response. The 'M.m_type' field of the * reply contains a value (>= 0) or an error code (<0). Use message format m1. */ M.m1_i1 = int1; M.m1_i2 = int2; M.m1_i3 = int3; M.m1_p1 = ptr1; M.m1_p2 = ptr2; M.m1_p3 = ptr3; return callx(proc, syscallnr); } PUBLIC int callm3(proc, syscallnr, int1, name) int proc; /* FS or MM */ int syscallnr; /* which system call */ int int1; /* integer parameter */ char *name; /* string */ { /* This form of system call is used for those calls that contain at most * one integer parameter along with a string. If the string fits in the * message, it is copied there. If not, a pointer to it is passed. */ register int k; register char *rp; k = len(name); M.m3_i1 = k; M.m3_i2 = int1; M.m3_p1 = name; rp = &M.m3_ca1[0]; if (k <= M3_STRING) while (k--) *rp++ = *name++; return callx(proc, syscallnr); } PUBLIC int callx(proc, syscallnr) int proc; /* FS or MM */ int syscallnr; /* which system call */ { /* Send a message and get the response. The 'M.m_type' field of the * reply contains a value (>= 0) or an error code (<0). */ int k; M.m_type = syscallnr; k = sendrec(proc, &M); if (k != OK) return(k); /* send itself failed */ if (M.m_type < 0) {errno = -M.m_type; return(-1);} return(M.m_type); } PUBLIC int len(s) register char *s; /* character string whose length is needed */ { /* Return the length of a character string, including the 0 at the end. */ register int k; k = 0; while (*s++ != 0) k++; return(k+1); /* return length including the 0-byte at end */ } chdir.cB~ j#include "../include/lib.h" PUBLIC int chdir(name) char *name; { return callm3(FS, CHDIR, 0, name); } chmod.cB~ }#include "../include/lib.h" PUBLIC int chmod(name, mode) char* name; int mode; { return callm3(FS, CHMOD, mode, name); } rchown.cC~ #include "../include/lib.h" PUBLIC int chown(name, owner, grp) char *name; int owner, grp; { return callm1(FS, CHOWN, len(name), owner, grp, name, NIL_PTR, NIL_PTR); } )chroot.cC~ l#include "../include/lib.h" PUBLIC int chroot(name) char* name; { return callm3(FS, CHROOT, 0, name); } cleanup.cC~ #include "../include/stdio.h" _cleanup() { register int i; for ( i = 0 ; i < NFILES ; i++ ) if ( _io_table[i] != NULL ) fflush(_io_table[i]); } Sclose.cC~ #include "../include/lib.h" PUBLIC int close(fd) int fd; { return callm1(FS, CLOSE, fd, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } creat.cC~ |#include "../include/lib.h" PUBLIC int creat(name, mode) char* name; int mode; { return callm3(FS, CREAT, mode, name); } crypt.cC~ pchar *crypt(pw, salt) char *pw, *salt; { static char buf[14]; register char bits[67]; register int i; register int j, rot; for (i=0; i < 67; i++) bits[i] = 0; if (salt[1] == 0) salt[1] = salt[0]; rot = (salt[1] * 4 - salt[0]) % 128; for (i=0; *pw && i < 8; i++) { for (j=0; j < 7; j++) bits[i+j*8] = (*pw & (1 << j) ? 1 : 0); bits[i+56] = (salt[i / 4] & (1 << (i % 4)) ? 1 : 0); pw++; } bits[64] = (salt[0] & 1 ? 1 : 0); bits[65] = (salt[1] & 1 ? 1 : 0); bits[66] = (rot & 1 ? 1 : 0); while (rot--) { for (i=65; i >= 0; i--) bits[i+1] = bits[i]; bits[0] = bits[66]; } for (i=0; i < 12; i++) { buf[i+2] = 0; for (j=0; j < 6; j++) buf[i+2] |= (bits[i*6+j] ? (1 << j) : 0); buf[i+2] += 48; if (buf[i+2] > '9') buf[i+2] += 7; if (buf[i+2] > 'Z') buf[i+2] += 6; } buf[0] = salt[0]; buf[1] = salt[1]; buf[13] = '\0'; return(buf); } ctype.cC~ l#include "../include/ctype.h" char _ctype_[] = { 0, _C, _C, _C, _C, _C, _C, _C, _C, _C, _S, _S, _S, _S, _S, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _C, _S, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _P, _N, _N, _N, _N, _N, _N, _N, _N, _N, _N, _P, _P, _P, _P, _P, _P, _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _U, _P, _P, _P, _P, _P, _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _P, _P, _P, _P, _C }; doprintf.cC~ #include "../include/stdio.h" #define MAXDIGITS 12 #define PRIVATE static /* This is the same as varargs , on BSD systems */ #define GET_ARG(arglist,mode) ((mode *)(arglist += sizeof(mode)))[-1] _doprintf(fp, format, args) FILE *fp; register char *format; int args; { register char *vl; int r, w1, w2, sign; long l; char c; char *s; char padchar; char a[MAXDIGITS]; vl = (char *) args; while ( *format != '\0') { if ( *format != '%' ) { putc( *format++, fp ); continue; } w1 = 0; w2 = 0; sign = 1; padchar = ' '; format++; if ( *format == '-' ) { sign = -1; format++; } if ( *format == '0') { padchar = '0'; format++; } while ( *format >='0' && *format <='     9' ){ w1 = 10 * w1 + sign * ( *format - '0' ); format++; } if ( *format == '.'){ format++; while ( *format >='0' && *format <='9' ){ w2 = 10 * w2 + ( *format - '0' ); format++; } } switch (*format) { case 'd': l = (long) GET_ARG(vl, int); r = 10; break; case 'u': l = (long) GET_ARG(vl, int); l = l & 0xFFFF; r = 10; break; case 'o': l = (long) GET_ARG(vl, int); if (l < 0) l = l & 0xFFFF; r = 8; break; case 'x': l = (long) GET_ARG(vl, int); if (l < 0) l = l & 0xFFFF; r = 16; break; case 'D': l = (long) GET_ARG(vl, long); r = 10; break; case 'O': l = (long) GET_ARG(vl, long); r = 8; break; case 'X': l = (long) GET_ARG(vl, long); r = 16; break; case 'c': c = (char) GET_ARG(vl, int); /* char's are casted back to int's */ putc( c, fp); format++; continue; case 's': s = GET_ARG(vl, char *); _printit(s,w1,w2,padchar,strlen(s),fp); format++; continue; default: putc('%',fp); putc(*format++,fp); continue; } _bintoascii (l, r, a); _printit(a,w1,w2,padchar,strlen(a),fp); format++; } } PRIVATE _bintoascii (num, radix, a) long num; int radix; char *a; { char b[MAXDIGITS]; int hit, negative; register int n, i; negative = 0; if (num == 0) { a[0] = '0'; a[1] = '\0'; return; } if (radix == 10) { if (num < 0) {num = -num; negative++;} } for (n = 0; n < MAXDIGITS; n++) b[n] = 0; n = 0; do { if (radix == 10) { b[n] = num % 10; num = (num - b[n]) / 10; } if (radix == 8) { b[n] = num & 0x7; num = (num >> 3) & 0x1FFFFFFF; } if (radix == 16) { b[n] = num & 0xF; num = (num >> 4) & 0x0FFFFFFF; } n++; } while (num != 0); /* Convert to ASCII. */ hit = 0; for (i = n - 1; i >= 0; i--) { if (b[i] == 0 && hit == 0) { b[i] = ' '; } else { if (b[i] < 10) b[i] += '0'; else b[i] += 'A' - 10; hit++; } } if (negative) b[n++] = '-'; for(i = n - 1 ; i >= 0 ; i-- ) *a++ = b[i]; *a = '\0'; } PRIVATE _printit(str, w1, w2, padchar, length, file) char *str; int w1, w2; char padchar; int length; FILE *file; { int len2 = length; int temp; if ( w2 > 0 && length > w2) len2 = w2; temp = len2; if ( w1 > 0 ) while ( w1 > len2 ){ --w1; putc(padchar,file); } while ( *str && ( len2-- != 0 )) putc(*str++, file); if ( w1 < 0 ) if ( padchar == '0' ){ putc('.',file); w1++; } while ( w1 < -temp ){ w1++; putc(padchar,file); } } dup.cC~ {#include "../include/lib.h" PUBLIC int dup(fd) int fd; { return callm1(FS, DUP, fd, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } 'dup2.cC~ #include "../include/lib.h" PUBLIC int dup2(fd, fd2) int fd, fd2; { return callm1(FS, DUP, fd+0100, fd2, 0, NIL_PTR, NIL_PTR, NIL_PTR); } exec.cC~ #include "../include/lib.h" char *nullptr[1]; /* the EXEC calls need a zero pointer */ PUBLIC int execl(name, arg0) char *name; char *arg0; { return execve(name, &arg0, nullptr); } PUBLIC int execle(name, argv) char *name, *argv; { char **p; p = (char **) &argv; while (*p++) /* null statement */ ; return execve(name, &argv, *p); } PUBLIC int execv(name, argv) char *name, *argv[]; { return execve(name, argv, nullptr); } PUBLIC int execve(name, argv, envp) char *name; /* pointer to name of file to be executed */ char *argv[]; /* pointer to argument array */ char *envp[]; /* pointer to environment */ { char stack[MAX_ISTACK_BYTES]; char **argorg, **envorg, *hp, **ap, *p; int i, nargs, nenvps, stackbytes, ptrsize, offset; /* Count the argument pointers and environment pointers. */ nargs = 0; nenvps = 0; argorg = argv; envorg = envp; while (*argorg++ != NIL_PTR) nargs++; while (*envorg++ != NIL_PTR) nenvps++; ptrsize = sizeof(NIL_PTR); /* Prepare to set up the initial stack. */ hp = &stack[(nargs + nenvps + 3) * ptrsize]; if (hp + nargs + nenvps >= &stack[MAX_ISTACK_BYTES]) return(E2BIG); ap = (char **) stack; *ap++ = (char *) nargs; /* Prepare the argument pointers and strings. */ for (i = 0; i < nargs; i++) { offset = hp - stack; *ap++ = (char *) offset; p = *argv++; while (*p) { *hp++ = *p++; if (hp >= &stack[MAX_ISTACK_BYTES]) return(E2BIG); } *hp++ = (char) 0; } *ap++ = NIL_PTR; /* Prepare the environment pointers and strings. */ for (i = 0; i < nenvps; i++) { offset = hp - stack; *ap++ = (char *) offset; p = *envp++; while (*p) { *hp++ = *p++; if (hp >= &stack[MAX_ISTACK_BYTES]) return(E2BIG); } *hp++ = (char) 0; } *ap++ = NIL_PTR; stackbytes = ( ( (hp - stack) + ptrsize - 1)/ptrsize) * ptrsize; return callm1(MM_PROC_NR, EXEC, len(name), stackbytes, 0,name, stack,NIL_PTR); } PUBLIC execn(name) char *name; /* pointer to file to be exec'd */ { /* Special version used when there are no args and no environment. This call * is principally used by INIT, to avoid having to allocate MAX_ISTACK_BYTES. */ char stack[4]; stack[0] = 0; stack[1] = 0; stack[2] = 0; stack[3] = 0; return callm1(MM_PROC_NR, EXEC, len(name), 4, 0, name, stack, NIL_PTR); } kexit.cC~ #include "../include/lib.h" PUBLIC int exit(status) int status; { return callm1(MM, EXIT, status, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } fclose.cC~ :#include "../include/stdio.h" fclose(fp) FILE *fp; { register int i; for (i=0; i= NFILES) return(EOF); fflush(fp); close(fp->_fd); if ( testflag(fp,IOMYBUF) && fp->_buf ) free( fp->_buf ); free(fp); return(NULL); } fflush.cD~ o#include "../include/stdio.h" fflush(iop) FILE *iop; { int count; if ( testflag(iop,UNBUFF) || !testflag(iop,WRITEMODE) ) return(0); if ( iop->_count <= 0 ) return(0); count = write(iop->_fd,iop->_buf,iop->_count); if ( count == iop->_count) { iop->_count = 0; iop->_ptr = iop->_buf; return(count); } iop->_flags |= _ERR; return(EOF); } )fgets.cD~ <#include "../include/stdio.h" char *fgets(str, n, file) char *str; unsigned n; FILE *file; { register int ch; register char *ptr; ptr = str; while ( --n > 0 && (ch = getc(file)) != EOF){ *ptr++ = ch; if ( ch == '\n') break; } if (ch == EOF && ptr==str) return(NULL); *ptr = '\0'; return(str); } fopen.cD~ #include "../include/stdio.h" #define PMODE 0644 FILE *fopen(name,mode) char *name , *mode; { register int i; FILE *fp; char *malloc(); int fd, flags = 0; for (i = 0; _io_table[i] != 0 ; i++) if ( i >= NFILES ) return(NULL); switch(*mode){ case 'w': flags |= WRITEMODE; if (( fd = creat (name,PMODE)) < 0) return(NULL); break; case 'a': flags |= WRITEMODE; if (( fd = open(name,1)) < 0 ) return(NULL); lseek(fd,0L,2); break; case 'r': flags |= READMODE; if (( fd = open (name,0)) < 0 ) return(NULL); break; default: return(NULL); } if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) return(NULL); fp->_count = 0; fp->_fd = fd; fp->_flags = flags; fp->_buf = malloc( BUFSIZ ); if ( fp->_buf == NULL ) fp->_flags |= UNBUFF; else fp->_flags |= IOMYBUF; fp->_ptr = fp->_buf; _io_table[i] = fp; return(fp); } Dfork.cD~ r#include "../include/lib.h" PUBLIC int fork() { return callm1(MM, FORK, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } fprintf.cD~ @#include "../include/stdio.h" fprintf (file, fmt, args) FILE *file; char *fmt; int args; { _doprintf (file, fmt, &args); if ( testflag(file,PERPRINTF) ) fflush(file); } printf (fmt, args) char *fmt; int args; { _doprintf (stdout, fmt, &args); if ( testflag(stdout,PERPRINTF) ) fflush(stdout); } fputs.cD~ q#include "../include/stdio.h" fputs(s,file) register char *s; FILE *file; { while ( *s ) putc(*s++,file); } ,fread.cD~ i#include "../include/stdio.h" fread(ptr, size, count, file) char *ptr; unsigned size, count; FILE *file; { register int c; unsigned ndone = 0, s; ndone = 0; if (size) while ( ndone < count ) { s = size; do { if ((c = getc(file)) != EOF) *ptr++ = (char) c; else return(ndone); } while (--s); ndone++; } return(ndone); } tfreopen.cE~ #include "../include/stdio.h" FILE *freopen(name,mode,stream) char *name,*mode; FILE *stream; { FILE *fopen(); if ( fclose(stream) != 0 ) return NULL; return fopen(name,mode); } fseek.cE~ i#include "../include/stdio.h" fseek(iop, offset, where) FILE *iop; long offset; { int count; long lseek(); long pos; iop->_flags &= ~(_EOF | _ERR); /* Clear both the end of file and error flags */ if ( testflag(iop,READMODE) ) { if ( where < 2 && iop->_buf && !testflag(iop,UNBUFF) ) { count = iop->_count; pos = offset; if ( where == 0 ) pos += count - lseek(fileno(iop), 0L,1) - 1; /*^^^ This caused the problem : - 1 corrected it */ else offset -= count; if ( count > 0 && pos <= count && pos >= iop->_buf - iop->_ptr ) { iop->_ptr += (int) pos; iop->_count -= (int) pos; return(0); } } pos = lseek(fileno(iop), offset, where); iop->_count = 0; } else if ( testflag(iop,WRITEMODE) ) { fflush(iop); pos = lseek(fileno(iop), offset, where); } return((pos == -1) ? -1 : 0 ); } fstat.cE~ #include "../include/lib.h" PUBLIC int fstat(fd, buffer) int fd; char *buffer; { int n; n = callm1(FS, FSTAT, fd, 0, 0, buffer, NIL_PTR, NIL_PTR); return(n); } ftell.cE~ #include "../include/stdio.h" long ftell(iop) FILE *iop; { long result; long lseek(); int adjust = 0; if ( testflag(iop,READMODE) ) adjust -= iop->_count; else if ( testflag(iop,WRITEMODE) && iop->_buf && !testflag(iop,UNBUFF)) adjust = iop->_ptr - iop->_buf; else return(-1); result = lseek(fileno(iop), 0L, 1); if ( result < 0 ) return ( result ); result += (long) adjust; return(result); } fwrite.cF~ F#include "../include/stdio.h" fwrite(ptr, size, count, file) unsigned size, count; char *ptr; FILE *file; { unsigned s; unsigned ndone = 0; if (size) while ( ndone < count ) { s = size; do { putc(*ptr++, file); if (ferror(file)) return(ndone); } while (--s); ndone++; } return(ndone); } getc.cF~ M#include "../include/stdio.h" getc(iop) FILE *iop; { int ch; if ( testflag(iop, (_EOF | _ERR ))) return (EOF); if ( !testflag(iop, READMODE) ) return (EOF); if (--iop->_count <= 0){ if ( testflag(iop, UNBUFF) ) iop->_count = read(iop->_fd,&ch,1); else iop->_count = read(iop->_fd,iop->_buf,BUFSIZ); if (iop->_count <= 0){ if (iop->_count == 0) iop->_flags |= _EOF; else iop->_flags |= _ERR; return (EOF); } else iop->_ptr = iop->_buf; } if (testflag(iop,UNBUFF)) return (ch & CMASK); else return (*iop->_ptr++ & CMASK); } lgetegid.cF~ #include "../include/lib.h" PUBLIC gid getegid() { int k; k = callm1(MM, GETGID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); if (k < 0) return ( (gid) k); return( (gid) M.m2_i1); } >getenv.cF~ #define NULL (char *) 0 char *getenv(name) register char *name; { extern char **environ; register char **v = environ, *p, *q; while ((p = *v) != NULL) { q = name; while (*p++ == *q) if (*q++ == 0) continue; if (*(p - 1) != '=') continue; return(p); } return(0); } ogeteuid.cF~ #include "../include/lib.h" PUBLIC uid geteuid() { int k; k = callm1(MM, GETUID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); if (k < 0) return ( (uid) k); return ((uid) M.m2_i1); } +getgid.cF~ #include "../include/lib.h" PUBLIC gid getgid() { int k; k = callm1(MM, GETGID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); return( (gid) k); } getgrent.cF~ /* * get entry from group file * * By: Patrick van Kleef */ #include "../include/grp.h" #define PRIVATE static PRIVATE char _gr_file[] = "/etc/group"; PRIVATE char _grbuf[256]; PRIVATE char _buffer[1024]; PRIVATE char *_pnt; PRIVATE char *_buf; PRIVATE int _gfd = -1; PRIVATE int _bufcnt; PRIVATE struct group grp; setgrent () { if (_gfd >= 0) lseek (_gfd, 0L, 0); else _gfd = open (_gr_file, 0); _bufcnt = 0; return (_gfd); } endgrent () { if (_gfd >= 0) close (_gfd); _gfd = -1; _bufcnt = 0; } static getline () { if (_gfd < 0 && setgrent () < 0) return (0); _buf = _grbuf; do { if (--_bufcnt <= 0){ if ((_bufcnt = read (_gfd, _buffer, 1024)) <= 0) return (0); else _pnt = _buffer; } *_buf++ = *_pnt++; } while (*_pnt != '\n'); _pnt++; _bufcnt--; *_buf = 0; _buf = _grbuf; return (1); } static skip_period () { while (*_buf != ':') _buf++; *_buf++ = '\0'; } struct group *getgrent () { if (getline () == 0) return (0); grp.name = _buf; skip_period (); grp.passwd = _buf; skip_period (); grp.gid = atoi (_buf); skip_period (); return (&grp); } struct group *getgrnam (name) char *name; { struct group *grp; setgrent (); while ((grp = getgrent ()) != 0) if (!strcmp (grp -> name, name)) break; endgrent (); if (grp != 0) return (grp); else return (0); } struct group *getgrgid (gid) int gid; { struct group *grp; setgrent (); while ((grp = getgrent ()) != 0) if (grp -> gid == gid) break; endgrent (); if (grp != 0) return (grp); else return (0); } getpass.cF~ #include "../h/sgtty.h" static char pwdbuf[9]; char * getpass(prompt) char *prompt; { int i = 0; struct sgttyb tty; prints(prompt); ioctl(0, TIOCGETP, &tty); tty.sg_flags = 06020; ioctl(0, TIOCSETP, &tty); i = read(0, pwdbuf, 9); while (pwdbuf[i - 1] != '\n') read(0, &pwdbuf[i - 1], 1); pwdbuf[i - 1] = '\0'; tty.sg_flags = 06030; ioctl(0, TIOCSETP, &tty); prints("\n"); return(pwdbuf); } getpid.cF~ v#include "../include/lib.h" PUBLIC int getpid() { return callm1(MM, GETPID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } getpwent.cF~ /* * get entry from password file * * By Patrick van Kleef * */ #include "../include/pwd.h" #define PRIVATE static PRIVATE char _pw_file[] = "/etc/passwd"; PRIVATE char _pwbuf[256]; PRIVATE char _buffer[1024]; PRIVATE char *_pnt; PRIVATE char *_buf; PRIVATE int _pw = -1; PRIVATE int _bufcnt; PRIVATE struct passwd pwd; setpwent() { if (_pw >= 0) lseek (_pw, 0L, 0); else _pw = open (_pw_file, 0); _bufcnt = 0; return (_pw); } endpwent () { if (_pw >= 0) close (_pw); _pw = -1; _bufcnt = 0; } static getline () { if (_pw < 0 && setpwent () < 0) return (0); _buf = _pwbuf; do { if (--_bufcnt <= 0){ if ((_bufcnt = read (_pw, _buffer, 1024)) <= 0) return (0); else _pnt = _buffer; } *_buf++ = *_pnt++; } while (*_pnt != '\n'); _pnt++; _bufcnt--; *_buf = 0; _buf = _pwbuf; return (1); } static skip_period () { while (*_buf != ':') _buf++; *_buf++ = '\0'; } struct passwd *getpwent () { if (getline () == 0) return (0); pwd.name = _buf; skip_period (); pwd.passwd = _buf; skip_period (); pwd.uid = atoi (_buf); skip_period (); pwd.gid = atoi (_buf); skip_period (); pwd.gecos = _buf; skip_period (); pwd.dir = _buf; skip_period (); pwd.shell = _buf; return (&pwd); } struct passwd *getpwnam (name) char *name; { struct passwd *pwd; setpwent (); while ((pwd = getpwent ()) != 0) if (!strcmp (pwd -> name, name)) break; endpwent (); if (pwd != 0) return (pwd); else return (0); } struct passwd *getpwuid (uid) int uid; { struct passwd *pwd; setpwent (); while ((pwd = getpwent ()) != 0) if (pwd -> uid == uid) break; endpwent (); if (pwd != 0) return (pwd); else return (0); } gets.cF~ #include "../include/stdio.h" char *gets(str) char *str; { register int ch; register char *ptr; ptr = str; while ((ch = getc(stdin)) != EOF && ch != '\n') *ptr++ = ch; if (ch == EOF && ptr==str) return(NULL); *ptr = '\0'; return(str); } agetuid.cF~ #include "../include/lib.h" PUBLIC uid getuid() { int k; k = callm1(MM, GETUID, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); return( (uid) k); } index.cG~ qchar *index(s, c) register char *s, c; { do { if (*s == c) return(s); } while (*s++ != 0); return(0); } Iioctl.cG~ #include "../include/lib.h" #include "../h/com.h" #include "../include/sgtty.h" PUBLIC int ioctl(fd, request, u) int fd; int request; union { struct sgttyb *argp; struct tchars *argt; } u; { int n; long erase, kill, intr, quit, xon, xoff, eof, brk; M.TTY_REQUEST = request; M.TTY_LINE = fd; switch(request) { case TIOCSETP: erase = u.argp->sg_erase & 0377; kill = u.argp->sg_kill & 0377; M.TTY_SPEK = (erase << 8) | kill; M.TTY_FLAGS = u.argp->sg_flags; n = callx(FS, IOCTL); return(n); case TIOCSETC: intr = u.argt->t_intrc & 0377; quit = u.argt->t_quitc & 0377; xon = u.argt->t_startc & 0377; xoff = u.argt->t_stopc & 0377; eof = u.argt->t_eofc & 0377; brk = u.argt->t_brkc & 0377; /* not used at the moment */ M.TTY_SPEK = (intr<<24) | (quit<<16) | (xon<<8) | (xoff<<0); M.TTY_FLAGS = (eof<<8) | (brk<<0); n = callx(FS, IOCTL); return(n); case TIOCGETP: n = callx(FS, IOCTL); u.argp->sg_erase = (M.TTY_SPEK >> 8) & 0377; u.argp->sg_kill = (M.TTY_SPEK >> 0) & 0377; u.argp->sg_flags = M.TTY_FLAGS; return(n); case TIOCGETC: n = callx(FS, IOCTL); u.argt->t_intrc = (M.TTY_SPEK >> 24) & 0377; u.argt->t_quitc = (M.TTY_SPEK >> 16) & 0377; u.argt->t_startc = (M.TTY_SPEK >> 8) & 0377; u.argt->t_stopc = (M.TTY_SPEK >> 0) & 0377; u.argt->t_eofc = (M.TTY_FLAGS >> 8) & 0377; u.argt->t_brkc = (M.TTY_FLAGS >> 8) & 0377; return(n); default: n = -1; errno = -(EINVAL); return(n); } } isatty.cG~ #include "../include/stat.h" int isatty(fd) int fd; { struct stat s; fstat(fd, &s); if ( (s.st_mode&S_IFMT) == S_IFCHR) return(1); else return(0); } >itoa.cG~ /* Integer to ASCII for signed decimal integers. */ static int next; static char qbuf[8]; char *itoa(n) int n; { register int r, k; int flag = 0; next = 0; if (n < 0) { qbuf[next++] = '-'; n = -n; } if (n == 0) { qbuf[next++] = '0'; } else { k = 10000; while (k > 0) { r = n/k; if (flag || r > 0) { qbuf[next++] = '0' + r; flag = 1; } n -= r * k; k = k/10; } } qbuf[next] = 0; return(qbuf); } kill.cG~ #include "../include/lib.h" PUBLIC int kill(proc, sig) int proc; /* which process is to be sent the signal */ int sig; /* signal number */ { return callm1(MM, KILL, proc, sig, 0, NIL_PTR, NIL_PTR, NIL_PTR); } link.cG~ #include "../include/lib.h" PUBLIC int link(name, name2) char *name, *name2; { return callm1(FS, LINK, len(name), len(name2), 0, name, name2, NIL_PTR); } lseek.cG~ #include "../include/lib.h" PUBLIC long lseek(fd, offset, whence) int fd; long offset; int whence; { int k; M.m2_i1 = fd; M.m2_l1 = offset; M.m2_i2 = whence; k = callx(FS, LSEEK); if (k != OK) return( (long) k); /* send itself failed */ return(M.m2_l1); } malloc.cG~  #define CLICK_SIZE 16 typedef unsigned short vir_bytes; extern bcopy(); #define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1)) #define BUSY 1 #define NEXT(p) (* (char **) (p)) extern char *sbrk(); static char *bottom, *top; static grow(len) unsigned len; { register char *p; p = (char *) ALIGN((vir_bytes) top + sizeof(char *) + len, CLICK_SIZE) - sizeof(char *); if (p < top || brk(p) < 0) return(0); top = p; for (p = bottom; NEXT(p) != 0; p = (char *) (* (vir_bytes *) p & ~BUSY)) ; NEXT(p) = top; NEXT(top) = 0; return(1); } char *malloc(size) unsigned size; { register char *p, *next, *new; register unsigned len = ALIGN(size, sizeof(char *)) + sizeof(char *); if ((p = bottom) == 0) { top = bottom = p = sbrk(sizeof(char *)); NEXT(top) = 0; } while ((next = NEXT(p)) != 0) if ((vir_bytes) next & BUSY) /* already in use */ p = (char *) ((vir_bytes) next & ~BUSY); else { while ((new = NEXT(next)) != 0 && !((vir_bytes) new & BUSY)) next = new; if (next - p >= len) { /* fits */ if ((new = p + len) < next) /* too big */ NEXT(new) = next; NEXT(p) = (char *) ((vir_bytes) new | BUSY); return(p + sizeof(char *)); } p = next; } return grow(len) ? malloc(size) : 0; } char *realloc(old, size) char *old; unsigned size; { register char *p = old - sizeof(char *), *next, *new; register unsigned len = ALIGN(size, sizeof(char *)) + sizeof(char *), n; next = (char *) (* (vir_bytes *) p & ~BUSY); n = next - old; /* old size */ while ((new = NEXT(next)) != 0 && !((vir_bytes) new & BUSY)) next = new; if (next - p >= len) { /* does it still fit */ if ((new = p + len) < next) { /* even too big */ NEXT(new) = next; NEXT(p) = (char *) ((vir_bytes) new | BUSY); } else NEXT(p) = (char *) ((vir_bytes) next | BUSY); return(old); } if ((new = malloc(size)) == 0) /* it didn't fit */ return(0); bcopy(old, new, n); /* n < size */ * (vir_bytes *) p &= ~BUSY; return(new); } free(p) char *p; { * (vir_bytes *) (p - sizeof(char *)) &= ~BUSY; } !message.cH~ ;#include "../h/const.h" #include "../h/type.h" message M; mknod.cH~ #include "../include/lib.h" PUBLIC int mknod(name, mode, addr) char *name; int mode, addr; { return callm1(FS, MKNOD, len(name), mode, addr, name, NIL_PTR, NIL_PTR); } )mktemp.cH~ /* mktemp - make a name for a temporary file */ char *mktemp(template) char *template; { int pid, k; char *p; pid = getpid(); /* get process id as semi-unique number */ p = template; while (*p++) ; /* find end of string */ p--; /* backup to last character */ /* Replace XXXXXX at end of template with pid. */ while (*--p == 'X') { *p = '0' + (pid % 10); pid = pid/10; } return(template); } mount.cH~ #include "../include/lib.h" PUBLIC int mount(special, name, rwflag) char *name, *special; int rwflag; { return callm1(FS, MOUNT, len(special), len(name), rwflag, special, name, NIL_PTR); } open.cH~ z#include "../include/lib.h" PUBLIC int open(name, mode) char* name; int mode; { return callm3(FS, OPEN, mode, name); } pause.cH~ t#include "../include/lib.h" PUBLIC int pause() { return callm1(MM, PAUSE, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } perror.cH~ /* perror(s) print the current error message. */ #include "../h/error.h" extern int errno; char *error_message[NERROR+1] = { "Error 0", "Not owner", "No such file or directory", "No such process", "Interrupted system call", "I/O error", "No such device or address", "Arg list too long", "Exec format error", "Bad file number", "No children", "No more processes", "Not enough core", "Permission denied", "Bad address", "Block device required", "Mount device busy", "File exists", "Cross-device link", "No such device", "Not a directory", "Is a directory", "Invalid argument", "File table overflow", "Too many open files", "Not a typewriter", "Text file busy", "File too large", "No space left on device", "Illegal seek", "Read-only file system", "Too many links", "Broken pipe", "Math argument", "Result too large" }; perror(s) char *s; { if (errno < 0 || errno > NERROR) { write(2, "Invalid errno\n", 14); } else { write(2, s, slen(s)); write(2, ": ", 2); write(2, error_message[errno], slen(error_message[errno])); write(2, "\n", 1); } } static int slen(s) char *s; { int k = 0; while (*s++) k++; return(k); } pipe.cH~ #include "../include/lib.h" PUBLIC int pipe(fild) int fild[2]; { int k; k = callm1(FS, PIPE, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); if (k >= 0) { fild[0] = M.m1_i1; fild[1] = M.m1_i2; return(0); } else return(k); } printdat.cI~ s#include "../include/stdio.h" char __stdin[BUFSIZ]; char __stdout[BUFSIZ]; struct _io_buf _stdin = { 0, 0, READMODE , __stdin, __stdin }; struct _io_buf _stdout = { 1, 0, WRITEMODE + PERPRINTF, __stdout, __stdout }; struct _io_buf _stderr = { 2, 0, WRITEMODE + UNBUFF, NULL, NULL }; struct _io_buf *_io_table[NFILES] = { &_stdin, &_stdout, &_stderr, 0 }; sprintk.cI~ Y/* This is a special version of printf. It is used only by the operating * system itself, and should never be included in user programs. The name * printk never appears in the operating system, because the macro printf * has been defined as printk there. */ #define MAXDIGITS 12 printk(s, arglist) char *s; int *arglist; { int w, k, r, *valp; unsigned u; long l, *lp; char a[MAXDIGITS], *p, *p1, c; valp = (int *) &arglist; while (*s != '\0') { if (*s != '%') { putc(*s++); continue; } w = 0; s++; while (*s >= '0' && *s <= '9') { w = 10 * w + (*s - '0'); s++; } lp = (long *) valp; switch(*s) { case 'd': k = *valp++; l = k; r = 10; break; case 'o': k = *valp++; u = k; l = u; r = 8; break; case 'x': k = *valp++; u = k; l = u; r = 16; break; case 'D': l = *lp++; r = 10; valp = (int *) lp; break; case 'O': l = *lp++; r = 8; valp = (int *) lp; break; case 'X': l = *lp++; r = 16; valp = (int *) lp; break; case 'c': k = *valp++; putc(k); s++; continue; case 's': p = (char *) *valp++; p1 = p; while(c = *p++) putc(c); s++; if ( (k = w - (p-p1-1)) > 0) while (k--) putc(' '); continue; default: putc('%'); putc(*s++); continue; } k = bintoascii(l, r, a); if ( (r = w - k) > 0) while(r--) putc(' '); for (r = k - 1; r >= 0; r--) putc(a[r]); s++; } } static int bintoascii(num, radix, a) long num; int radix; char a[MAXDIGITS]; { int i, n, hit, negative; negative = 0; if (num == 0) {a[0] = '0'; return(1);} if (num < 0 && radix == 10) {num = -num; negative++;} for (n = 0; n < MAXDIGITS; n++) a[n] = 0; n = 0; do { if (radix == 10) {a[n] = num % 10; num = (num -a[n])/10;} if (radix == 8) {a[n] = num & 0x7; num = (num >> 3) & 0x1FFFFFFF;} if (radix == 16) {a[n] = num & 0xF; num = (num >> 4) & 0x0FFFFFFF;} n++; } while (num != 0); /* Convert to ASCII. */ hit = 0; for (i = n - 1; i >= 0; i--) { if (a[i] == 0 && hit == 0) { a[i] = ' '; } else { if (a[i] < 10) a[i] += '0'; else a[i] += 'A' - 10; hit++; } } if (negative) a[n++] = '-'; return(n); } Gprints.cI~ /* prints() is like printf(), except that it can only handle %s and %c. It * cannot print any of the numeric types such as %d, %o, etc. It has the * advantage of not requiring the runtime code for converting binary numbers * to ASCII, which saves 1K bytes in the object program. Since many of the * small utilities do not need numeric printing, they all use prints. */ #define TRUNC_SIZE 128 char Buf[TRUNC_SIZE], *Bufp; #define OUT 1 prints(s, arglist) register char *s; int *arglist; { register w; int k, r, *valp; char *p, *p1, c; Bufp = Buf; valp = (int *) &arglist; while (*s != '\0') { if (*s != '%') { put(*s++); continue; } w = 0; s++; while (*s >= '0' && *s <= '9') { w = 10 * w + (*s - '0'); s++; } switch(*s) { case 'c': k = *valp++; put(k); s++; continue; case 's': p = (char *) *valp++; p1 = p; while(c = *p++) put(c); s++; if ( (k = w - (p-p1-1)) > 0) while (k--) put(' '); continue; default: put('%'); put(*s++); continue; } } write(OUT, Buf, Bufp - Buf); /* write everything in one blow. */ } static put(c) char c; { if (Bufp < &Buf[TRUNC_SIZE]) *Bufp++ = c; } +putc.cI~ #include "../include/stdio.h" putc(ch, iop) char ch; FILE *iop; { int n, didwrite = 0; if (testflag(iop, (_ERR | _EOF))) return (EOF); if ( !testflag(iop,WRITEMODE)) return(EOF); if ( testflag(iop,UNBUFF)){ n = write(iop->_fd,&ch,1); iop->_count = 1; didwrite++; } else{ *iop->_ptr++ = ch; if ((++iop->_count) >= BUFSIZ && !testflag(iop,STRINGS) ){ n = write(iop->_fd,iop->_buf,iop->_count); iop->_ptr = iop->_buf; didwrite++; } } if (didwrite){ if (n<=0 || iop->_count != n){ if (n < 0) iop->_flags |= _ERR; else iop->_flags |= _EOF; return (EOF); } iop->_count=0; } return(0); } rand.cI~ |static long seed = 1L; int rand() { seed = (1103515245L * seed + 12345) & 0x7FFFFFFF; return((int) (seed & 077777)); } read.cI~ #include "../include/lib.h" PUBLIC int read(fd, buffer, nbytes) int fd; char *buffer; int nbytes; { int n; n = callm1(FS, READ, fd, nbytes, 0, buffer, NIL_PTR, NIL_PTR); return(n); } regexp.cI~ l/* * regcomp and regexec -- regsub and regerror are elsewhere * * Copyright (c) 1986 by University of Toronto. * Written by Henry Spencer. Not derived from licensed software. * * Permission is granted to anyone to use this software for any * purpose on any computer system, and to redistribute it freely, * subject to the following restrictions: * * 1. The author is not responsible for the consequences of use of * this software, no matter how awful, even if they arise * from defects in it. * * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * * Beware that some of this code is subtly aware of the way operator * precedence is structured in regular expressions. Serious changes in * regular-expression syntax might require a total rethink. * * The third parameter to regexec was added by Martin C. Atkins. * Andy Tanenbaum also made some changes. */ #include "../include/stdio.h" #include "../include/regexp.h" /* * The first byte of the regexp internal "program" is actually this magic * number; the start node begins in the second byte. */ #define MAGIC 0234 /* * The "internal use only" fields in regexp.h are present to pass info from * compile to execute that permits the execute phase to run lots faster on * simple cases. They are: * * regstart char that must begin a match; '\0' if none obvious * reganch is the match anchored (at beginning-of-line only)? * regmust string (pointer into program) that match must include, or NULL * regmlen length of regmust string * * Regstart and reganch permit very fast decisions on suitable starting points * for a match, cutting down the work a lot. Regmust permits fast rejection * of lines that cannot possibly match. The regmust tests are costly enough * that regcomp() supplies a regmust only if the r.e. contains something * potentially expensive (at present, the only such thing detected is * or + * at the start of the r.e., which can involve a lot of backup). Regmlen is * supplied because the test in regexec() needs it and regcomp() is computing * it anyway. */ /* * Structure for regexp "program". This is essentially a linear encoding * of a nondeterministic finite-state machine (aka syntax charts or * "railroad normal form" in parsing technology). Each node is an opcode * plus a "next" pointer, possibly plus an operand. "Next" pointers of * all nodes except BRANCH implement concatenation; a "next" pointer with * a BRANCH on both ends of it is connecting two alternatives. (Here we * have one of the subtle syntax dependencies: an individual BRANCH (as * opposed to a collection of them) is never concatenated with anything * because of operator precedence.) The operand of some types of node is * a literal string; for others, it is a node leading into a sub-FSM. In * particular, the operand of a BRANCH node is the first node of the branch. * (NB this is *not* a tree structure: the tail of the branch connects * to the thing following the set of BRANCHes.) The opcodes are: */ /* definition number opnd? meaning */ #define END 0 /* no End of program. */ #define BOL 1 /* no Match "" at beginning of line. */ #define EOL 2 /* no Match "" at end of line. */ #define ANY 3 /* no Match any one character. */ #define ANYOF 4 /* str Match any character in this string. */ #define ANYBUT 5 /* str Match any character not in this string. */ #define BRANCH 6 /* node Match this alternative, or the next... */ #define BACK 7 /* no Match "", "next" ptr points backward. */ #define EXACTLY 8 /* str Match this string. */ #define NOTHING 9 /* no Match empty string. */ #define STAR 10 /* node Match this (simple) thing 0 or more times. */ #define PLUS 11 /* node Match this (simple) thing 1 or more times. */ #define OPEN 20 /* no Mark this point in input as start of #n. */ /* OPEN+1 is number 1, etc. */ #define CLOSE 30 /* no Analogous to OPEN. */ /* * Opcode notes: * * BRANCH The set of branches constituting a single choice are hooked * together with their "next" pointers, since precedence prevents * anything being concatenated to any individual branch. The * "next" pointer of the last BRANCH in a choice points to the * thing following the whole choice. This is also where the * final "next" pointer of each individual branch points; each * branch starts with the operand node of a BRANCH node. * * BACK Normal "next" pointers all implicitly point forward; BACK * exists to make loop structures possible. * * STAR,PLUS '?', and complex '*' and '+', are implemented as circular * BRANCH structures using BACK. Simple cases (one character * per match) are implemented with STAR and PLUS for speed * and to minimize recursive plunges. * * OPEN,CLOSE ...are numbered at compile time. */ /* * A node is one char of opcode followed by two chars of "next" pointer. * "Next" pointers are stored as two 8-bit pieces, high order first. The * value is a positive offset from the opcode of the node containing it. * An operand, if any, simply follows the node. (Note that much of the * code generation knows about this implicit relationship.) * * Using two bytes for the "next" pointer is vast overkill for most things, * but allows patterns to get big without disasters. */ #define OP(p) (*(p)) #define NEXT(p) (((*((p)+1)&0377)<<8) + *((p)+2)&0377) #define OPERAND(p) ((p) + 3) /* * Utility definitions. */ #ifndef CHARBITS #define UCHARAT(p) ((int)*(unsigned char *)(p)) #else #define UCHARAT(p) ((int)*(p)&CHARBITS) #endif #define FAIL(m) { regerror(m); return(NULL); } #define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?') #define META "^$.[()|?+*\\" /* * Flags to be passed up and down. */ #define HASWIDTH 01 /* Known never to match null string. */ #define SIMPLE 02 /* Simple enough to be STAR/PLUS operand. */ #define SPSTART 04 /* Starts with * or +. */ #define WORST 0 /* Worst case. */ /* * Global work variables for regcomp(). */ static char *regparse; /* Input-scan pointer. */ static int regnpar; /* () count. */ static char regdummy; static char *regcode; /* Code-emit pointer; ®dummy = don't. */ static long regsize; /* Code size. */ /* * Forward declarations for regcomp()'s friends. */ #ifndef STATIC #define STATIC static #endif STATIC char *reg(); STATIC char *regbranch(); STATIC char *regpiece(); STATIC char *regatom(); STATIC char *regnode(); STATIC char *regnext(); STATIC void regc(); STATIC void reginsert(); STATIC void regtail(); STATIC void regoptail(); STATIC int strcspn(); /* - regcomp - compile a regular expression into internal code * * We can't allocate space until we know how big the compiled form will be, * but we can't compile it (and thus know how big it is) until we've got a * place to put the code. So we cheat: we compile it twice, once with code * generation turned off and size counting turned on, and once "for real". * This also means that we don't allocate space until we are sure that the * thing really will compile successfully, and we never have to move the * code and thus invalidate pointers into it. (Note that it has to be in * one piece because free() must be able to free it all.) * * Beware that the optimization-preparation code in here knows about some * of the structure of the compiled regexp. */ regexp * regcomp(exp) char *exp; { register regexp *r; register char *scan; register char *longest; register int len; int flags; extern char *malloc(); if (exp == NULL) FAIL("NULL argument"); /* First pass: determine size, legality. */ regparse = exp; regnpar = 1; regsize = 0L; regcode = ®dummy; regc(MAGIC); if (reg(0, &flags) == NULL) return(NULL); /* Small enough for pointer-storage convention? */ if (regsize >= 32767L) /* Probably could be 65535L. */ FAIL("regexp too big"); /* Allocate space. */ r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize); if (r == NULL) FAIL("out of space"); /* Second pass: emit code. */ regparse = exp; regnpar = 1; regcode = r->program; regc(MAGIC); if (reg(0, &flags) == NULL) return(NULL); /* Dig out information for optimizations. */ r->regstart = '\0'; /* Worst-case defaults. */ r->reganch = 0; r->regmust = NULL; r->regmlen = 0; scan = r->program+1; /* First BRANCH. */ if (OP(regnext(scan)) == END) { /* Only one top-level choice. */ scan = OPERAND(scan); /* Starting-point info. */ if (OP(scan) == EXACTLY) r->regstart = *OPERAND(scan); else if (OP(scan) == BOL) r->reganch++; /* * If there's something expensive in the r.e., find the * longest literal string that must appear and make it the * regmust. Resolve ties in favor of later strings, since * the regstart check works with the beginning of the r.e. * and avoiding duplication strengthens checking. Not a * strong reason, but sufficient in the absence of others. */ if (flags&SPSTART) { longest = NULL; len = 0; for (; scan != NULL; scan = regnext(scan)) if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) { longest = OPERAND(scan); len = strlen(OPERAND(scan)); } r->regmust = longest; r->regmlen = len; } } return(r); } /* - reg - regular expression, i.e. main body or parenthesized thing * * Caller must absorb opening parenthesis. * * Combining parenthesis handling with the base level of regular expression * is a trifle forced, but the need to tie the tails of the branches to what * follows makes it hard to avoid. */ static char * reg(paren, flagp) int paren; /* Parenthesized? */ int *flagp; { register char *ret; register char *br; register char *ender; register int parno; int flags; *flagp = HASWIDTH; /* Tentatively. */ /* Make an OPEN node, if parenthesized. */ if (paren) { if (regnpar >= NSUBEXP) FAIL("too many ()"); parno = regnpar; regnpar++; ret = regnode(OPEN+parno); } else ret = NULL; /* Pick up the branches, linking them together. */ br = regbranch(&flags); if (br == NULL) return(NULL); if (ret != NULL) regtail(ret, br); /* OPEN -> first. */ else ret = br; if (!(flags&HASWIDTH)) *flagp &= ~HASWIDTH; *flagp |= flags&SPSTART; while (*regparse == '|') { regparse++; br = regbranch(&flags); if (br == NULL) return(NULL); regtail(ret, br); /* BRANCH -> BRANCH. */ if (!(flags&HASWIDTH)) *flagp &= ~HASWIDTH; *flagp |= flags&SPSTART; } /* Make a closing node, and hook it on the end. */ ender = regnode((paren) ? CLOSE+parno : END); regtail(ret, ender); /* Hook the tails of the branches to the closing node. */ for (br = ret; br != NULL; br = regnext(br)) regoptail(br, ender); /* Check for proper termination. */ if (paren && *regparse++ != ')') { FAIL("unmatched ()"); } else if (!paren && *regparse != '\0') { if (*regparse == ')') { FAIL("unmatched ()"); } else FAIL("junk on end"); /* "Can't happen". */ /* NOTREACHED */ } return(ret); } /* - regbranch - one alternative of an | operator * * Implements the concatenation operator. */ static char * regbranch(flagp) int *flagp; { register char *ret; register char *chain; register char *latest; int flags; *flagp = WORST; /* Tentatively. */ ret = regnode(BRANCH); chain = NULL; while (*regparse != '\0' && *regparse != '|' && *regparse != ')') { latest = regpiece(&flags); if (latest == NULL) return(NULL); *flagp |= flags&HASWIDTH; if (chain == NULL) /* First piece. */ *flagp |= flags&SPSTART; else regtail(chain, latest); chain = latest; } if (chain == NULL) /* Loop ran zero times. */ (void) regnode(NOTHING); return(ret); } /* - regpiece - something followed by possible [*+?] * * Note that the branching code sequences used for ? and the general cases * of * and + are somewhat optimized: they use the same NOTHING node as * both the endmarker for their branch list and the body of the last branch. * It might seem that this node could be dispensed with entirely, but the * endmarker role is not redundant. */ static char * regpiece(flagp) int *flagp; { register char *ret; register char op; register char *next; int flags; ret = regatom(&flags); if (ret == NULL) return(NULL); op = *regparse; if (!ISMULT(op)) { *flagp = flags; return(ret); } if (!(flags&HASWIDTH) && op != '?') FAIL("*+ operand could be empty"); *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH); if (op == '*' && (flags&SIMPLE)) reginsert(STAR, ret); else if (op == '*') { /* Emit x* as (x&|), where & means "self". */ reginsert(BRANCH, ret); /* Either x */ regoptail(ret, regnode(BACK)); /* and loop */ regoptail(ret, ret); /* back */ regtail(ret, regnode(BRANCH)); /* or */ regtail(ret, regnode(NOTHING)); /* null. */ } else if (op == '+' && (flags&SIMPLE)) reginsert(PLUS, ret); else if (op == '+') { /* Emit x+ as x(&|), where & means "self". */ next = regnode(BRANCH); /* Either */ regtail(ret, next); regtail(regnode(BACK), ret); /* loop back */ regtail(next, regnode(BRANCH)); /* or */ regtail(ret, regnode(NOTHING)); /* null. */ } else if (op == '?') { /* Emit x? as (x|) */ reginsert(BRANCH, ret); /* Either x */ regtail(ret, regnode(BRANCH)); /* or */ next = regnode(NOTHING); /* null. */ regtail(ret, next); regoptail(ret, next); } regparse++; if (ISMULT(*regparse)) FAIL("nested *?+"); return(ret); } /* - regatom - the lowest level * * Optimization: gobbles an entire sequence of ordinary characters so that * it can turn them into a single node, which is smaller to store and * faster to run. Backslashed characters are exceptions, each becoming a * separate node; the code is simpler that way and it's not worth fixing. */ static char * regatom(flagp) int *flagp; { register char *ret; int flags; *flagp = WORST; /* Tentatively. */ switch (*regparse++) { case '^': ret = regnode(BOL); break; case '$': ret = regnode(EOL); break; case '.': ret = regnode(ANY); *flagp |= HASWIDTH|SIMPLE; break; case '[': { register int class; register int classend; if (*regparse == '^') { /* Complement of range. */ ret = regnode(ANYBUT); regparse++; } else ret = regnode(ANYOF); if (*regparse == ']' || *regparse == '-') regc(*regparse++); while (*regparse != '\0' && *regparse != ']') { if (*regparse == '-') { regparse++; if (*regparse == ']' || *regparse == '\0') regc('-'); else { class = UCHARAT(regparse-2)+1; classend = UCHARAT(regparse); if (class > classend+1) FAIL("invalid [] range"); for (; class <= classend; class++) regc(class); regparse++; } } else regc(*regparse++); } regc('\0'); if (*regparse != ']') FAIL("unmatched []"); regparse++; *flagp |= HASWIDTH|SIMPLE; } break; case '(': ret = reg(1, &flags); if (ret == NULL) return(NULL); *flagp |= flags&(HASWIDTH|SPSTART); break; case '\0': case '|': case ')': FAIL("internal urp"); /* Supposed to be caught earlier. */ break; case '?': case '+': case '*': FAIL("?+* follows nothing"); break; case '\\': if (*regparse == '\0') FAIL("trailing \\"); ret = regnode(EXACTLY); regc(*regparse++); regc('\0'); *flagp |= HASWIDTH|SIMPLE; break; default: { register int len; register char ender; regparse--; len = strcspn(regparse, META); if (len <= 0) FAIL("internal disaster"); ender = *(regparse+len); if (len > 1 && ISMULT(ender)) len--; /* Back off clear of ?+* operand. */ *flagp |= HASWIDTH; if (len == 1) *flagp |= SIMPLE; ret = regnode(EXACTLY); while (len > 0) { regc(*regparse++); len--; } regc('\0'); } break; } return(ret); } /* - regnode - emit a node */ static char * /* Location. */ regnode(op) char op; { register char *ret; register char *ptr; ret = regcode; if (ret == ®dummy) { regsize += 3; return(ret); } ptr = ret; *ptr++ = op; *ptr++ = '\0'; /* Null "next" pointer. */ *ptr++ = '\0'; regcode = ptr; return(ret); } /* - regc - emit (if appropriate) a byte of code */ static void regc(b) char b; { if (regcode != ®dummy) *regcode++ = b; else regsize++; } /* - reginsert - insert an operator in front of already-emitted operand * * Means relocating the operand. */ static void reginsert(op, opnd) char op; char *opnd; { register char *src; register char *dst; register char *place; if (regcode == ®dummy) { regsize += 3; return; } src = regcode; regcode += 3; dst = regcode; while (src > opnd) *--dst = *--src; place = opnd; /* Op node, where operand used to be. */ *place++ = op; *place++ = '\0'; *place++ = '\0'; } /* - regtail - set the next-pointer at the end of a node chain */ static void regtail(p, val) char *p; char *val; { register char *scan; register char *temp; register int offset; if (p == ®dummy) return; /* Find last node. */ scan = p; for (;;) { temp = regnext(scan); if (temp == NULL) break; scan = temp; } if (OP(scan) == BACK) offset = scan - val; else offset = val - scan; *(scan+1) = (offset>>8)&0377; *(scan+2) = offset&0377; } /* - regoptail - regtail on operand of first argument; nop if operandless */ static void regoptail(p, val) char *p; char *val; { /* "Operandless" and "op != BRANCH" are synonymous in practice. */ if (p == NULL || p == ®dummy || OP(p) != BRANCH) return; regtail(OPERAND(p), val); } /* * regexec and friends */ /* * Global work variables for regexec(). */ static char *reginput; /* String-input pointer. */ static char *regbol; /* Beginning of input, for ^ check. */ static char **regstartp; /* Pointer to startp array. */ static char **regendp; /* Ditto for endp. */ /* * Forwards. */ STATIC int regtry(); STATIC int regmatch(); STATIC int regrepeat(); #ifdef DEBUG int regnarrate = 0; void regdump(); STATIC char *regprop(); #endif /* - regexec - match a regexp against a string */ int regexec(prog, string, bolflag) register regexp *prog; register char *string; int bolflag; { register char *s; extern char *strchr(); /* Be paranoid... */ if (prog == NULL || string == NULL) { regerror("NULL parameter"); return(0); } /* Check validity of program. */ if (UCHARAT(prog->program) != MAGIC) { regerror("corrupted program"); return(0); } /* If there is a "must appear" string, look for it. */ if (prog->regmust != NULL) { s = string; while ((s = strchr(s, prog->regmust[0])) != NULL) { if (strncmp(s, prog->regmust, prog->regmlen) == 0) break; /* Found it. */ s++; } if (s == NULL) /* Not present. */ return(0); } /* Mark beginning of line for ^ . */ if(bolflag) regbol = string; else regbol = NULL; /* Simplest case: anchored match need be tried only once. */ if (prog->reganch) return(regtry(prog, string)); /* Messy cases: unanchored match. */ s = string; if (prog->regstart != '\0') /* We know what char it must start with. */ while ((s = strchr(s, prog->regstart)) != NULL) { if (regtry(prog, s)) return(1); s++; } else /* We don't -- general case. */ do { if (regtry(prog, s)) return(1); } while (*s++ != '\0'); /* Failure. */ return(0); } /* - regtry - try match at specific point */ static int /* 0 failure, 1 success */ regtry(prog, string) regexp *prog; char *string; { register int i; register char **sp; register char **ep; reginput = string; regstartp = prog->startp; regendp = prog->endp; sp = prog->startp; ep = prog->endp; for (i = NSUBEXP; i > 0; i--) { *sp++ = NULL; *ep++ = NULL; } if (regmatch(prog->program + 1)) { prog->startp[0] = string; prog->endp[0] = reginput; return(1); } else return(0); } /* - regmatch - main matching routine * * Conceptually the strategy is simple: check to see whether the current * node matches, call self recursively to see whether the rest matches, * and then act accordingly. In practice we make some effort to avoid * recursion, in particular by going through "ordinary" nodes (that don't * need to know whether the rest of the match failed) by a loop instead of * by recursion. */ static int /* 0 failure, 1 success */ regmatch(prog) char *prog; { register char *scan; /* Current node. */ char *next; /* Next node. */ extern char *strchr(); scan = prog; #ifdef DEBUG if (scan != NULL && regnarrate) fprintf(stderr, "%s(\n", regprop(scan)); #endif while (scan != NULL) { #ifdef DEBUG if (regnarrate) fprintf(stderr, "%s...\n", regprop(scan)); #endif next = regnext(scan); switch (OP(scan)) { case BOL: if (reginput != regbol) return(0); break; case EOL: if (*reginput != '\0') return(0); break; case ANY: if (*reginput == '\0') return(0); reginput++; break; case EXACTLY: { register int len; register char *opnd; opnd = OPERAND(scan); /* Inline the first character, for speed. */ if (*opnd != *reginput) return(0); len = strlen(opnd); if (len > 1 && strncmp(opnd, reginput, len) != 0) return(0); reginput += len; } break; case ANYOF: if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == NULL) return(0); reginput++; break; case ANYBUT: if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != NULL) return(0); reginput++; break; case NOTHING: break; case BACK: break; case OPEN+1: case OPEN+2: case OPEN+3: case OPEN+4: case OPEN+5: case OPEN+6: case OPEN+7: case OPEN+8: case OPEN+9: { register int no; register char *save; no = OP(scan) - OPEN; save = reginput; if (regmatch(next)) { /* * Don't set startp if some later * invocation of the same parentheses * already has. */ if (regstartp[no] == NULL) regstartp[no] = save; return(1); } else return(0); } break; case CLOSE+1: case CLOSE+2: case CLOSE+3: case CLOSE+4: case CLOSE+5: case CLOSE+6: case CLOSE+7: case CLOSE+8: case CLOSE+9: { register int no; register char *save; no = OP(scan) - CLOSE; save = reginput; if (regmatch(next)) { /* * Don't set endp if some later * invocation of the same parentheses * already has. */ if (regendp[no] == NULL) regendp[no] = save; return(1); } else return(0); } break; case BRANCH: { register char *save; if (OP(next) != BRANCH) /* No choice. */ next = OPERAND(scan); /* Avoid recursion. */ else { do { save = reginput; if (regmatch(OPERAND(scan))) return(1); reginput = save; scan = regnext(scan); } while (scan != NULL && OP(scan) == BRANCH); return(0); /* NOTREACHED */ } } break; case STAR: case PLUS: { register char nextch; register int no; register char *save; register int min; /* * Lookahead to avoid useless match attempts * when we know what character comes next. */ nextch = '\0'; if (OP(next) == EXACTLY) nextch = *OPERAND(next); min = (OP(scan) == STAR) ? 0 : 1; save = reginput; no = regrepeat(OPERAND(scan)); while (no >= min) { /* If it could work, try it. */ if (nextch == '\0' || *reginput == nextch) if (regmatch(next)) return(1); /* Couldn't or didn't -- back up. */ no--; reginput = save + no; } return(0); } break; case END: return(1); /* Success! */ break; default: regerror("memory corruption"); return(0); break; } scan = next; } /* * We get here only if there's trouble -- normally "case END" is * the terminating point. */ regerror("corrupted pointers"); return(0); } /* - regrepeat - repeatedly match something simple, report how many */ static int regrepeat(p) char *p; { register int count = 0; register char *scan; register char *opnd; scan = reginput; opnd = OPERAND(p); switch (OP(p)) { case ANY: count = strlen(scan); scan += count; break; case EXACTLY: while (*opnd == *scan) { count++; scan++; } break; case ANYOF: while (*scan != '\0' && strchr(opnd, *scan) != NULL) { count++; scan++; } break; case ANYBUT: while (*scan != '\0' && strchr(opnd, *scan) == NULL) { count++; scan++; } break; default: /* Oh dear. Called inappropriately. */ regerror("internal foulup"); count = 0; /* Best compromise. */ break; } reginput = scan; return(count); } /* - regnext - dig the "next" pointer out of a node */ static char * regnext(p) register char *p; { register int offset; if (p == ®dummy) return(NULL); offset = NEXT(p); if (offset == 0) return(NULL); if (OP(p) == BACK) return(p-offset); else return(p+offset); } #ifdef DEBUG STATIC char *regprop(); /* - regdump - dump a regexp onto stdout in vaguely comprehensible form */ void regdump(r) regexp *r; { register char *s; register char op = EXACTLY; /* Arbitrary non-END op. */ register char *next; extern char *strchr(); s = r->program + 1; while (op != END) { /* While that wasn't END last time... */ op = OP(s); printf("%2d%s", s-r->program, regprop(s)); /* Where, what. */ next = regnext(s); if (next == NULL) /* Next ptr. */ printf("(0)"); else printf("(%d)", (s-r->program)+(next-s)); s += 3; if (op == ANYOF || op == ANYBUT || op == EXACTLY) { /* Literal string, where present. */ while (*s != '\0') { putchar(*s); s++; } s++; } putchar('\n'); } /* Header fields of interest. */ if (r->regstart != '\0') printf("start `%c' ", r->regstart); if (r->reganch) printf("anchored "); if (r->regmust != NULL) printf("must have \"%s\"", r->regmust); printf("\n"); } /* - regprop - printable representation of opcode */ static char * regprop(op) char *op; { register char *p; static char buf[50]; (void) strcpy(buf, ":"); switch (OP(op)) { case BOL: p = "BOL"; break; case EOL: p = "EOL"; break; case ANY: p = "ANY"; break; case ANYOF: p = "ANYOF"; break; case ANYBUT: p = "ANYBUT"; break; case BRANCH: p = "BRANCH"; break; case EXACTLY: p = "EXACTLY"; break; case NOTHING: p = "NOTHING"; break; case BACK: p = "BACK"; break; case END: p = "END"; break; case OPEN+1: case OPEN+2: case OPEN+3: case OPEN+4: case OPEN+5: case OPEN+6: case OPEN+7: case OPEN+8: case OPEN+9: sprintf(buf+strlen(buf), "OPEN%d", OP(op)-OPEN); p = NULL; break; case CLOSE+1: case CLOSE+2: case CLOSE+3: case CLOSE+4: case CLOSE+5: case CLOSE+6: case CLOSE+7: case CLOSE+8: case CLOSE+9: sprintf(buf+strlen(buf), "CLOSE%d", OP(op)-CLOSE); p = NULL; break; case STAR: p = "STAR"; break; case PLUS: p = "PLUS"; break; default: regerror("corrupted opcode"); break; } if (p != NULL) (void) strcat(buf, p); return(buf); } #endif /* * The following is provided for those people who do not have strcspn() in * their C libraries. They should get off their butts and do something * about it; at least one public-domain implementation of those (highly * useful) string routines has been published on Usenet. */ /* * strcspn - find length of initial segment of s1 consisting entirely * of characters not from s2 */ static int strcspn(s1, s2) char *s1; char *s2; { register char *scan1; register char *scan2; register int count; count = 0; for (scan1 = s1; *scan1 != '\0'; scan1++) { for (scan2 = s2; *scan2 != '\0';) /* ++ moved down. */ if (*scan1 == *scan2++) return(count); count++; } return(count); } regsub.cI~ I/* * regsub * * Copyright (c) 1986 by University of Toronto. * Written by Henry Spencer. Not derived from licensed software. * * Permission is granted to anyone to use this software for any * purpose on any computer system, and to redistribute it freely, * subject to the following restrictions: * * 1. The author is not responsible for the consequences of use of * this software, no matter how awful, even if they arise * from defects in it. * * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. */ #include "../include/stdio.h" #include "../include/regexp.h" /* * The first byte of the regexp internal "program" is actually this magic * number; the start node begins in the second byte. */ #define MAGIC 0234 #define CHARBITS 0377 #ifndef CHARBITS #define UCHARAT(p) ((int)*(unsigned char *)(p)) #else #define UCHARAT(p) ((int)*(p)&CHARBITS) #endif /* - regsub - perform substitutions after a regexp match */ regsub(prog, source, dest) regexp *prog; char *source; char *dest; { register char *src; register char *dst; register char c; register int no; register int len; extern char *strncpy(); if (prog == NULL || source == NULL || dest == NULL) { regerror("NULL parm to regsub"); return; } if (UCHARAT(prog->program) != MAGIC) { regerror("damaged regexp fed to regsub"); return; } src = source; dst = dest; while ((c = *src++) != '\0') { if (c == '&') no = 0; else if (c == '\\' && '0' <= *src && *src <= '9') no = *src++ - '0'; else no = -1; if (no < 0) { /* Ordinary character. */ if (c == '\\' && (*src == '\\' || *src == '&')) c = *src++; *dst++ = c; } else if (prog->startp[no] != NULL && prog->endp[no] != NULL) { len = prog->endp[no] - prog->startp[no]; strncpy(dst, prog->startp[no], len); dst += len; if (len !=0 && *(dst-1) == '\0') { /* strncpy hit NUL. */ regerror("damaged match string"); return; } } } *dst++ = '\0'; } =rindex.cI~ char *rindex(s, c) register char *s, c; { register char *result; result = 0; do if (*s == c) result = s; while (*s++ != 0); return(result); } setbuf.cJ~ 6#include "../include/stdio.h" setbuf(iop, buffer) FILE *iop; char *buffer; { if ( iop->_buf && testflag(iop,IOMYBUF) ) free(iop->_buf); iop->_flags &= ~(IOMYBUF | UNBUFF | PERPRINTF); iop->_buf = buffer; if ( iop->_buf == NULL ) iop->_flags |= UNBUFF; iop->_ptr = iop->_buf; iop->_count = 0; } setgid.cJ~ #include "../include/lib.h" PUBLIC int setgid(grp) int grp; { return callm1(MM, SETGID, grp, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } setuid.cJ~ #include "../include/lib.h" PUBLIC int setuid(usr) int usr; { return callm1(MM, SETUID, usr, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } signal.cJ~ F#include "../include/lib.h" #include "../include/signal.h" int (*vectab[NR_SIGS])(); /* array of functions to catch signals */ /* The definition of signal really should be * PUBLIC int (*signal(signr, func))() * but some compilers refuse to accept this, even though it is correct. * The only thing to do if you are stuck with such a defective compiler is * change it to * PUBLIC int *signal(signr, func) * and change ../h/signal.h accordingly. */ PUBLIC int (*signal(signr, func))() int signr; /* which signal is being set */ int (*func)(); /* pointer to function that catches signal */ { int r,(*old)(); old = vectab[signr - 1]; vectab[signr - 1] = func; M.m6_i1 = signr; M.m6_f1 = ( (func == SIG_IGN || func == SIG_DFL) ? func : begsig); r = callx(MM, SIGNAL); return( (r < 0 ? (int (*)()) r : old) ); } sleep.cJ~ #include "../include/lib.h" #include "../include/signal.h" PRIVATE alfun(){} /* used with sleep() below */ PUBLIC sleep(n) int n; { /* sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt. */ signal(SIGALRM, alfun); alarm(n); pause(); } sprintf.cJ~ 1#include "../include/stdio.h" char *sprintf(buf,format,args) char *buf, *format; int args; { FILE _tempfile; _tempfile._fd = -1; _tempfile._flags = WRITEMODE + STRINGS; _tempfile._buf = buf; _tempfile._ptr = buf; _doprintf(&_tempfile,format,&args); putc('\0',&_tempfile); return buf; } (stat.cJ~ #include "../include/lib.h" PUBLIC int stat(name, buffer) char *name; char *buffer; { int n; n = callm1(FS, STAT, len(name), 0, 0, name, buffer, NIL_PTR); return(n); } 0stb.cJ~ /* library routine for copying structs with unpleasant alignment */ __stb(n, f, t) register char *f, *t; register int n; { if (n > 0) do *t++ = *f++; while (--n); } Tstderr.cJ~ Tstd_err(s) char *s; { char *p = s; while(*p != 0) p++; write(2, s, p - s); } stime.cJ~ o#include "../include/lib.h" PUBLIC int stime(top) long *top; { M.m2_l1 = *top; return callx(FS, STIME); } *strcat.cK~ char *strcat(s1, s2) register char *s1, *s2; { /* Append s2 to the end of s1. */ char *original = s1; /* Find the end of s1. */ while (*s1 != 0) s1++; /* Now copy s2 to the end of s1. */ while (*s2 != 0) *s1++ = *s2++; *s1 = 0; return(original); } astrcmp.cK~ int strcmp(s1, s2) register char *s1, *s2; { /* Compare 2 strings. */ while (1) { if (*s1 != *s2) return(*s1 - *s2); if (*s1 == 0) return(0); s1++; s2++; } } Nstrcpy.cK~ char *strcpy(s1, s2) register char *s1, *s2; { /* Copy s2 to s1. */ char *original = s1; while (*s2 != 0) *s1++ = *s2++; *s1 = 0; return(original); } ;strlen.cL~ |int strlen(s) char *s; { /* Return length of s. */ char *original = s; while (*s != 0) s++; return(s - original); } strncat.cL~ jchar *strncat(s1, s2, n) register char *s1, *s2; int n; { /* Append s2 to the end of s1, but no more than n characters */ char *original = s1; if (n == 0) return(s1); /* Find the end of s1. */ while (*s1 != 0) s1++; /* Now copy s2 to the end of s1. */ while (*s2 != 0) { *s1++ = *s2++; if (--n == 0) break; } *s1 = 0; return(original); } strncmp.cL~ int strncmp(s1, s2, n) register char *s1, *s2; int n; { /* Compare two strings, but at most n characters. */ while (1) { if (*s1 != *s2) return(*s1 - *s2); if (*s1 == 0 || --n == 0) return(0); s1++; s2++; } } strncpy.cL~ char *strncpy(s1, s2, n) register char *s1, *s2; int n; { /* Copy s2 to s1, but at most n characters. */ char *original = s1; while (*s2 != 0) { *s1++ = *s2++; if (--n == 0) break; } *s1 = 0; return(original); } sync.cL~ r#include "../include/lib.h" PUBLIC int sync() { return callm1(FS, SYNC, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } syslib.c #include "../h/const.h" #include "../h/type.h" #include "../h/callnr.h" #include "../h/com.h" #include "../h/error.h" #define FS FS_PROC_NR #define MM MMPROCNR extern int errno; extern message M; /*---------------------------------------------------------------------------- Messages to systask (special calls) ----------------------------------------------------------------------------*/ PUBLIC sys_xit(parent, proc) int parent; /* parent of exiting proc. */ int proc; /* which proc has exited */ { /* A proc has exited. Tell the kernel. */ callm1(SYSTASK, SYS_XIT, parent, proc, 0, NIL_PTR, NIL_PTR, NIL_PTR); } PUBLIC sys_getsp(proc, newsp) int proc; /* which proc has enabled signals */ vir_bytes *newsp; /* place to put sp read from kernel */ { /* Ask the kernel what the sp is. */ callm1(SYSTASK, SYS_GETSP, proc, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); *newsp = (vir_bytes) M.STACK_PTR; } PUBLIC sys_sig(proc, sig, sighandler) int proc; /* which proc has exited */ int sig; /* signal number: 1 - 16 */ int (*sighandler)(); /* pointer to signal handler in user space */ { /* A proc has to be signaled. Tell the kernel. */ M.m6_i1 = proc; M.m6_i2 = sig; M.m6_f1 = sighandler; callx(SYSTASK, SYS_SIG); } PUBLIC sys_fork(parent, child, pid) int parent; /* proc doing the fork */ int child; /* which proc has been created by the fork */ int pid; /* process id assigned by MM */ { /* A proc has forked. Tell the kernel. */ callm1(SYSTASK, SYS_FORK, parent, child, pid, NIL_PTR, NIL_PTR, NIL_PTR); } PUBLIC sys_exec(proc, ptr) int proc; /* proc that did exec */ char *ptr; /* new stack pointer */ { /* A proc has exec'd. Tell the kernel. */ callm1(SYSTASK, SYS_EXEC, proc, 0, 0, ptr, NIL_PTR, NIL_PTR); } PUBLIC sys_newmap(proc, ptr) int proc; /* proc whose map is to be changed */ char *ptr; /* pointer to new map */ { /* A proc has been assigned a new memory map. Tell the kernel. */ callm1(SYSTASK, SYS_NEWMAP, proc, 0, 0, ptr, NIL_PTR, NIL_PTR); } PUBLIC sys_copy(mptr) message *mptr; /* pointer to message */ { /* A proc wants to use local copy. */ /* Make this routine better. Also check other guys' error handling -DEBUG */ mptr->m_type = SYS_COPY; if (sendrec(SYSTASK, mptr) != OK) panic("sys_copy can't send", NO_NUM); } PUBLIC sys_times(proc, ptr) int proc; /* proc whose times are needed */ real_time ptr[4]; /* pointer to time buffer */ { /* Fetch the accounting info for a proc. */ callm1(SYSTASK, SYS_TIMES, proc, 0, 0, ptr, NIL_PTR, NIL_PTR); ptr[0] = M.USER_TIME; ptr[1] = M.SYSTEM_TIME; ptr[2] = M.CHILD_UTIME; ptr[3] = M.CHILD_STIME; } PUBLIC sys_abort() { /* Something awful has happened. Abandon ship. */ callm1(SYSTASK, SYS_ABORT, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } PUBLIC int tell_fs(what, p1, p2, p3) int what, p1, p2, p3; { /* This routine is only used by MM to inform FS of certain events: * tell_fs(CHDIR, slot, dir, 0) * tell_fs(EXIT, proc, 0, 0) * tell_fs(FORK, parent, child, 0) * tell_fs(SETGID, proc, realgid, effgid) * tell_fs(SETUID, proc, realuid, effuid) * tell_fs(SYNC, 0, 0, 0) * tell_fs(UNPAUSE, proc, signr, 0) */ callm1(FS, what, p1, p2, p3, NIL_PTR, NIL_PTR, NIL_PTR); } time.cL~ #include "../include/lib.h" PUBLIC long time(tp) long *tp; { int k; long l; k = callm1(FS, TIME, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); if (M.m_type < 0 || k != OK) {errno = -M.m_type; return(-1L);} l = M.m2_l1; if (tp != (long *) 0) *tp = l; return(l); } ttimes.cL~ #include "../include/lib.h" struct tbuf { long b1, b2, b3, b4;}; PUBLIC int times(buf) struct tbuf *buf; { int k; k = callm1(FS, TIMES, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); buf->b1 = M.m4_l1; buf->b2 = M.m4_l2; buf->b3 = M.m4_l3; buf->b4 = M.m4_l4; return(k); } sumask.cL~ #include "../include/lib.h" PUBLIC int umask(complmode) int complmode; { return callm1(FS, UMASK, complmode, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); } umount.cM~ k#include "../include/lib.h" PUBLIC int umount(name) char* name; { return callm3(FS, UMOUNT, 0, name); } oungetc.cM~ )#include "../include/stdio.h" ungetc(ch, iop) int ch; FILE *iop; { if ( ch < 0 || !testflag(iop,READMODE) || testflag(iop,UNBUFF) ) return( EOF ); if ( iop->_count >= BUFSIZ) return(EOF); if ( iop->_ptr == iop->_buf) iop->_ptr++; iop->_count++; *--iop->_ptr = ch; return(ch); } iunlink.cM~ k#include "../include/lib.h" PUBLIC int unlink(name) char *name; { return callm3(FS, UNLINK, 0, name); } )utime.cM~ #include "../include/lib.h" PUBLIC int utime(name, timp) char *name; long timp[2]; { M.m2_i1 = len(name); M.m2_l1 = timp[0]; M.m2_l2 = timp[1]; M.m2_p1 = name; return callx(FS, UTIME); } wait.cM~ #include "../include/lib.h" PUBLIC int wait(status) int *status; { int k; k = callm1(MM, WAIT, 0, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR); *status = M.m2_i1; return(k); } ewrite.cM~ #include "../include/lib.h" PUBLIC int write(fd, buffer, nbytes) char *buffer; int nbytes; { return callm1(FS, WRITE, fd, nbytes, 0, buffer, NIL_PTR, NIL_PTR); } brksize.sQ~ 5.data .globl endbss, _brksize _brksize: .word endbss fcatchsig.sQ~ .globl _begsig .globl _vectab, _M mtype = 2 | M+mtype = &M.m_type _begsig: push ax | after interrupt, save all regs push bx push cx push dx push si push di push bp push ds push es mov bx,sp mov bx,18(bx) | bx = signal number mov ax,bx | ax = signal number dec bx | vectab[0] is for sig 1 add bx,bx | pointers are two bytes on 8088 mov bx,_vectab(bx) | bx = address of routine to call push _M+mtype | push status of last system call push ax | func called with signal number as arg call (bx) back: pop ax | get signal number off stack pop _M+mtype | restore status of previous system call pop es | signal handling finished pop ds pop bp pop di pop si pop dx pop cx pop bx pop ax pop dummy | remove signal number from stack iret .data dummy: .word 0 csv.sQ~ WRITE = 4 FS = 1 |*===========================================================================* |* csv & cret * |*===========================================================================* | This version of csv replaces the standard one. It checks sp. .globl csv, cret, _sp_limit, _sendrec, _M csv: pop bx | bx = return address push bp | stack old frame pointer mov bp,sp | set new frame pointer to sp push di | save di push si | save si sub sp,ax | ax = # bytes of local variables cmp sp,_sp_limit | has stack overflowed? jb csv.err | jump if stack overflow jmp (bx) | normal return: copy bx to pc csv.err: | come here if stack overflow mov _M+2,#WRITE | m_type mov _M+4,#2 | file descriptor 2 is std error mov _M+6,#15 | prepare to print error message mov _M+10,#stkovmsg | error message mov ax,#_M | prepare to call sendrec(FS, &M); push ax | push second parameter mov ax,#FS | prepare to push first parameter push ax | push first parameter call _sendrec | write(fd, stkovmsg, 15); add sp,#4 | clean up stack L0: jmp L0 | hang forever cret: lea sp,*-4(bp) pop si pop di pop bp ret .data _sp_limit: .word 0 | stack limit default is 0 stkovmsg: .asciz "Stack overflow\n" rgetutil.sQ~ .globl _get_base, _get_size, _get_tot_mem .globl endbss |*========================================================================* | utilities * |*========================================================================* _get_base: | return click at which prog starts mov ax,ds ret _get_size: | return prog size in bytes (text+data+bss) mov ax,#endbss | end is compiler label at end of bss ret | Find out how much memory the machine has, including vectors, kernel MM, etc. _get_tot_mem: cli push es push di mov ax,#8192 | start search at 128K (8192 clicks) sub di,di L1: mov es,ax seg es mov (di),#0xA5A4 | write random bit pattern to memory xor bx,bx seg es mov bx,(di) | read back pattern just written cmp bx,#0xA5A4 | compare with expected value jne L2 | if different, no memory present add ax,#4096 | advance counter by 64K cmp ax,#0xA000 | stop seaching at 640K jne L1 L2: pop di pop es sti ret sendrec.sQ~ | See ../h/com.h for C definitions SEND = 1 RECEIVE = 2 BOTH = 3 SYSVEC = 32 |*========================================================================* | send and receive * |*========================================================================* | send(), receive(), sendrec() all save bp, but destroy ax, bx, and cx. .globl _send, _receive, _sendrec _send: mov cx,*SEND | send(dest, ptr) jmp L0 _receive: mov cx,*RECEIVE | receive(src, ptr) jmp L0 _sendrec: mov cx,*BOTH | sendrec(srcdest, ptr) jmp L0 L0: push bp | save bp mov bp,sp | can't index off sp mov ax,4(bp) | ax = dest-src mov bx,6(bp) | bx = message pointer int SYSVEC | trap to the kernel pop bp | restore bp ret | return crtso.sQ~ V| This is the C run-time start-off routine. It's job is to take the | arguments as put on the stack by EXEC, and to parse them and set them up the | way _main expects them. .globl _main, _exit, crtso, _environ .globl begtext, begdata, begbss, endtext, enddata, endbss .text begtext: crtso: mov bx,sp mov cx,(bx) add bx,*2 mov ax,cx inc ax shl ax,#1 add ax,bx mov _environ,ax | save envp in environ push ax | push environ push bx | push argv push cx | push argc call _main add sp,*6 push ax | push exit status call _exit .data begdata: _environ: .word 0 .bss begbss: end.sQ~ K.globl endtext, enddata, endbss .text endtext: .data enddata: .bss endbss: shead.sQ~ .globl _main, _stackpt, begtext, begdata, begbss, _data_org, _exit .text begtext: jmp L0 .zerow 7 | kernel uses this area as stack for inital IRET L0: mov sp,_stackpt call _main L1: jmp L1 | this will never be executed _exit: jmp _exit | this will never be executed either .data begdata: _data_org: | fs needs to know where build stuffed table .word 0xDADA,0,0,0,0,0,0,0 | first 8 words of MM, FS, INIT are for stack | 0xDADA is magic number for build .bss begbss: setjmp.sQ~ .globl _setjmp, _longjmp .globl csv .text _setjmp: mov bx,sp mov ax,(bx) mov bx,*2(bx) mov (bx),bp mov *2(bx),sp mov *4(bx),ax xor ax,ax ret _longjmp: xor ax,ax call csv mov bx,*4(bp) mov ax,*6(bp) or ax,ax jne L1 inc ax L1: mov cx,(bx) L2: cmp cx,*0(bp) je L3 mov bp,*0(bp) or bp,bp jne L2 hlt L3: mov di,*-2(bp) mov si,*-4(bp) mov bp,*0(bp) mov sp,*2(bx) mov cx,*4(bx) mov bx,sp mov (bx),cx ret bscanf.c= /* scanf - formatted input conversion Author: Patrick van Kleef */ #include int scanf (format, args) char *format; unsigned args; { return _doscanf (0, stdin, format, &args); } int fscanf (fp, format, args) FILE *fp; char *format; unsigned args; { return _doscanf (0, fp, format, &args); } int sscanf (string, format, args) char *string; /* source of data */ char *format; /* control string */ unsigned args; /* our args */ { return _doscanf (1, string, format, &args); } union ptr_union { char *chr_p; unsigned int *uint_p; unsigned long *ulong_p; }; static int ic; /* the current character */ static char *rnc_arg; /* the string or the filepointer */ static rnc_code; /* 1 = read from string, else from FILE */ /* get the next character */ static rnc () { if (rnc_code) { if (!(ic = *rnc_arg++)) ic = EOF; } else ic = getc ((FILE *) rnc_arg); } /* * unget the current character */ static ugc () { if (rnc_code) --rnc_arg; else ungetc (ic, rnc_arg); } static index(ch, string) char ch; char *string; { while (*string++ != ch) if (!*string) return 0; return 1; } /* * this is cheaper than iswhite from */ static iswhite (ch) int ch; { return (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); } static isdigit (ch) int ch; { return (ch >= '0' && ch <= '9'); } static tolower (ch) int ch; { if (ch >= 'A' && ch <= 'Z') ch = ch + 'a' - 'A'; return ch; } /* * the routine that does the job */ _doscanf (code, funcarg, format, argp) int code; /* function to get a character */ char *funcarg; /* an argument for the function */ char *format; /* the format control string */ union ptr_union *argp; /* our argument list */ { int done = 0; /* number of items done */ int base; /* conversion base */ long val; /* an integer value */ int sign; /* sign flag */ int do_assign; /* assignment suppression flag */ unsigned width; /* width of field */ int widflag; /* width was specified */ int longflag; /* true if long */ int done_some; /* true if we have seen some data */ int reverse; /* reverse the checking in [...] */ char *endbracket; /* position of the ] in format string */ rnc_arg = funcarg; rnc_code = code; rnc (); /* read the next character */ if (ic == EOF) { done = EOF; goto quit; } while (1) { while (iswhite (*format)) ++format; /* skip whitespace */ if (!*format) goto all_done; /* end of format */ if (ic < 0) goto quit; /* seen an error */ if (*format != '%') { while (iswhite (ic)) rnc (); if (ic != *format) goto all_done; ++format; rnc (); ++done; continue; } ++format; do_assign = 1; if (*format == '*') { ++format; do_assign = 0; } if (isdigit (*format)) { widflag = 1; for (width = 0; isdigit (*format);) width = width * 10 + *format++ - '0'; } else widflag = 0; /* no width spec */ if (longflag = (tolower (*format) == 'l')) ++format; if (*format != 'c') while (iswhite (ic)) rnc (); done_some = 0; /* nothing yet */ switch (*format) { case 'o': base = 8; goto decimal; case 'u': case 'd': base = 10; goto decimal; case 'x': base = 16; if (((!widflag) || width >= 2) && ic == '0') { rnc (); if (tolower (ic) == 'x') { width -= 2; done_some = 1; rnc (); } else { ugc (); ic = '0'; } } decimal: val = 0L; /* our result value */ sign = 0; /* assume positive */ if (!widflag) width = 0xffff; /* very wide */ if (width && ic == '+') rnc (); else if (width && ic == '-') { sign = 1; rnc (); } while (width--) { if (isdigit (ic) && ic - '0' < base) ic -= '0'; else if (base == 16 && tolower (ic) >= 'a' && tolower (ic) <= 'f') ic = 10 + tolower (ic) - 'a'; else break; val = val * base + ic; rnc (); done_some = 1; } if (do_assign) { if (sign) val = -val; if (longflag) *(argp++)->ulong_p = (unsigned long) val; else *(argp++)->uint_p = (unsigned) val; } if (done_some) ++done; else goto all_done; break; case 'c': if (!widflag) width = 1; while (width-- && ic >= 0) { if (do_assign) *(argp)->chr_p++ = (char) ic; rnc (); done_some = 1; } if (do_assign) argp++; /* done with this one */ if (done_some) ++done; break; case 's': if (!widflag) width = 0xffff; while (width-- && !iswhite (ic) && ic > 0) { if (do_assign) *(argp)->chr_p++ = (char) ic; rnc (); done_some = 1; } if (do_assign) /* terminate the string */ *(argp++)->chr_p = '\0'; if (done_some) ++done; else goto all_done; break; case '[': if (!widflag) width = 0xffff; if ( *(++format) == '^' ) { reverse = 1; format++; } else reverse = 0; endbracket = format; while ( *endbracket != ']' && *endbracket != '\0') endbracket++; if (!*endbracket) goto quit; *endbracket = '\0'; /* change format string */ while (width-- && !iswhite (ic) && ic > 0 && (index (ic, format) ^ reverse)) { if (do_assign) *(argp)->chr_p++ = (char) ic; rnc (); done_some = 1; } format = endbracket; *format = ']'; /* put it back */ if (do_assign) /* terminate the string */ *(argp++)->chr_p = '\0'; if (done_some) ++done; else goto all_done; break; } /* end switch */ ++format; } all_done: if (ic >= 0) ugc (); /* restore the character */ quit: return done; } t# ========== compile everything =========== #for i in *.c #do # echo $i # cc -c -LIB $i #done # ========== build library ============== # # Build libc.a using all of the .s files in the current directory. # New files are placed at the beginning of the library followed by # modules which are already in the old library (/usr/lib/libc.a). # Old modules are placed in the new library in the same order in which # they appear in the old library. # # Art Zemon, July 17, 1987 # echo Reading old library ar t /usr/lib/libc.a > list split -8 list cat /dev/null > orig.order echo Creating orig.order for f in x?? do echo ar a libc.a `cat $f` >> orig.order rm $f done # # Figure out which files are not in the existing library. # Base this decision on the .c files because there are a couple of .s # files here which don't belong in the library. # echo Checking .c files cat /dev/null > new.files for c in *.c do f=`basename $c .c` f=$f".s" echo $f if grep -s $f list > /dev/null 2>&1 ; then cat /dev/null ; else echo ar av libc.a $f >> new.files ; fi done # # Figure out which modules are in the library but not here and extract them # from the library. # echo determining which modules must be extracted from old library rm -f libc.a sh orig.order > /dev/null 2> missing ar xv /usr/lib/libc.a `grep 'Cannot find ' missing | gres 'Cannot find ' ''` rm missing libc.a list # # Construct the library # echo constructing new library with new modules sh new.files echo appending original modules to new library sh orig.order echo done #-- # -- Art Zemon # FileNet Corporation # Costa Mesa, California # ...!hplabs!felix!zemon echo Rebuilding libc.a in this directory split -8 order for f in x?? do ar av libc.a `cat $f` done rm x?? getpwent.s qsort.s popen.s scanf.s system.s fgets.s fprintf.s puts.s fputs.s fread.s freopen.s fclose.s fopen.s fseek.s ftell.s fwrite.s gets.s getc.s printdat.s setbuf.s ctime.s sprintf.s doprintf.s putc.s ungetc.s strcmp.s access.s chdir.s chmod.s chown.s chroot.s creat.s dup.s dup2.s exec.s exit.s cleanup.s fflush.s fork.s isatty.s fstat.s getegid.s getenv.s geteuid.s getgid.s getpass.s close.s getuid.s ioctl.s abort.s kill.s link.s lseek.s malloc.s brk.s brk2.s brksize.s mknod.s mktemp.s getpid.s mount.s open.s perror.s pipe.s prints.s read.s setgid.s setuid.s sleep.s alarm.s pause.s signal.s catchsig.s stat.s stime.s strcat.s strcpy.s strlen.s strncat.s strncmp.s strncpy.s sync.s time.s times.s umask.s umount.s unlink.s utime.s wait.s stderr.s write.s syslib.s call.s atoi.s message.s sendrec.s printk.s itoa.s abs.s atol.s ctype.s index.s bcopy.s getutil.s rand.s rindex.s setjmp.s adi.s and.s cii.s cms.s cmu4.s com.s csa2.s csb2.s cuu.s .dup.s dvi.s dvi4.s dvu.s dvu4.s exg.s fakfp.s gto.s iaar.s ilar.s inn.s ior.s isar.s lar2.s loi.s mli.s mli4.s ngi.s nop.s rck.s rmi.s rmi4.s rmu.s rmu4.s rol.s ror.s sar2.s sbi.s set.s sli.s sri.s sti.s xor.s error.s unknown.s trp.s stb.s crypt.s ar a libc.a cleanup.s fgets.s fprintf.s fputs.s fread.s freopen.s fclose.s fopen.s ar a libc.a fseek.s fflush.s ftell.s fwrite.s gets.s getc.s printdat.s setbuf.s ar a libc.a sprintf.s doprintf.s putc.s scanf.s ungetc.s strcmp.s access.s chdir.s ar a libc.a chmod.s chown.s chroot.s creat.s dup.s dup2.s exec.s exit.s ar a libc.a fork.s isatty.s fstat.s getegid.s getenv.s geteuid.s getgid.s getpass.s ar a libc.a close.s getuid.s ioctl.s kill.s link.s lseek.s malloc.s brk.s ar a libc.a brk2.s brksize.s mknod.s mktemp.s getpid.s mount.s open.s perror.s ar a libc.a pipe.s prints.s read.s setgid.s setuid.s sleep.s alarm.s pause.s ar a libc.a signal.s catchsig.s stat.s stime.s strcat.s strcpy.s strlen.s strncat.s ar a libc.a strncmp.s strncpy.s sync.s time.s times.s umask.s umount.s unlink.s ar a libc.a utime.s wait.s stderr.s write.s syslib.s call.s atoi.s message.s ar a libc.a sendrec.s printk.s abort.s itoa.s stb.s abs.s atol.s ctype.s ar a libc.a index.s bcopy.s getutil.s rand.s rindex.s adi.s and.s cii.s ar a libc.a cms.s cmu4.s com.s csa2.s csb2.s cuu.s .dup.s dvi.s ar a libc.a dvi4.s dvu.s dvu4.s exg.s fakfp.s gto.s iaar.s ilar.s ar a libc.a inn.s ior.s isar.s lar2.s loi.s mli.s mli4.s ngi.s ar a libc.a nop.s rck.s rmi.s rmi4.s rmu.s rmu4.s rol.s ror.s ar a libc.a sar2.s sbi.s set.s sli.s sri.s sti.s xor.s error.s ar a libc.a unknown.s trp.s setjmp.s /* From Andy Tanenbaum's book "Computer Networks", rewritten in C */ struct block { unsigned char b_data[64]; }; struct ordering { unsigned char o_data[64]; }; static struct block key; static struct ordering InitialTr = { 58,50,42,34,26,18,10, 2,60,52,44,36,28,20,12, 4, 62,54,46,38,30,22,14, 6,64,56,48,40,32,24,16, 8, 57,49,41,33,25,17, 9, 1,59,51,43,35,27,19,11, 3, 61,53,45,37,29,21,13, 5,63,55,47,39,31,23,15, 7, }; static struct ordering FinalTr = { 40, 8,48,16,56,24,64,32,39, 7,47,15,55,23,63,31, 38, 6,46,14,54,22,62,30,37, 5,45,13,53,21,61,29, 36, 4,44,12,52,20,60,28,35, 3,43,11,51,19,59,27, 34, 2,42,10,50,18,58,26,33, 1,41, 9,49,17,57,25, }; static struct ordering swap = { 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48, 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16, 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, }; static struct ordering KeyTr1 = { 57,49,41,33,25,17, 9, 1,58,50,42,34,26,18, 10, 2,59,51,43,35,27,19,11, 3,60,52,44,36, 63,55,47,39,31,23,15, 7,62,54,46,38,30,22, 14, 6,61,53,45,37,29,21,13, 5,28,20,12, 4, }; static struct ordering KeyTr2 = { 14,17,11,24, 1, 5, 3,28,15, 6,21,10, 23,19,12, 4,26, 8,16, 7,27,20,13, 2, 41,52,31,37,47,55,30,40,51,45,33,48, 44,49,39,56,34,53,46,42,50,36,29,32, }; static struct ordering etr = { 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9,10,11,12,13,12,13,14,15,16,17, 16,17,18,19,20,21,20,21,22,23,24,25, 24,25,26,27,28,29,28,29,30,31,32, 1, }; static struct ordering ptr = { 16, 7,20,21,29,12,28,17, 1,15,23,26, 5,18,31,10, 2, 8,24,14,32,27, 3, 9,19,13,30, 6,22,11, 4,25, }; static unsigned char s_boxes[8][64] = { { 14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7, 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8, 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0, 15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13, }, { 15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10, 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5, 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15, 13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9, }, { 10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8, 13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1, 13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7, 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12, }, { 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15, 13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9, 10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4, 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14, }, { 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9, 14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6, 4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14, 11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3, }, { 12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11, 10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8, 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6, 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13, }, { 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1, 13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6, 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2, 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12, }, { 13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7, 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2, 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8, 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11, }, }; static int rots[] = { 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1, }; static transpose(data, t, n) register struct block *data; register struct ordering *t; register int n; { struct block x; x = *data; while (n-- > 0) { data->b_data[n] = x.b_data[t->o_data[n] - 1]; } } static rotate(key) register struct block *key; { register unsigned char *p = key->b_data; register unsigned char *ep = &(key->b_data[55]); int data0 = key->b_data[0], data28 = key->b_data[28]; while (p++ < ep) *(p-1) = *p; key->b_data[27] = data0; key->b_data[55] = data28; } static struct ordering *EP = &etr; static f(i, key, a, x) struct block *key, *a; register struct block *x; { struct block e, ikey, y; int k; register unsigned char *p, *q, *r; e = *a; transpose(&e, EP, 48); for (k = rots[i]; k; k--) rotate(key); ikey = *key; transpose(&ikey, &KeyTr2, 48); p = &(y.b_data[48]); q = &(e.b_data[48]); r = &(ikey.b_data[48]); while (p > y.b_data) { *--p = *--q ^ *--r; } q = x->b_data; for (k = 0; k < 8; k++) { register int xb, r; r = *p++ << 5; r += *p++ << 3; r += *p++ << 2; r += *p++ << 1; r += *p++; r += *p++ << 4; xb = s_boxes[k][r]; *q++ = (xb >> 3) & 1; *q++ = (xb>>2) & 1; *q++ = (xb>>1) & 1; *q++ = (xb & 1); } transpose(x, &ptr, 32); } setkey(k) register char *k; { key = *((struct block *) k); transpose(&key, &KeyTr1, 56); } encrypt(blck, edflag) char *blck; { register struct block *p = (struct block *) blck; register int i; transpose(p, &InitialTr, 64); for (i = 15; i>= 0; i--) { int j = edflag ? i : 15 - i; register int k; struct block b, x; b = *p; for (k = 31; k >= 0; k--) { p->b_data[k] = b.b_data[k + 32]; } f(j, &key, p, &x); for (k = 31; k >= 0; k--) { p->b_data[k+32] = b.b_data[k] ^ x.b_data[k]; } } transpose(p, &swap, 64); transpose(p, &FinalTr, 64); } char * crypt(pw,salt) register char *pw; char *salt; { /* Unfortunately, I had to look at the sources of V7 crypt. There was no other way to find out what this routine actually does. */ char pwb[66]; static char result[16]; register char *p = pwb; struct ordering new_etr; register int i; while (*pw && p < &pwb[64]) { register int j = 7; while (j--) { *p++ = (*pw >> j) & 01; } pw++; *p++ = 0; } while (p < &pwb[64]) *p++ = 0; setkey(p = pwb); while (p < &pwb[66]) *p++ = 0; new_etr = etr; EP = &new_etr; for (i = 0; i < 2; i++) { register char c = *salt++; register int j; result[i] = c; if ( c > 'Z') c -= 6 + 7 + '.'; /* c was a lower case letter */ else if ( c > '9') c -= 7 + '.';/* c was upper case letter */ else c -= '.'; /* c was digit, '.' or '/'. */ /* now, 0 <= c <= 63 */ for (j = 0; j < 6; j++) { if ((c >> j) & 01) { int t = 6*i + j; int temp = new_etr.o_data[t]; new_etr.o_data[t] = new_etr.o_data[t+24]; new_etr.o_data[t+24] = temp; } } } if (result[1] == 0) result[1] = result[0]; for (i = 0; i < 25; i++) encrypt(pwb,0); EP = &etr; p = pwb; pw = result+2; while (p < &pwb[66]) { register int c = 0; register int j = 6; while (j--) { c <<= 1; c |= *p++; } c += '.'; /* becomes >= '.' */ if (c > '9') c += 7; /* not in [./0-9], becomes upper */ if (c > 'Z') c += 6; /* not in [A-Z], becomes lower */ *pw++ = c; } *pw = 0; return result; } _setkey _encrypt _crypt _InitialTr: 12858 8746 4634 522 13372 9260 8 1036 13886 9774 5662 1550 14400 10288 6176 2064 12601 8489 4377 265 13115 9003 4891 779 13629 9517 5405 1293 14143 10031 5919 1807 _FinalTr: 2088 4144 6200 8256 1831 3887 5943 7999 1574 3630 5686 7742 1317 3373 5429 7485 1060 3116 5172 7228 803 2859 4915 6971 546 2602 4658 6714 289 2345 4401 6457 _swap: 8737 9251 9765 10279 10793 11307 11821 12335 12849 13363 13877 14391 14905 15419 15933 16447 513 1027 1541 2055 .word 2569 3083 3597 4111 4625 5139 5653 6167 6681 7195 7709 8223 _KeyTr1: 12601 8489 4377 265 12858 8746 4634 522 13115 9003 4891 779 13372 9260 14143 10031 5919 1807 13886 9774 5662 1550 13629 9517 5405 1293 8 1036 _KeyTr2: 4366 6155 1281 7171 1551 2581 4887 1036 2074 1808 7 525 13353 9503 14127 10270 11571 12321 12588 14375 13602 10798 9266 8221 _etr: 288 770 1284 1284 1798 2312 2312 2826 3340 3340 3854 4368 4368 4882 5396 5396 5910 .word 6424 6424 6938 7452 7452 7966 288 _ptr: 1808 5396 3101 4380 3841 6679 4613 2591 2050 3608 6944 2307 3347 1566 2838 6404 _s_boxes: 1038 269 3842 2059 2563 3078 2309 1792 3840 1031 526 269 1546 2828 1289 2051 260 2062 1549 2818 3087 1801 2563 5 3087 520 2308 1793 2821 3587 10 3334 271 3592 2822 1027 1801 3330 12 2565 3331 1796 527 3592 12 2561 2310 1291 3584 2823 1034 269 2053 .word 1548 777 3842 2061 266 3843 516 1547 3079 1280 2318 10 3593 774 1295 3329 1804 1035 2050 1805 2304 1027 2566 2050 3589 2828 271 1549 2308 3848 3 267 3074 2565 1806 2561 13 2310 1800 3844 782 1291 3074 3335 782 1536 2569 513 1288 3083 3844 2061 1291 3846 768 1796 3074 2561 2318 1546 9 2828 3335 271 3587 517 1032 3843 1536 266 2061 1033 2821 1804 3586 3074 260 2567 1547 1288 3843 13 2318 2830 3074 1796 269 5 5 2307 1544 516 2817 3338 2055 2319 1292 774 3584 2059 1804 3585 3330 3846 2304 1034 773 268 3850 521 2054 3328 1027 1806 2821 3850 516 3079 1289 262 3597 2816 2051 3593 1295 2050 780 7 2564 3329 1547 772 3074 1289 5 3595 1793 6 3336 2820 3586 15 3336 3075 1801 2565 262 13 1803 2308 2561 782 3077 3842 1544 1025 3339 780 3591 3850 2054 1280 521 2822 2061 1025 1802 1289 3840 526 3075 525 1032 3846 267 2314 3587 5 1804 3841 2061 778 1031 1292 2822 3584 521 2823 260 3081 526 1536 3338 783 2053 258 1806 2564 3336 3087 9 1283 2822 _rots: 1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1 _tranose: ,#64 ,#-62 62 64 ___stb -6 2 64 ___stb ,#70 jle I0012 1 al,-64(_) _rotate: ,#8 55 , , al,28 , I0023: push ,#1 jae I0022 (),al I0023 I0022: 27,al 55,al _EP: _etr _f: ,#214 ,#-62 62 64 ___stb -6 2 64 ___stb ,#70 48 _EP -6 _tranose sal 1 _rots -19, I0035: -19 je I0032 _rotate -19 I0035 I0032: ,#-62 62 64 ___stb -12 2 64 ___stb ,#70 48 _KeyTr2 -12 _tranose -14 -19, -1 -19, -80() -200(), I0037: -192() -19, jbe I0036 -200(),#-1 -200() -19,#-1 -19 -19,#-1 -19 (),bl I0037 I0036: 10() -19, -19 I003C: -19,#8 jge I0039 -19 -19,#1 5 sal cl -20, -20 -19 -19,#1 3 sal cl -20, -20 -19 -19,#1 sal cl call -20, -20 -19 -19,#1 1 sal cl -20, -20 -19 -19,#1 -20, -20 -19 -19,#1 4 sal cl -20, 6 -19 sal cl -20 al,_s_boxes -202(), 3 -202() sar cl 1 -19 -19,#1 -202() sar cl 1 -19 -198(bp),#1 -202() sar 1 1 -19 -19,#1 -202() 1 -19 -19,#1 -19 I003C I0039: 32 _ptr 10() _tranose _setkey _setkey: ,#-62 62 64 ___stb _key 2 64 ___stb ,#70 56 _KeyTr1 _key _tranose _encrypt _encrypt: ,#136 64 _InitialTr _tranose ,#15 I0055: jl I0052 je I0057 I0058 I0057: 5 I0058: -2() ,#-62 62 64 ___stb -72() 2 64 ___stb ,#70 ,#31 I005C: jl I0059 32 al,-72(_) I005C I0059: -13 _key _f ,#8 ,#31 I00510: jl I0053 al,-72(_) bl,-136(_) bh,bh #32 (),bl I00510 I0053: I0055 I0052: 64 _swap _tranose 64 _FinalTr _tranose _crypt _crypt: ,#148 _1: .zerow 16/2 -6 -6, I0063: cmpb je I006A bx, -6, jae I006A -13,#7 I0067: -13 -13 je I0066 -13 sar cl 1 -6 -6,#1 I0067 I0066: -6 -6,#1 I0063 I006A: -6, jae I0069 -6 -6,#1 I006A I0069: -6 -6, -6 _setkey I006D: 0() -6, jae I006C -6 -6,#1 I006D I006C: _etr ,#-62 62 64 ___stb -132() 2 64 ___stb ,#70 -132() _EP, -13 I00612: -13,#2 jge I006F ,#1 -135(),al -13 al,-135() _1,al al,-135() 90 jle I00614 al,-135() 59 -135(),al I00615 I00614: al,-135() 57 jle I00617 al,-135() 53 -135(),al I00615 I00617: al,-135() 46 -135(),al I00615: -13 I0061C: -13,#6 jge I00610 al,-135() -13 sar cl testb al,#1 je I0061A 6 mul -13 -13 -14, -14 al,-132(_) -14, -14 24 -14 al,-132(_) -132(_),al -14 -14 24 -132(_),al I0061A: -13 I0061C I00610: -13 I00612 I006F: cmpb _1+1 I00621 cl,_1 _1+1,cl I00621: -13 I00626: -13,#25 jge I00623 -6 _encrypt -13 I00626 I00623: _EP,#_etr -6 -6, ,#_1+2 I00628: 0() -6, jae I00627 -13 -13,#6 I0062B: -13 -13 je I0062A -13 sal 1 -13, -13 -6 -6,#1 or -13, I0062B I0062A: -13,#46 -13,#57 jle I0062E -13,#7 I0062E: -13,#90 jle I00631 -13,#6 I00631: -13 I00628 I00627: _1 _key: .zerow 64/2 struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; }; struct timeb { long time; unsigned short millitm; short timezone; short dstflag; }; extern struct tm *localtime(); extern char *asctime(); char *ctime(clock) long *clock; { return asctime(localtime(clock)); } static int monthsize[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; #define SECS_DAY (24*60L*60L) #define YEARSIZE(year) ((year) % 4 ? 365 : 366) struct tm * gmtime(clock) long *clock; { long cl = *clock; long dayclock, dayno; static struct tm tm_buf; register struct tm *pbuf = &tm_buf; register int *months = monthsize; int year = 1970; dayclock = cl % SECS_DAY; dayno = cl / SECS_DAY; pbuf->tm_sec = dayclock % 60; pbuf->tm_min = (dayclock % 3600) / 60; pbuf->tm_hour = dayclock / 3600; pbuf->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */ while (dayno >= YEARSIZE(year)) { dayno -= YEARSIZE(year); year++; } pbuf->tm_year = year - 1900; pbuf->tm_yday = dayno; pbuf->tm_isdst = 0; if (YEARSIZE(year) == 366) monthsize[1] = 29; while (dayno - *months >= 0) dayno -= *months++; pbuf->tm_mday = dayno + 1; pbuf->tm_mon = months - monthsize; monthsize[1] = 28; return pbuf; } #define FIRSTSUNDAY(t) (((t)->tm_yday - (t)->tm_wday + 420) % 7) #define SUNDAY(day, t) ((day) < 58 ? \ ((day) < FIRSTSUNDAY(t) ? FIRSTSUNDAY(t) : static int last_sunday(d, t) register int d; register struct tm *t; { int first = FIRSTSUNDAY(t); if (d >= 58 && YEARSIZE(t->tm_year)) d++; if (d < first) return first; return d - (d - first) % 7; } extern struct tm *gmtime(); struct tm * localtime(clock) long *clock; { register struct tm *gmt; long cl; int begindst, enddst; extern int __daylight; extern long __timezone; tzset(); cl = *clock - __timezone; gmt = gmtime(&cl); if (__daylight) { /* daylight saving time. Unfortunately, rules differ for different countries. Implemented here are heuristics that got it right in Holland, over the last couple of years. Of course, there is no algorithm. It is all politics ... */ begindst = last_sunday(89, gmt); /* last Sun before Apr */ enddst = last_sunday(272, gmt); /* last Sun in Sep */ if ((gmt->tm_yday>begindst || (gmt->tm_yday==begindst && gmt->tm_hour>=2)) && (gmt->tm_ydaytm_yday==enddst && gmt->tm_hour<3))) { /* it all happens between 2 and 3 */ cl += 1*60*60; gmt = gmtime(&cl); gmt->tm_isdst++; } } return gmt; } #ifdef BSD4_2 #else #ifndef USG #endif #endif #ifdef USG long timezone = -1 * 60; int daylight = 1; char *tzname[] = {"MET", "MDT",}; #endif long __timezone = -1 * 60; int __daylight = 1; char *__tzname[] = {"MET", "MDT", }; tzset() { #ifdef BSD4_2 struct timeval tval; struct timezone tzon; gettimeofday(&tval, &tzon); __timezone = tzon.tz_minuteswest * 60L; __daylight = tzon.tz_dsttime; #else #ifndef USG struct timeb time; ftime(&time); __timezone = time.timezone*60L; __daylight = time.dstflag; #endif #endif { extern char *getenv(); register char *p = getenv("TZ"); if (p && *p) { register int n = 0; int sign = 1; strncpy(__tzname[0], p, 3); p += 3; if (*(p += 3) == '-') { sign = -1; p++; } while(*p >= '0' && *p <= '9') n = 10 * n + (*p++ - '0'); n *= sign; __timezone = ((long)(n * 60)) * 60; __daylight = (*p != '\0'); strncpy(__tzname[1], p, 3); } } #ifdef USG timezone = __timezone; daylight = __daylight; tzname[0] = __tzname[0]; tzname[1] = __tzname[1]; #endif } _localtime _tzset ___timezone ___daylight _ctime _gmtime ___tzname _ctime _ctime: _localtime _asctime _monthze: 31 28 31 30 31 30 31 31 30 31 30 _gmtime 31 _gmtime: ,#20 _1: .zerow 18/2 2 -1,#_1 -1,#_monthze -1,#1970 0864 .rmi4 , , 0864 .dvi4 -12(), -10(), 60 .rmi4 -1 , 3600 .rmi4 60 call .dvi4 -1 2, 3600 .dvi4 -1 4, -12() -10() 4 adc 0 7 .rmi4 -1 12, I0023: 4 -1 cwd iv -10() -12() or je I0026 365 I0027 I0026: 366 I0027: cwd sbb 1f je 1f 1: or jl I0022 4 -1 cwd iv -10() -12() or je I0029 365 I002A I0029: 366 I002A: cwd sbb -12(), -10(), -1 I0023 I0022: -1 1900 -1 10, -1 -12() 14, -1 16 4 -1 cwd iv or je I002F 365 I00210 I002F: 366 I00210: 366 I00212 _monthze+2,#29 I00212: -1 cwd -12() -10() sbb 0 sbb 0 1f je 1f 1: or jl I00211 -10() -12() -1 -1,#2 cwd sbb -12(), -10(), I00212 I00211: -12() -10() 1 adc 0 -1 6, -1 _monthze cwd iv -1 8, _monthze+2,#28 -1 _last_sunday: 14 12() 420 7 cwd iv , ,#58 jl I0033 4 10 cwd iv or je I0037 365 I0038 I0037: 366 I0038: je I0033 I0033: , jge I003A I0031 I003A: ax, 7 cwd iv I0031: _localtime _localtime: ,#14 _tzset 2 ___timezone sbb ___timezone+2 , , _gmtime ___daylight je I0043 89 _last_sunday , 72 _last_sunday -10(), 14, jg I0048 14, I0043 4,#2 jl I0043 I0048: -10() 14, jl I0045 -10() 14, I0043 4,#3 jge I0043 I0045: 3600 adc 0 , , _gmtime 16 -1, I0043: mov ___timezone ___timezone: -60,-1 ___daylight ___daylight: ___tzname 1 ___tzname: _2 _3 _tzset _tzset: ,#22 -10() _ftime cwd #60 .mli4 ___timezone, ___timezone+2, ___daylight, _4 _getenv -12(), -12() je I0053 -12() cmpb je I0053 -1 -1,#1 3 -12() ___tzname _strncpy -12(),#3 -12(),#3 -12() cmpb ,#45 I005A -1,#-1 -12(),#1 I005A: -12() 48 jl I0059 -12() 57 jg I0059 -12() -12(),#1 48 0 mul -1 -1, I005A I0059: ,-1 mul -1 -1, 60 mul -1 cwd #60 .mli4 ___timezone, ___timezone+2, -12() cmpb I005D I005E I005D: I005E: ___daylight 3 -12() ___tzname+2 _strncpy I0053: _2: 17741 84 _3: 17485 84 _4: 23124 char *getenv(name) register char *name; { extern char **environ; register char **v = environ, *p, *q; while ((p = *v++) != 0) { q = name; while (*q && *q++ == *p++) /* nothing */ ; if (*q || *p != '=') continue; return(p+1); } return(0); } _getenv _getenv _getenv: ,#6 _environ , ,#2 , cmpb je I0015 ,#1 ,#1 I0015 I0016 I0015: cmpb I0013 cmpb ,#61 je I001A I001A: /* * get entry from password file * * By Patrick van Kleef * */ #include "../include/pwd.h" #define PRIVATE static PRIVATE char _pw_file[] = "/etc/passwd"; PRIVATE char _pwbuf[256]; PRIVATE char _buffer[1024]; PRIVATE char *_pnt; PRIVATE char *_buf; PRIVATE int _pw = -1; PRIVATE int _bufcnt; PRIVATE struct passwd pwd; setpwent() { if (_pw >= 0) lseek (_pw, 0L, 0); else _pw = open (_pw_file, 0); _bufcnt = 0; return (_pw); } endpwent () { if (_pw >= 0) close (_pw); _pw = -1; _bufcnt = 0; } static getline () { if (_pw < 0 && setpwent () < 0) return (0); _buf = _pwbuf; do { if (--_bufcnt <= 0){ if ((_bufcnt = read (_pw, _buffer, 1024)) <= 0) return (0); else _pnt = _buffer; } *_buf++ = *_pnt++; } while (*_pnt != '\n'); _pnt++; _bufcnt--; *_buf = 0; _buf = _pwbuf; return (1); } static skip_period () { while (*_buf != ':') _buf++; *_buf++ = '\0'; } struct passwd *getpwent () { if (getline () == 0) return (0); pwd.pw_name = _buf; skip_period (); pwd.pw_passwd = _buf; skip_period (); pwd.pw_uid = atoi (_buf); skip_period (); pwd.pw_gid = atoi (_buf); skip_period (); pwd.pw_gecos = _buf; skip_period (); pwd.pw_dir = _buf; skip_period (); pwd.pw_shell = _buf; return (&pwd); } struct passwd *getpwnam (name) char *name; { struct passwd *pwd; setpwent (); while ((pwd = getpwent ()) != 0) if (!strcmp (pwd -> pw_name, name)) break; endpwent (); if (pwd != 0) return (pwd); else return (0); } struct passwd *getpwuid (uid) int uid; { struct passwd *pwd; setpwent (); while ((pwd = getpwent ()) != 0) if (pwd -> pw_uid == uid) break; endpwent (); if (pwd != 0) return (pwd); else return (0); } _getpwent _setpwent _getpwnam _getpwuid _endpwent __pw_file: 25903 25460 28719 29537 30579 100 __pw: _setpwent -1 _setpwent: __pw jl I0013 __pw _lseek ,#8 I0014 __pw_file _open __pw, I0014: __bufcnt __pw _endpwent _endpwent: __pw jl I0023 __pw _close I0023: __pw,#-1 __bufcnt _getline: __pw jge I0033 _setpwent jge I0033 I0031 I0033: __buf,#__pwbuf I0038: __bufcnt jg I003A 024 __buffer __pw _read __bufcnt, __bufcnt jg I003D I0031 I003D: __pnt,#__buffer I003A: __pnt __pnt,#1 mov __buf (),al __buf,#1 __pnt cmpb ,#10 I0038 __pnt,#1 __bufcnt __buf __buf,#__pwbuf I0031: _skip_period: I0043: __buf cmpb ,#58 je I0042 __buf,#1 I0043 I0042: __buf __buf,#1 _getpwent _getpwent: _getline I0053 I0051 I0053: __buf _pwd, _skip_period __buf _pwd+2, _skip_period __buf _atoi _pwd+4, _skip_period __buf _atoi _pwd+6, _skip_period __buf _pwd+8, _skip_period __buf _pwd+10, _skip_period __buf _pwd+12, _pwd I0051: _getpwnam _getpwnam: _setpwent I0063: _getpwent je I0062 _strcmp I0063 I0062: _endpwent je I0069 I0061 I0069: I0061: _getpwuid _getpwuid: _setpwent I0073: _getpwent je I0072 4, I0073 I0072: _endpwent je I0079 I0071 I0079: I0071: _pwd: .zerow 14/2 __bufcnt: .zerow 2/2 __buf: .zerow 2/2 __pnt: .zerow 2/2 __buffer: .zerow 1024/2 __pwbuf: .zerow 256/2 #define CLICK_SIZE 16 typedef unsigned short vir_bytes; extern bcopy(); #define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1)) #define BUSY 1 #define NEXT(p) (* (char **) (p)) extern char *sbrk(); static char *bottom, *top; static grow(len) unsigned len; { register char *p; p = (char *) ALIGN((vir_bytes) top + sizeof(char *) + len, CLICK_SIZE) - sizeof(char *); if (p < top || brk(p) < 0) return(0); top = p; for (p = bottom; NEXT(p) != 0; p = (char *) (* (vir_bytes *) p & ~BUSY)) ; NEXT(p) = top; NEXT(top) = 0; return(1); } char *malloc(size) unsigned size; { register char *p, *next, *new; register unsigned len = ALIGN(size, sizeof(char *)) + sizeof(char *); if ((p = bottom) == 0) { top = bottom = p = sbrk(sizeof(char *)); NEXT(top) = 0; } while ((next = NEXT(p)) != 0) if ((vir_bytes) next & BUSY) /* already in use */ p = (char *) ((vir_bytes) next & ~BUSY); else { while ((new = NEXT(next)) != 0 && !((vir_bytes) new & BUSY)) next = new; if (next - p >= len) { /* fits */ if ((new = p + len) < next) /* too big */ NEXT(new) = next; NEXT(p) = (char *) ((vir_bytes) new | BUSY); return(p + sizeof(char *)); } p = next; } return grow(len) ? malloc(size) : 0; } char *realloc(old, size) char *old; unsigned size; { register char *p = old - sizeof(char *), *next, *new; register unsigned len = ALIGN(size, sizeof(char *)) + sizeof(char *), n; next = (char *) (* (vir_bytes *) p & ~BUSY); n = next - old; /* old size */ while ((new = NEXT(next)) != 0 && !((vir_bytes) new & BUSY)) next = new; if (next - p >= len) { /* does it still fit */ if ((new = p + len) < next) { /* even too big */ NEXT(new) = next; NEXT(p) = (char *) ((vir_bytes) new | BUSY); } else NEXT(p) = (char *) ((vir_bytes) next | BUSY); return(old); } if ((new = malloc(size)) == 0) /* it didn't fit */ return(0); bcopy(old, new, n); /* n < size */ * (vir_bytes *) p &= ~BUSY; return(new); } char *calloc(m,size) unsigned m,size; { char *malloc(); char *cp; register int i; register char *temp; i = m*size; if ((cp=malloc(i))==(char *)0) return (char *)0; /* malloc succeeded--clear allocated memory */ for (temp = cp ; i-- ; ) *temp++ = '\0'; return cp; } free(p) char *p; { * (vir_bytes *) (p - sizeof(char *)) &= ~BUSY; } _calloc _malloc _free _realloc _grow: _top 2 15 65520 -2 , _top , jb I0012 _brk jge I0013 _top, _bottom , I0019: je I0016 65534 I0019 _top (), _top _malloc _malloc: ,#8 1 65534 2 , _bottom , _bottom I0026 _sbrk _bottom, _top, I0026: () 0 je I0025 testb ,#1 je I002C and 65534 I0026 I002C: () , 0 je I002B testb ,#1 I002B I002C I002B: , ja I00210 mul , , jae I00213 I00213: or 1 2 I0021 I00210: I0026 I0025: _grow je I00216 _malloc I0021 I00216: I0021: _realloc _realloc: ,#12 -2 , 1 65534 2 , 65534 -10(), I0033: () , 0 je I0032 testb ,#1 I0032 I0033 I0032: , ja I0037 mul , , jae I003A or 1 I003B I003A: or 1 I003B: I0031 I0037: _malloc , I003D I0031 I003D: -10() _bcopy -12(), -12() 65534 I0031: _calloc _calloc: ,#6 mul _malloc I0043 push I0041 I0043: , I0048: je I0045 ,#1 I0048 I0045: I0041: _free _free: -2 , 65534 _top: .zerow 2/2 _bottom: .zerow 2/2 #include #include static int pids[20]; FILE * popen(command, type) char *command, *type; { int piped[2]; int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2; int pid; if (Xtype == 2 || pipe(piped) < 0 || (pid = fork()) < 0) return 0; if (pid == 0) { /* child */ register int *p; for (p = pids; p < &pids[20]; p++) { if (*p) close(p - pids); } close(piped[Xtype]); dup2(piped[!Xtype], !Xtype); close(piped[!Xtype]); execl("/bin/sh", "sh", "-c", command, (char *) 0); _exit(127); /* like system() ??? */ } pids[piped[Xtype]] = pid; close(piped[!Xtype]); return fdopen(piped[Xtype], type); } pclose(iop) FILE *iop; { int fd = fileno(iop); int status, wret; int (*intsave)() = signal(SIGINT, SIG_IGN); int (*quitsave)() = signal(SIGQUIT, SIG_IGN); fclose(iop); while ((wret = wait(&status)) != -1) { if (wret == pids[fd]) break; } if (wret == -1) status = -1; signal(SIGINT, intsave); signal(SIGQUIT, quitsave); pids[fd] = 0; return status; } _popen _pclose _popen _popen: ,#10 cmpb ,#114 I0013 I0014 cmpb ,#119 I0016 I0014 I0014: ,#2 je I0018 _pipe jl I0018 _fork , jge I0019 I0018: I0019: I001E -10(),#_pids I00113: -10(),#_pids+40 jae I00110 -10() je I00111 -10() _pids cwd iv _close I00111: -10(),#2 3 I00110: sal 1 -4(_) _close je I00117 9 I00117: I00119: je I0011A C I0011A: I0011C: sal 1 _dup2 ax, je I0011D F I0011D: I0011F: sal 1 _close _3 _2 _1 _execl ,#10 27 __exit I001E: sal 1 -4(_) sal 1 _pids, 0 I00122 I00120: I00122: sal 1 _close sal 1 -4(_) _fdopen _pclose _pclose: ,#10 _gnal , 3 _gnal -10(), _fclose I0023: -4() _wait , ,#-1 je I0022 sal 1 _pids , I0023 I0022: ,#-1 I0029 ,#-1 I0029: _gnal -10() 3 _gnal sal 1 _pids _pids: .zerow 40/2 _1: 25135 28265 29487 104 _2: 26739 _3: 25389 /* This is a special version of printf. It is used only by the operating * system itself, and should never be included in user programs. The name * printk never appears in the operating system, because the macro printf * has been defined as printk there. */ #define MAXDIGITS 12 printk(s, arglist) char *s; int *arglist; { int w, k, r, *valp; unsigned u; char **pp; long l, *lp; char a[MAXDIGITS], *p, *p1, c; valp = (int *) &arglist; while (*s != '\0') { if (*s != '%') { putc(*s++); continue; } w = 0; s++; while (*s >= '0' && *s <= '9') { w = 10 * w + (*s - '0'); s++; } lp = (long *) valp; pp = (char **) valp; switch(*s) { case 'd': k = *valp++; l = k; r = 10; break; case 'o': k = *valp++; u = k; l = u; r = 8; break; case 'x': k = *valp++; u = k; l = u; r = 16; break; case 'D': l = *lp++; r = 10; valp = (int *) lp; break; case 'O': l = *lp++; r = 8; valp = (int *) lp; break; case 'X': l = *lp++; r = 16; valp = (int *) lp; break; case 'c': k = *valp++; putc(k); s++; continue; case 's': p = *pp++; valp = (int *) pp; p1 = p; while(c = *p++) putc(c); s++; if ( (k = w - (p-p1-1)) > 0) while (k--) putc(' '); continue; default: putc('%'); putc(*s++); continue; } k = bintoascii(l, r, a); if ( (r = w - k) > 0) while(r--) putc(' '); for (r = k - 1; r >= 0; r--) putc(a[r]); s++; } } static int bintoascii(num, radix, a) long num; int radix; char a[MAXDIGITS]; { int i, n, hit, negative; negative = 0; if (num == 0) {a[0] = '0'; return(1);} if (num < 0 && radix == 10) {num = -num; negative++;} for (n = 0; n < MAXDIGITS; n++) a[n] = 0; n = 0; do { if (radix == 10) {a[n] = num % 10; num = (num -a[n])/10;} if (radix == 8) {a[n] = num & 0x7; num = (num >> 3) & 0x1FFFFFFF;} if (radix == 16) {a[n] = num & 0xF; num = (num >> 4) & 0x0FFFFFFF;} n++; } while (num != 0); /* Convert to ASCII. */ hit = 0; for (i = n - 1; i >= 0; i--) { if (a[i] == 0 && hit == 0) { a[i] = ' '; } else { if (a[i] < 10) a[i] += '0'; else a[i] += 'A' - 10; hit++; } } if (negative) a[n++] = '-'; return(n); } _printk _printk _printk: ,#36 _1: I0011F 8 68 I00111 79 I00112 88 I00113 99 I00114 100 I001E 111 I001F 115 I00115 120 I00110 , cmpb cmpb ,#37 je I0016 _putc I0019: 48 jl I0018 57 jg I0018 48 0 mul , I0019 I0018: -1, -12(), I001C I001E: ,#2 cwd -1, -14(bp), ,#10 I001D I001F: ,#2 -10(), -10() -1, -1, ,#8 I001D I00110: ,#2 -10(), -10() -1, -1, , I001D I00111: -1 -1,#4 2 -1, -1 ,#10 -1 , I001D I00112: -1 -1,#4 2 -1, -1 ,#8 -1 , I001D I00113: -1 -1,#4 2 -1, -1 , -1 , I001D I00114: ,#2 _putc I00115: -12() add -12(),#2 -32(), -12() , -32() -3, I00117: -32() -32(),#1 -35(),al je I00116 al,-35() _putc 7 I00116: -32() -3 jle I0013 I0011D: je I0013 32 _putc D I0011F: 37 _putc _putc I001C: #_1 .csb2 I001D: -30() -1 -1 _bintoascii ,#8 , jle I00121 I00124: 1 32 _putc I00124 I00121: , I00129: jl I00126 al,-30(_) _putc I00129 I00126: _bintoascii: ,#10 0 sbb 0 1f or 1: or I0023 10() ,#48 I0021 I0023: 0 sbb 0 1f je 1f 1: or jge I0026 ,#10 I0026 sbb 0 , , I0026: I002C: ,#12 jge I0029 10() I002C I0029: I002F: ,#10 I00211 0 .rmi4 10() ,dl 10() cwd sbb 0 .dvi4 , , I00211: ,#8 I00214 4 4 7 0 10() 3 2: sar 1 rcr 1 1: 65535 8191 , , I00214: , I00217 4 4 15 0 10() 4 2: sar 1 rcr 1 1: 65535 4095 , , I00217: 0 sbb 0 1f or 1: or I002F I0021C: jl I00219 10() cmpb I0021E I0021E 10() ,#32 I0021A I0021E: 10() 10 jge I00222 ,10() -10(), -10() 48 I00223 I00222: 10() -10(), -10() 55 I00223: I0021A: I0021C I00219: je I00225 45 10() I00225: I0021: #include "../include/stdio.h" putc(ch, iop) char ch; FILE *iop; { int n, didwrite = 0; if (testflag(iop, (_ERR | _EOF))) return (EOF); if ( !testflag(iop,WRITEMODE)) return(EOF); if ( testflag(iop,UNBUFF)){ n = write(iop->_fd,&ch,1); iop->_count = 1; didwrite++; } else{ *iop->_ptr++ = ch; if ((++iop->_count) >= BUFSIZ && !testflag(iop,STRINGS) ){ n = write(iop->_fd,iop->_buf,iop->_count); iop->_ptr = iop->_buf; didwrite++; } } if (didwrite){ if (n<=0 || iop->_count != n){ if (n < 0) iop->_flags |= _ERR; else iop->_flags |= _EOF; return (EOF); } iop->_count=0; } return(ch & CMASK); } _putc _putc _putc: ,#6 testb 4,#24 je I0013 -1 testb 4,#2 I0016 -1 testb 4,#4 je I0019 _write 2,#1 I001A I0019: 8 , al, (),#1 2 , ,#1024 jl I001A testb 4,#128 I001A 2 6() () _write 6 8(), I001A: je I00110 jle I00112 2, je I00113 I00112: jge I00117 add 4 , or 16 8 I00117: 4 , or 8 I00118: -1 I00113: 2 I00110: al, #include "stdio.h" int puts(s) char *s; { char c; c = fputs(s,stdout); putchar('\n'); return(c); } _puts _puts _puts: __io_table+2 _fputs -1(),al __io_table+2 0 _putc al,-1() static qsort1(); static int (*qcompar)(); static qexchange(); static q3exchange(); qsort(base, nel, width, compar) char *base; int (*compar)(); { qcompar = compar; qsort1(base, base + (nel - 1) * width, width); } static qsort1(a1, a2, width) char *a1, *a2; register int width; { register char *left, *right; register char *lefteq, *righteq; int cmp; for (;;) { if (a2 <= a1) return; left = a1; right = a2; lefteq = righteq = a1 + width * (((a2-a1)+width)/(2*width)); /* Pick an element in the middle of the array. We will collect the equals around it. "lefteq" and "righteq" indicate the left and right bounds of the equals respectively. Smaller elements end up left of it, larger elements end up right of it. */ again: while (left < lefteq && (cmp = (*qcompar)(left, lefteq)) <= 0) { if (cmp < 0) { /* leave it where it is */ left += width; } else { /* equal, so exchange with the element to the left of the "equal"-interval. */ lefteq -= width; qexchange(left, lefteq, width); } } while (right > righteq) { if ((cmp = (*qcompar)(right, righteq)) < 0) { /* smaller, should go to left part */ if (left < lefteq) { /* yes, we had a larger one at the left, so we can just exchange */ qexchange(left, right, width); left += width; right -= width; goto again; } /* no more room at the left part, so we move the "equal-interval" one place to the right, and the smaller element to the left of it. This is best expressed as a three-way exchange. */ righteq += width; q3exchange(left, righteq, right, width); lefteq += width; left = lefteq; } else if (cmp == 0) { /* equal, so exchange with the element to the right of the "equal-interval" */ righteq += width; qexchange(right, righteq, width); } else /* just leave it */ right -= width; } if (left < lefteq) { /* larger element to the left, but no more room, so move the "equal-interval" one place to the left, and the larger element to the right of it. */ lefteq -= width; q3exchange(right, lefteq, left, width); righteq -= width; right = righteq; goto again; } /* now sort the "smaller" part */ qsort1(a1, lefteq - width, width); /* and now the larger, saving a subroutine call because of the for(;;) */ a1 = righteq + width; } /*NOTREACHED*/ } static qexchange(p, q, n) register char *p, *q; register int n; { register int c; while (n-- > 0) { c = *p; *p++ = *q; *q++ = c; } } static q3exchange(p, q, r, n) register char *p, *q, *r; register int n; { register int c; while (n-- > 0) { c = *p; *p++ = *r; *r++ = *q; *q++ = c; } } _qsort _qsort _qsort: 10() _qcompar, mul _qsort1 _qsort1: ,#14 I0025: , ja I0027 I0027: sal 1 cwd iv mul , , I002B: , jae I00212 _qcompar -10(), -10() jg I00212 -10() jge I002F , I002B I002F: , _qexchange I002B I00212: , jbe I00211 _qcompar -10(), cmp -10() jge I00215 , jae I00218 _qexchange , , I002B I00218: , _q3exchange ,#8 , I00212 I00215: -10() I0021B , _qexchange I00212 I0021B: , I00212 I00211: , jae I0021E , _q3exchange ,#8 , I002B I0021E: _qsort1 , I0025 _qexchange: I0033: jle I0032 (),al ,#1 I0033 I0032: _q3exchange: I0043: 10() 10() jle I0042 (),al (),al ,#1 ,#1 I0043 I0042: _qcompar: .zerow 2/2 /* scanf - formatted input conversion Author: Patrick van Kleef */ #include "stdio.h" int scanf (format, args) char *format; unsigned args; { return _doscanf (0, stdin, format, &args); } int fscanf (fp, format, args) FILE *fp; char *format; unsigned args; { return _doscanf (0, fp, format, &args); } int sscanf (string, format, args) char *string; /* source of data */ char *format; /* control string */ unsigned args; /* our args */ { return _doscanf (1, string, format, &args); } union ptr_union { char *chr_p; unsigned int *uint_p; unsigned long *ulong_p; }; static int ic; /* the current character */ static char *rnc_arg; /* the string or the filepointer */ static rnc_code; /* 1 = read from string, else from FILE */ /* get the next character */ static rnc () { if (rnc_code) { if (!(ic = *rnc_arg++)) ic = EOF; } else ic = getc ((FILE *) rnc_arg); } /* * unget the current character */ static ugc () { if (rnc_code) --rnc_arg; else ungetc (ic, rnc_arg); } static scnindex(ch, string) char ch; char *string; { while (*string++ != ch) if (!*string) return 0; return 1; } /* * this is cheaper than iswhite from */ static iswhite (ch) int ch; { return (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); } static isdigit (ch) int ch; { return (ch >= '0' && ch <= '9'); } static tolower (ch) int ch; { if (ch >= 'A' && ch <= 'Z') ch = ch + 'a' - 'A'; return ch; } /* * the routine that does the job */ _doscanf (code, funcarg, format, argp) int code; /* function to get a character */ char *funcarg; /* an argument for the function */ char *format; /* the format control string */ union ptr_union *argp; /* our argument list */ { int done = 0; /* number of items done */ int base; /* conversion base */ long val; /* an integer value */ int sign; /* sign flag */ int do_assign; /* assignment suppression flag */ unsigned width; /* width of field */ int widflag; /* width was specified */ int longflag; /* true if long */ int done_some; /* true if we have seen some data */ int reverse; /* reverse the checking in [...] */ char *endbracket; /* position of the ] in format string */ rnc_arg = funcarg; rnc_code = code; rnc (); /* read the next character */ if (ic == EOF) { done = EOF; goto quit; } while (1) { while (iswhite (*format)) ++format; /* skip whitespace */ if (!*format) goto all_done; /* end of format */ if (ic < 0) goto quit; /* seen an error */ if (*format != '%') { while (iswhite (ic)) rnc (); if (ic != *format) goto all_done; ++format; rnc (); ++done; continue; } ++format; do_assign = 1; if (*format == '*') { ++format; do_assign = 0; } if (isdigit (*format)) { widflag = 1; for (width = 0; isdigit (*format);) width = width * 10 + *format++ - '0'; } else widflag = 0; /* no width spec */ if (longflag = (tolower (*format) == 'l')) ++format; if (*format != 'c') while (iswhite (ic)) rnc (); done_some = 0; /* nothing yet */ switch (*format) { case 'o': base = 8; goto decimal; case 'u': case 'd': base = 10; goto decimal; case 'x': base = 16; if (((!widflag) || width >= 2) && ic == '0') { rnc (); if (tolower (ic) == 'x') { width -= 2; done_some = 1; rnc (); } else { ugc (); ic = '0'; } } decimal: val = 0L; /* our result value */ sign = 0; /* assume positive */ if (!widflag) width = 0xffff; /* very wide */ if (width && ic == '+') rnc (); else if (width && ic == '-') { sign = 1; rnc (); } while (width--) { if (isdigit (ic) && ic - '0' < base) ic -= '0'; else if (base == 16 && tolower (ic) >= 'a' && tolower (ic) <= 'f') ic = 10 + tolower (ic) - 'a'; else break; val = val * base + ic; rnc (); done_some = 1; } if (do_assign) { if (sign) val = -val; if (longflag) *(argp++)->ulong_p = (unsigned long) val; else *(argp++)->uint_p = (unsigned) val; } if (done_some) ++done; else goto all_done; break; case 'c': if (!widflag) width = 1; while (width-- && ic >= 0) { if (do_assign) *(argp)->chr_p++ = (char) ic; rnc (); done_some = 1; } if (do_assign) argp++; /* done with this one */ if (done_some) ++done; break; case 's': if (!widflag) width = 0xffff; while (width-- && !iswhite (ic) && ic > 0) { if (do_assign) *(argp)->chr_p++ = (char) ic; rnc (); done_some = 1; } if (do_assign) /* terminate the string */ *(argp++)->chr_p = '\0'; if (done_some) ++done; else goto all_done; break; case '[': if (!widflag) width = 0xffff; if ( *(++format) == '^' ) { reverse = 1; format++; } else reverse = 0; endbracket = format; while ( *endbracket != ']' && *endbracket != '\0') endbracket++; if (!*endbracket) goto quit; *endbracket = '\0'; /* change format string */ while (width-- && !iswhite (ic) && ic > 0 && (scnindex (ic, format) ^ reverse)) { if (do_assign) *(argp)->chr_p++ = (char) ic; rnc (); done_some = 1; } format = endbracket; *format = ']'; /* put it back */ if (do_assign) /* terminate the string */ *(argp++)->chr_p = '\0'; if (done_some) ++done; else goto all_done; break; } /* end switch */ ++format; } all_done: if (ic >= 0) ugc (); /* restore the character */ quit: return done; } _scanf __doscanf _sscanf _fscanf _scanf _scanf: __io_table __doscanf ,#8 _fscanf _fscanf: __doscanf ,#8 _sscanf _sscanf: __doscanf ,#8 _rnc: _rnc_code je I0043 _rnc_arg _rnc_arg,#1 _ic, _ic I0044 _ic,#-1 I0044 I0043: _rnc_arg _getc _ic, I0044: _ugc: _rnc_code je I0053 _rnc_arg,#-1 I0054 I0053: _rnc_arg _ic _ungetc I0054: _scnindex: I0063: ,#1 xorb ah,ah al, je I0062 cmpb I0063 I0061 I0062: I0061: _iswhite: ,#32 je I0072 ,#9 je I0072 ,#10 je I0072 ,#13 je I0072 I0071 I0072: I0071: _isgit: ,#48 jl I0083 ,#57 jg I0083 I0081 I0083: I0081: _tolower: ,#65 jl I0093 ,#90 jg I0093 ,#32 I0093: __doscanf __doscanf: ,#26 _1: I00A32 7 91 I00A86 99 I00A63 100 I00A36 111 I00A33 115 I00A74 117 I00A36 120 I00A37 _rnc_arg, _rnc_code, _rnc _ic,#-1 I00AA ,#-1 I00A5 I00AA: _iswhite je I00A9 ,#1 I00AA I00A9: cmpb I00AD I00AF I00AD: _ic jge I00A11 I00A5 I00A11: cmpb ,#37 je I00A14 I00A17: _ic _iswhite je I00A16 _rnc I00A17 I00A16: _ic, je I00A1A I00AF I00A1A: ,#1 _rnc I00AA I00A14: ,#1 -12(),#1 cmpb ,#42 I00A1D ,#1 -12() I00A1D: _isgit je I00A20 -1,#1 -1 I00A25: _isgit je I00A21 ,#1 0 mul -1 48 -1, I00A25 I00A20: -1 I00A21: _tolower 108 je I00A29 I00A2A I00A29: I00A2A: -1 -1 je I00A27 ,#1 I00A27: cmpb ,#99 je I00A2C I00A2F: _ic _iswhite je I00A2C _rnc I00A2F I00A2C: -20() I00A31 I00A33: ,#8 I00A34 I00A36: ,#10 I00A34 I00A37: , -1 je I00A3B -1,#2 jb I00A34 I00A3B: _ic,#48 I00A34 _rnc _ic _tolower 120 I00A3E -1 2 -1, -20(),#1 _rnc I00A34 I00A3E: _ugc _ic,#48 I00A34: -10() -1 I00A41 -1,#65535 I00A41: -1 je I00A44 _ic,#43 I00A44 _rnc I00A4C I00A44: -1 je I00A4C _ic,#45 I00A4C -10(),#1 _rnc I00A4C: -1 1 -1 -1, je I00A4B _ic _isgit je I00A4F _ic 48 , jle I00A4F _ic 48 _ic, I00A50 I00A4F: , I00A4B _ic _tolower 97 jl I00A4B _ic _tolower 102 jg I00A4B _ic _tolower -87 _ic, I00A50: cwd .mli4 _ic cwd adc , , _rnc -20(),#1 I00A4C I00A4B: -12() je I00A58 -10() je I00A5B sbb 0 , , I00A5B: -1 je I00A5E 4 4 10() 10(),#2 2, I00A58 I00A5E: 10() 10(),#2 I00A58: -20() je I00AF I00A32 I00A63: -1 I00A68 -1,#1 I00A68: -1 1 -1 -1, je I00A67 _ic jl I00A67 -12() je I00A6C 10() -2, 10() -2 _ic (), I00A6C: _rnc -20(),#1 I00A68 I00A67: -12() je I00A6F 10(),#2 I00A6F: -20() je I00A32 I00A32 I00A74: -1 I00A79 -1,#65535 I00A79: -1 1 -1 -1, je I00A78 _ic _iswhite I00A78 _ic jle I00A78 -12() je I00A7E 10() -2, 10() -2 _ic (), I00A7E: _rnc -20(),#1 I00A79 I00A78: -12() je I00A81 push 10() 10(),#2 I00A81: -20() je I00AF I00A32 I00A86: -1 I00A88 -1,#65535 I00A88: ,#1 cmpb ,#94 I00A8B -22(),#1 ,#1 I00A8C I00A8B: -22() I00A8C: -2, I00A8E: -2 cmpb ,#93 je I00A8D -2 cmpb je I00A8D -2,#1 I00A8E I00A8D: -2 cmpb I00A92 I00A5 I00A92: -2 I00A95: -1 1 -1 -1, je I00A94 _ic _iswhite I00A94 _ic jle I00A94 _ic _scnindex -22() je I00A94 -12() je I00A9B 10() -2, 10() -2 _ic (), I00A9B: _rnc -20(),#1 I00A95 I00A94: -2 , ,#93 -12() je I00A9E 10() 10(),#2 I00A9E: -20() je I00AF I00A32 I00A31: #_1 .csb2 I00A32: ,#1 I00AA I00AF: _ic jl I00A5 _ugc I00A5: _rnc_code: .zerow 2/2 _rnc_arg: .zerow 2/2 _ic: .zerow 2/2 #include #ifndef NIL #define NIL 0 #endif system( cmd ) char *cmd; { int retstat, procid, waitstat; if( (procid = fork()) == 0 ) { execl( "/bin/sh", "sh", "-c", cmd, NIL ); exit( 127 ); } while( (waitstat = wait(&retstat)) != procid && waitstat != -1 ) ; if (waitstat == -1) retstat = -1; return( retstat ); } _system _system _system: ,#6 _fork I0016 _3 _2 _1 _execl ,#10 27 _exit _wait , , je I0015 ,#-1 je I0015 I0016 I0015: ,#-1 I001A ,#-1 I001A: _1: 25135 28265 29487 104 _2: 26739 _3: 25389 E2