home *** CD-ROM | disk | FTP | other *** search
- /* */
- /* CURLY A debugging program written in BDS C Version 1.5 */
- /* Written by Michael Girle */
- /* */
-
- #include <bdscio.h>
- #define MAX_NUM_LINES 250
- #define CHARS_PER_LINE 80
- #define MAX_NESTING 12
-
- main(argc,argv)
- char **argv;
- {
- int i, j, k, l, m, count, maxbr, nol, pos, errchk1, errchk2;
- char str1[15], str2[15];
- char array1[MAX_NUM_LINES][2+CHARS_PER_LINE],
- array3[MAX_NUM_LINES][MAX_NESTING],
- array2[MAX_NUM_LINES][MAX_NESTING],
- ibuf[BUFSIZ], obuf[BUFSIZ],
- linbuf[MAXLINE];
-
- /* Initialisation */
-
- printf("Initialising variables . . . please wait\n");
- i=0;j=0;k=0;l=0;m=0;count=0;maxbr=0;nol=0;pos=0;errchk1=0;errchk2=0;
- for (i=&array1[0][0];i<=&array1[MAX_NUM_LINES-1][CHARS_PER_LINE+1];i++)
- poke (i,0);
- for (i=&array2[0][0];i<=&array2[MAX_NUM_LINES-1][MAX_NESTING-1];i++)
- poke (i,0);
- for (i=&array3[0][0];i<=&array3[MAX_NUM_LINES-1][MAX_NESTING-1];i++)
- poke (i,32);
-
- printf("Warning *** Maximum capacity - %d lines of %d chars each\n\n"
- ,MAX_NUM_LINES,CHARS_PER_LINE);
-
- /* Getting the first filename */
-
- if ((argc != 2) && (argc != 3)) {
- printf("Error - wrong no. of file names\n");
- printf("Use the form - A>curly X:XXXXX.XXX Y:YYYYY.YYY\n");
- exit();}
- strcpy(str1,argv[1]);
- for(i=0;i<strlen(str1);i++)
- if (str1[i] == '.') /* Adjust for '.C' where necessary */
- break;
- if (i>=strlen(str1)) {
- str1[i] = '.';str1[i+1] = 'C';str1[i+2] = 0;}
-
- /* Getting second filename */
-
- if (argc == 3)
- strcpy(str2,argv[2]);
- else strcpy(str2,str1); /* Copy first filename if */
- /* no second name is given */
-
- for (i=0;i<strlen(str2);i++)
- if (str2[i] == '.') /* Adjust for .CUR where necessary */
- break;
- if ((i >= strlen(str2)) || (strcmp(str1,str2) == 0)) {
- str2[i] = '.';str2[i+1]='C';
- str2[i+2]='U';str2[i+3]='R';}
-
- if (strcmp(str1,str2) == 0) {
- printf("Initial file name has the form .CUR - Fatal error\n");
- exit();}
-
- if (fopen(str1,ibuf) == -1) {
- printf("Cannot open filename %s\n",str1);
- exit();
- }
- /* Load the program in */
-
- nol = 0;
- for (i=0;i<MAX_NUM_LINES;i++) {
- if (fgets(linbuf,ibuf) == 0) {
- nol = i;break;}
- strcpy(&array1[i][0],linbuf);
- }
- fclose(ibuf);
- if (i == MAX_NUM_LINES) {
- printf("Program too long error\n");
- exit();
- }
-
- /* Lets get down to business */
- /* First the calculating of how */
- /* many nests of curly braces. */
-
- printf("%d lines found\n",nol);
-
- errchk1 = 0;errchk2 = 0;
- for (i=0;i<=nol;i++)
- for(j=0;j<1+CHARS_PER_LINE;j++) {
-
- /* Check to see if a comment starts or ends */
-
- if ((check(&array1[i][j],'/') == 1) &&
- check(&array1[i][j+1],'*') == 1) errchk2 = 1;
- if ((check(&array1[i][j],'*') == 1) &&
- check(&array1[i][j+1],'/') == 1) errchk2 = 0;
-
- /* Check to see if a double quote starts or ends */
-
- if (check(&array1[i][j],'"') == 1) errchk1 = 1-errchk1;
-
- /* Now check for curly brace. */
- /* 'Check' function determines if the */
- /* given character is within single quotes */
-
- if ((check(&array1[i][j],'{') == 1) &&
- (errchk1 == 0) && (errchk2 == 0)) count++;
- if ((check(&array1[i][j],'}') == 1) &&
- (errchk1 == 0) && (errchk2 == 0)) count--;
- if (count > maxbr) maxbr=count;
- }
- if (count != 0)
- printf("Counting error - comes to %d\n",count);
-
- printf("Maximum nesting goes %d levels deep\n",maxbr);
- printf("\n\nPlease note that in the following structuring\n");
- printf("some of your own program structure may be lost.\n");
- printf("This happens with the first tab setting. As things are\n");
- printf("added to the left of each line, the first tab setting\n");
- printf("is pushed along until it reaches the second. It will then\n");
- printf("push all the others on the same line along one tab setting.\n");
- printf("All this results in is a possibility of the first tab\n");
- printf("being shorter than usual. It should not hamper debugging\n");
- printf("because even if it is cut down to only one character,\n");
- printf("the program structuring will still be there.\n");
-
- errchk1 = 0; /* Now we mark the given nests of */
- errchk2 = 0; /* curly braces as they come. */
- count = 0;
- for (i=0;i<=nol;i++) {
- array3[i][maxbr+2] = 0;
- pos = 0;
- for (j=0;j<=CHARS_PER_LINE;j++) {
- if (array1[i][j] == 0) break;
-
- /* Once again, check for comments or quotes */
-
- if ((check(&array1[i][j],'/') == 1) &&
- check(&array1[i][j+1],'*') == 1) errchk2 = 1;
- if ((check(&array1[i][j],'*') == 1) &&
- check(&array1[i][j+1],'/') == 1) errchk2 = 0;
- if (check(&array1[i][j],'"') == 1) errchk1 = 1-errchk1;
-
- /* Now we actually mark them */
-
- if ((check(&array1[i][j],'}') == 1) &&
- (errchk1 == 0) && (errchk2 == 0)) {
- pos++;array2[i][pos] = count;
- count--;}
- if ((check(&array1[i][j],'{') == 1) &&
- (errchk1 == 0) && (errchk2 == 0)) {
- count++;pos++;
- array2[i][pos] = count;}
- }
- }
-
- for (i=1;i<=maxbr;i++) {
- l = 0;
- while (l <= nol) {
-
- /* This finds the first curly brace */
-
- for (j=0;j<=nol;j++) {
- for (k=0;k<=maxbr+2;k++)
- if (array2[j][k] == i) {
- array2[j][k] = 0;break;}
- if (k <= maxbr+2) break;
- }
- array3[j][i] = '+';
-
- /* This finds the matching curly brace */
-
- for (l=j;l<=nol;l++) {
- for (m=0;m<=maxbr+2;m++)
- if (array2[l][m] != i) {
- if (array3[l][i] != '+')
- array3[l][i] = '!';
- } else {
- array3[l][i] = '+';
- array2[l][m] = 0;
- break;}
- if (m <= maxbr+2) break;
- }
- }
- }
-
- /* And then, all we have to do */
- /* is save the whole lot again */
-
- fcreat(str2,obuf);
- for (i=0;i<=nol;i++) {
- strcpy(linbuf,&array3[i][0]);
- strcpy(&linbuf[maxbr+2],&array1[i][0]);
- fputs(linbuf,obuf);
- }
- putc(CPMEOF,obuf);
- fclose(obuf);
-
- exit();
- }
- check(c,d)
- char *c; /* This routine checks for the character */
- int d; /* in 'd' and makes sure it is not */
- { /* surrounded by single quotes */
- int i;
-
- i=0;
- if ((*(c-1) != 39) && (*(c+1) != 39) && (*c == d)) i = 1;
-
- return(i);
- }