/* Find all lines longer than a certain length, 80 by default 
   usage: getlonglines filename <length> 
*/

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

#define LRAW 110
#define LRAWFOOTNOTESIZE 122
#define LRAWSCRIPTSIZE 140

int main(int argc, char **argv)
{
    int length, lmax = 110;
    char buf1[1024], buf2[1024];
    FILE *fp;
    if (argc < 2) {
	fprintf(stderr, "Usage %s filename <length.\n", argv[0]);
	exit(-1);
    }

    if (!(fp = fopen(argv[1], "r"))) {
	fprintf(stderr, "couldn't open %s\n", argv[1]);
	exit(-1);
    }

    while (fgets(buf1, 1024, fp)) {

	lmax = LRAW;
	if (strstr(buf1, "\\begin{raw")) {
	    fgets(buf2, 1024, fp);
	    if (!strstr(buf2, "\\end{raw")) {
		length = strlen(buf2);
		if (length > lmax)
		    printf("RAW:%s: %d : %s", argv[1], length, buf2);
	    }
	}

	lmax = LRAWFOOTNOTESIZE;
	if (strstr(buf1, "\\begin{rawfootnotesize")) {
	    fgets(buf2, 1024, fp);
	    if (!strstr(buf2, "\\end{raw")) {
		length = strlen(buf2);
		if (length > lmax)
		    printf("RAWFOOTNOTESIZE:%s: %d : %s", argv[1],
			   length, buf2);
	    }
	}

	lmax = LRAWSCRIPTSIZE;
	if (strstr(buf1, "\\begin{rawscriptsize")) {
	    fgets(buf2, 1024, fp);
	    if (!strstr(buf2, "\\end{rawscriptsize")) {
		length = strlen(buf2);
		if (length > lmax)
		    printf("RAW_SCRIPTSIZE:%s: %d : %s", argv[1], length, buf2);
	    }
	}

    }
    fclose(fp);
    exit(0);
}
