home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / beehive / program / ckbasnum.arc / CBN.C next >
Encoding:
C/C++ Source or Header  |  1990-07-22  |  2.5 KB  |  96 lines

  1. /*==========================================================================
  2.  
  3.                   c k B a s N u m
  4.                   ---------------
  5.  
  6.     Sometimes one gets stuck with HAVING to write in (shudder)
  7.     BASIC.  The BASIC editor is awful so you use your favourite
  8.     text editor, maybe on a different computer.  You load your
  9.     program under the interpreter and the code you carefully
  10.     tested two days ago and which hasn't been touched since no
  11.     longer works.
  12.  
  13.     One possibility is that some new code you have written has
  14.     erroneous line numbers and is loaded in the wrong spot (as
  15.     far as you are concerned).
  16.  
  17.     Far-fetched?  Well that is what happened to me.  It was too
  18.     painful to do a visual check so I wrote this quickie.
  19.  
  20.     This program checks a Microsoft (or similar) BASIC source
  21.     program to ensure that the line numbers are monotonically
  22.     increasing.  Any sequence error is reported.
  23.  
  24.     Writing these notes and tidying up the source code took
  25.     longer than writing the program in the first place.  (I'm not
  26.     kidding!).
  27.  
  28.     Originally compiled for Z80 CP/M with Hi-Tech C 3.02 but should
  29.     compile with just about any standard C compiler for CP/M, MS-DOS
  30.     or UNIX without modification to the source.
  31.  
  32.     Jon Saxton - 7th May 1987.
  33.  
  34. ==========================================================================*/
  35.  
  36. #include <stdio.h>
  37. #include <ctype.h>
  38.  
  39. FILE *basic;
  40. short int c;
  41. char lineBuf[256];
  42.  
  43.  
  44.  
  45.  
  46. /*******
  47.    Sample atol() function in case your C library doesn't have one -
  48.    Converts sequence of decimal digits to a long int.  This ultra
  49.    simple version doesn't handle negative numbers (and doesn't need to).
  50.  
  51. long int atol(cp)
  52. char *cp;
  53. {
  54.     long int v = 0L;
  55.  
  56.     while (isdigit(*cp))
  57.        v = v * 10L + *cp++ - '0';
  58.  
  59.     return v;
  60. }
  61. *******/
  62.  
  63.  
  64.  
  65. main(argc,argv)
  66. short int argc;
  67. char *argv[];
  68. {
  69.     long int previous, lineNo;
  70.     short int seqErr = 0;
  71.  
  72.     extern long atol();
  73.  
  74.     previous = -1L;
  75.     if (argc < 2 || (basic = fopen(argv[1],"r")) == NULL)
  76.     {
  77.         fprintf(stderr,"Input file not specified or not found\n");
  78.         exit(-4);
  79.     }
  80.  
  81.     while (fgets(lineBuf, 250, basic) != NULL)
  82.         if (isdigit(lineBuf[0]))
  83.         {
  84.             lineNo = atol(lineBuf);
  85.             if (lineNo <= previous)
  86.             {
  87.                 seqErr = -4;    /* Error value for CP/M+, MS-DOS, UNIX */
  88.             printf("Sequence error: %ld -> %ld\n", previous, lineNo);
  89.             }
  90.             previous = lineNo;
  91.         }
  92.  
  93.     fclose(basic);
  94.     exit(seqErr);
  95. }
  96.