Task: Strip block comments

C: #include <stdio.h>
#include <string.h>
#include <stdlib.h>

const char *ca = "";
int al = 2, bl = 2;

char *loadfile(const char *fn) {
    FILE *f = fopen(fn, "rb");
    int l;
    char *s;

    if (f != NULL) {
	fseek(f, 0, SEEK_END);
	l = ftell(f);
	s = malloc(l+1);
	rewind(f);
	if (s)
	    fread(s, 1, l, f);
	fclose(f);
    }
    return s;
}

void stripcomments(char *s) {
    char *a, *b;
    int len = strlen(s) + 1;

    while ((a = strstr(s, ca)) != NULL) {
	b = strstr(a+al, cb);
	if (b == NULL)
	    break;
	b += bl;
	memmove(a, b, len-(b-a));
    }
}

int main(int argc, char **argv) {
    const char *fn = "input.txt";
    char *s;

    if (argc >= 2)
	fn = argv[1];
    s = loadfile(fn);
    if (argc == 4) {
	al = strlen(ca = argv[2]);
	bl = strlen(cb = argv[3]);
    }
    stripcomments(s);
    puts(s);
    free(s);
    return 0;
}










Fortran:       SUBROUTINE UNBLOCK(THIS,THAT)	
Copies from file INF to file OUT, record by record, except skipping null output records.
       CHARACTER*(*) THIS,THAT	
       INTEGER LOTS			
       PARAMETER (LOTS = 6666)		
       CHARACTER*(LOTS) ACARD,ALINE	
       INTEGER LC,LL,L		
       INTEGER L1,L2		
       INTEGER NC,NL		
       LOGICAL BLAH		
       INTEGER MSG,KBD,INF,OUT		
       COMMON /IODEV/MSG,KBD,INF,OUT	
        NC = 0		
        NL = 0		
        BLAH = .FALSE.	
Chug through the input.
   10   READ(INF,11,END = 100) LC,ACARD(1:MIN(LC,LOTS))	
   11   FORMAT (Q,A)		
        NC = NC + 1		
        IF (LC.GT.LOTS) THEN	
          WRITE (MSG,12) NC,LC,LOTS	
   12     FORMAT ("Record ",I0," has length ",I0,"
          LC = LOTS			
        END IF			
Chew through ACARD according to mood.
        LL = 0		
        L2 = 0		
   20   L1 = L2 + 1	
        IF (L1.LE.LC) THEN	
          L2 = L1		
          IF (BLAH) THEN	
   21       IF (L2 + LEN(THAT) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THAT) - 1).EQ.THAT) THEN	
                BLAH = .FALSE.		
                L2 = L2 + LEN(THAT) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 21		
            END IF	
           ELSE		
   22       IF (L2 + LEN(THIS) - 1 .LE. LC) THEN	
              IF (ACARD(L2:L2 + LEN(THIS) - 1).EQ.THIS) THEN	
                BLAH = .TRUE.		
                L = L2 - L1		
                ALINE(LL + 1:LL + L) = ACARD(L1:L2 - 1)	
                LL = LL + L		
                L2 = L2 + LEN(THIS) - 1	
                GO TO 20		
              END IF		
              L2 = L2 + 1	
              GO TO 22		
            END IF	
            L = LC - L1 + 1	
            ALINE(LL + 1:LL + L) = ACARD(L1:LC)	
            LL = LL + L		
          END IF	
        END IF	
Cast forth some output.
        IF (LL.GT.0) THEN	
          WRITE (OUT,23) ALINE(1:LL)	
   23     FORMAT (">",A,"<") 		
          NL = NL + 1			
        END IF        		
        GO TO 10	
Completed.
  100   WRITE (MSG,101) NC,NL	
  101   FORMAT (I0," read, ",I0," written.")
      END       

      PROGRAM TEST
      INTEGER MSG,KBD,INF,OUT
      COMMON /IODEV/MSG,KBD,INF,OUT
      KBD = 5
      MSG = 6
      INF = 10
      OUT = 11
      OPEN (INF,FILE="Source.txt",STATUS="OLD",ACTION="READ")
      OPEN (OUT,FILE="Src.txt",STATUS="REPLACE",ACTION="WRITE")

      CALL UNBLOCK("/*","*/")

      END