home *** CD-ROM | disk | FTP | other *** search
- /*==========================================================================
-
- c k B a s N u m
- ---------------
-
- Sometimes one gets stuck with HAVING to write in (shudder)
- BASIC. The BASIC editor is awful so you use your favourite
- text editor, maybe on a different computer. You load your
- program under the interpreter and the code you carefully
- tested two days ago and which hasn't been touched since no
- longer works.
-
- One possibility is that some new code you have written has
- erroneous line numbers and is loaded in the wrong spot (as
- far as you are concerned).
-
- Far-fetched? Well that is what happened to me. It was too
- painful to do a visual check so I wrote this quickie.
-
- This program checks a Microsoft (or similar) BASIC source
- program to ensure that the line numbers are monotonically
- increasing. Any sequence error is reported.
-
- Writing these notes and tidying up the source code took
- longer than writing the program in the first place. (I'm not
- kidding!).
-
- Originally compiled for Z80 CP/M with Hi-Tech C 3.02 but should
- compile with just about any standard C compiler for CP/M, MS-DOS
- or UNIX without modification to the source.
-
- Jon Saxton - 7th May 1987.
-
- ==========================================================================*/
-
- #include <stdio.h>
- #include <ctype.h>
-
- FILE *basic;
- short int c;
- char lineBuf[256];
-
-
-
-
- /*******
- Sample atol() function in case your C library doesn't have one -
- Converts sequence of decimal digits to a long int. This ultra
- simple version doesn't handle negative numbers (and doesn't need to).
-
- long int atol(cp)
- char *cp;
- {
- long int v = 0L;
-
- while (isdigit(*cp))
- v = v * 10L + *cp++ - '0';
-
- return v;
- }
- *******/
-
-
-
- main(argc,argv)
- short int argc;
- char *argv[];
- {
- long int previous, lineNo;
- short int seqErr = 0;
-
- extern long atol();
-
- previous = -1L;
- if (argc < 2 || (basic = fopen(argv[1],"r")) == NULL)
- {
- fprintf(stderr,"Input file not specified or not found\n");
- exit(-4);
- }
-
- while (fgets(lineBuf, 250, basic) != NULL)
- if (isdigit(lineBuf[0]))
- {
- lineNo = atol(lineBuf);
- if (lineNo <= previous)
- {
- seqErr = -4; /* Error value for CP/M+, MS-DOS, UNIX */
- printf("Sequence error: %ld -> %ld\n", previous, lineNo);
- }
- previous = lineNo;
- }
-
- fclose(basic);
- exit(seqErr);
- }