FINE MAXLINE 1000 /* MAX. INPUT LINE SIZE*/ CHAR LINE[MAXLINE]; /* INPUT LINE */ CHAR SAVE[MAXLINE];/* LONGEST LINE SAVED HERE*/ INT MAX;/*LENGTH OF LONGEST LINE SEEN SO FAR*/ MAIN() /*FIND LONGEST LINE; SPECIALIZED VERSION*/ { INT LEN; EXTERN INT MAX; EXTERN CHAR SAVE[]; MAX = 0; WHILE ( (LEN = GETLINE()) > 0 ) IF ( LEN > MAX ) { MAX = LEN; COPY(); } IF ( MAX > 0 ) /* THERE WAS A LINE */ PRINTF( "%S", SAVE ); } GETLINE() /* SPECIALIZED VERSION */ { INT C, I; EXTERN CHAR LINE[]; FOR (I = 0; I < MAXLINE-1 && (C=GETCHAR()) !=EOF && C!='\N'; ++I) LINE[I] = C; ++I; } LINE[I] = '\0' RETURN(I) } COPY() /* SPECIALIZED VERSION */ { INT I; EXTERN CHAR LINE[], SAVE[]; I = 0; WHILE ((SAVE[I] = LINE[I]) !='\0') ++I; } MAIN, GETLINE COPY - , - - . , - , , - , . - , . - EXTERN; EXTERN. EXTERN - : , - , EXTERN . EXTERN MAIN, GETLINE COPY , , . , - EXTERN. , , 1, - 2, - , 2 EXTERN. 4. , - . "" - , - ; "" , , . , , , , , , - - , - . , . - , , - . - , - , . , , , , .  1-18 --------------- FOR GETLINE - . , , - . ? 1.11.  , "C". , , , - - : - , , . "C", . , , , "C", - .  1-19 --------------- DETAB, , - . - , , N .  1-20 ---------------- ENTAB, - , . - , DETAB.  1-21 ---------------- "" , N , N - . , - - , , .  1-22 ---------------- "C"- - . "- " .  1-23 ---------------- "C"- - , , . , , , . ( , ).  * 2. , *  , . - , , , - , . , - . - . - . 2.1.  , - - . ; - . "_" ; . ; - "" - , - . , . , , - , - . - . , IF, ELSE, INT, FLOAT .., : . ( ). , - , , - , - . 2.2.  "C" - : CHAR , . INT , - . FLOAT . DOUBLE . , - INT: SHORT (), LONG () UNSIGNED ( ). SHORT LONG . - 2 N, N - - INT; . : SHORT INT X; LONG INT Y; UNSIGNED INT Z; C INT , . , ; - . 1 --------------------------------------------------------- ! DEC PDP-11 HONEYWELL IBM 370 INTERDATA ! 6000 8/32 ! ! ASCII ASCII EBCDIC ASCII ! ! CHAR 8-BITS 9-BITS 8-BITS 8-BITS ! INT 16 36 32 32 ! SHORT 16 36 16 16 ! LONG 32 36 32 32 ! FLOAT 32 36 32 32 ! DOUBLE 64 72 64 64 ! ! --------------------------------------------------------- , SHORT LONG - - ; INT "" . , SHORT LONG - . , - , , SHORT , LONG. 2.3.  INT FLOAT . , 123.456-7, "" 0.123 FLOAT . DOUBLE, "E" FLOAT, DOUBLE. 123L. - , INT, - LONG. - : 0() INT , 0X . , - 31 037 - 0X1F . - L, LONG. 2.3.1.  - , , , , ''. - . , ASCII , '0', 48, EBCDIC - 240, 0. '0' , 48 240, - . - - , , - . - . - , , , \N ( ), \T (), \0 ( ), \\ ( ), \' ( ) .. , . , - , '\DDD' DDD - , #DEFINE FORMFEED '\014' /* FORM FEED */ '\0', - 0, 0 , . 2.3.2.  - , - . - , , , - , , #DEFINE MAXLINE 1000 CHAR LINE[MAXLINE+1]; SECONDS = 60 * 60 * HOURS; 2.3.3.  - , , , , , "I AM A STRING" /* - */ "" /* NULL STRING */ /* - */ , . , - , ; \". , . - , - - \0. , - , , , . , - . STRLEN(S) - S \0. STRLEN(S) /* RETURN LENGTH OF S */ CHAR S[]; { INT I; I = 0; WHILE (S[I] != '\0') ++I; RETURN(I); } , : 'X' - , "X". - , , . - , ( ) \0. 2.4.  , , . - , , , , INT LOWER, UPPER, STEP; CHAR C, LINE[1000]; - ; INT LOWER; INT UPPER; INT STEP; CHAR C; CHAR LINE[1000]; , - . - , . - , , , , CHAR BACKSLASH = '\\'; INT I = 0; FLOAT EPS = 1.0E-5; , , . - , . , - , , (.. ). , , , . , . 2.5.  +, -, *, / %. -, +. . X % Y X Y , , , Y . , - , 4, 100, , 400 . - IF(YEAR % 4 == 0 && YEAR % 100 != 0 \!\! YEAR % 400 == 0) ELSE % FLOAT DOUBLE. + - , *, / %, - . . ( ). - + - ; - - , . , +(B+C) - (A+B)+C. - - , , - . , - (.. - ), . 2.6.  => > =< < . - - : == != . - , I<LIM-1 I<(LIM-1), . && \!\! . , && \!\!, , - , . - . , , - GETLINE, 1. FOR(I=0;I<LIM-1 && (C=GETCHAR()) != '\N' && C != EOF; ++I) S[I]=C; , , S, I<LIM-1 . - , . 'C' EOF - GETCHAR : , . && , \!\!, . - , I<LIM-1 && (C = GETCHAR()) != '\N' && C != EOF . != , (C = GETCHAR()) != '\N' . ! 0, 1. ! IF( ! INWORD ) IF( INWORD == 0 ) T , . ! INWORD (" "). .  2-1 --------------- , FOR, &&. 2.7.  , - . , , , , , F+I. - , , - FLOAT , . -, CHAR INT : CHAR - INT. - . ATOI, . ATOI(S) /* CONVERT S TO INTEGER */ CHAR S[]; { INT I, N; N = 0; FOR ( I = 0; S[I]>='0' && S[I]<='9'; ++I) N = 10 * N + S[I] - '0'; RETURN(N); } KAK 1, S[I] - '0' S[I] , '0', '1' .. . CHAR INT LOWER, . - , LOWER . ASCII. LOWER(C) /* CONVERT C TO LOWER CASE; ASCII ONLY */ INT C; { IF ( C >= 'A' && C <= 'Z' ) RETURN( C + '@' - 'A'); ELSE /*@ 'A' */ RETURN(C); } ASCII, , , , - Z , . EBCDIC IBM 360/370 , - . - . , - , CHAR - . - CHAR INT ? - , , - . (PDP-11, ) CHAR, 1, (" "). - , - . "C" , - , - . - , , , . , 1 EOF. CHAR C; C = GETCHAR(); IF ( C == EOF ) ... , , '' , CHAR, EOF , . , - INT CHAR - , GETCHAR. INT CHAR - - . GETCHAR ( ) , , EOF. - EOF CHAR, INT. , , I>J, , && \!\!, - 1, , 0, . , ISDIGIT = C >= '0' && C <= '9'; ISDIGIT 1, - , 0 - . ( IF, WHILE, FOR .. "" " "). - , . , + *, ( ), , "" "" - "" . , . - CHAR SHORT INT, FLOAT DOUBLE. - , DOUBLE, DOUBLE, DOUBLE. - , LONG, LONG, LONG. - , UNSIGNED, UNSIGNED UNSIGNED. - INT, INT. , FLOAT - DOUBLE; "C" - . ; , . - , , . INT CHAR - . - INT I; CHAR C; I = C; C = I; '' . , . FLOAT, I INT, = I; I = ; ; FLOAT INT . DOUBLE FLOAT . - CHAR - . , - : , CHAR SHORT INT, FLOAT DOUBLE. INT DOUBLE , CHAR FLOAT. , ("") - , (CAST). , ( ) , . : , . - , SQRT DOUBLE , - - . , N - , SQRT((DOUBLE) N) SQRT N DOUBLE. (, N ; N ). - , - , .  2-2 --------------- HTOI(S), - - . 1 9 F. 2.8.  "C" . - ++ 1 , - -- 1. ++ , , , IF(C == '\N') ++I; , ++ -- ( , ++N), ( : N++). N. ++N N , N++ N , . , , , , ++N N++ - . N = 5, = N++; 5, = ++N; 6. N 6. ; =(I+J)++ . , , , , , IF ( C == '\N' ) NL++; . , - . , , SQUEEZE(S,C), '' S, , . SQUEEZE(S,C) /* DELETE ALL C FROM S */ CHAR S[]; INT C; { INT I, J; FOR ( I = J = 0; S[I] != '\0'; I++) IF ( S[I] != C ) S[J++] = S[I]; S[J] = '\0'; } , , '', - J, J - 1, . IF ( S[I] != C ) { S[J] = S[I]; J++; } GETLINE, 1, IF ( C == '\N' ) { S[I] = C; ++I; } IF ( C == '\N' ) S[I++] = C; STRCAT(S,T), S, S . , S . STRCAT(S,T) /* CONCATENATE T TO END OF S */ CHAR S[], T[]; /* S MUST BE BIG ENOUGH */ { INT I, J; I = J = 0; WHILE (S[I] != '\0') / *FIND END OF S */ I++; WHILE((S[I++] = T[J++]) != '\0') /*COPY T*/ ; } T T S , ++ - I J.  2-3 --------------- SQUEEZE(S1,S2), S1 , - S2.  2-4 --------------- ANY(S1,S2), - S1 - S2 , S1 S2, -1. 2.9.  ; FLOAT DOUBLE. & AND \! OR ^ OR << >> \^ ( ) "\" . AND ; , C = N & 0177 '' N , - . '' OR - : C = X MASK , MASK. & '' && \!\! , - . , =1, Y=2, &Y , X&&Y ./?/ << >> , . , <<2 , , 4. - , PDP-11, - /" "/, - /" "/. \^ ; - , 1 0 . - X & \^077 . , X&\^077 , , , X&0177700, - , 16 . , \^077 - , , . , GETBITS(X,P,N), - / / N . , 0, N - - . , GETBITS(,4,3) - , 4,3 2. GETBITS(X,P,N) /* GET N BITS FROM POSITION P */ UNSIGNED X, P, N; { RETURN((X >> (P+1-N)) & \^(\^0 << N)); } X >> (P+1-N) . X UNSIGNED , - , , , . \^0 1; N - \^0<<N N ; \^ N .  2-5 --------------- GETBITS , - .  2-6 --------------- WORDLENGTH(), , .. - INT. , .. .  2-7 --------------- RIGHTROT(N,B), N B .  2-8 --------------- INVERT(X,P,N), (.. 1 0 ) N X, - P, . 2.10.  , I = I + 2 I += 2 +=. ( +, - ) =, - + - * / % << >> & \^ \! 1 2 - , 1 = 2 1 = (1) (2) , 1 . 2: X *= Y + 1 X = X * (Y + 1) X = X * Y + 1 BITCOUNT, 1 . BITCOUNT(N) /* COUNT 1 BITS IN N */ UNSIGNED N; ( INT B; FOR (B = 0; N != 0; N >>= 1) IF (N & 01) B++; RETURN(B); ) , , . : " 2 I" " I 2", " I, 2 I". , I += 2. , , YYVAL[YYPV[P3+P4] + YYPV[P1+P2]] += 2 T , , , - , . - - . , ; WHILE ((C = GETCHAR()) != EOF) , (+=, -= ..) , - . .  2-9 --------------- X&(X-1) 1 X.(?) BITCOUNT. 2.11.  IF (A > B) Z = A; ELSE Z = B; Z . , "?:", - . 1 ? 2 : 3 1. (), 2, . - 3, . - 2 3. , Z , Z = (A > B) ? A : B; /* Z = MAX(A,B) */ , - , . 2 3 , , . , F FLOAT, N - INT, (N > 0) ? F : N DOUBLE , N . ?: , , - . , , . - . , - N , 10 , ( ) . OR (I = 0; I < N; I++) PRINTF("%6D%C",A[I],(I%10==9 \!\! I==N-1) ? '\N' : ' ') N- . - . , , - , , - .  2-10 --------------- LOWER, , IF-ELSE . 2.12.  - , , . , , ; - . , , *, / % , , - + -. OPERATOR ASSOCIATIVITY () [] -> . LEFT TO RIGHT ! \^ ++ -- - (TYPE) * & SIZEOF RIGHT TO LEFT * / % LEFT TO RIGHT + - LEFT TO RIGHT << >> LEFT TO RIGHT < <= > >= LEFT TO RIGHT == != LEFT TO RIGHT & LEFT TO RIGHT ^ LEFT TO RIGHT \! LEFT TO RIGHT && LEFT TO RIGHT \!\! LEFT TO RIGHT ?: RIGHT TO LEFT = += -= ETC. RIGHT TO LEFT , (CHAPTER 3) LEFT TO RIGHT -> . - ; 6 SIZEOF ( ). 5 * ( - ) & (). , - &, ^ == !=. , , - IF ((X & MASK) == 0) ... .