home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ME22-OS2.ZIP / MACROS.ZIP / MSCCOMP.M < prev    next >
Text File  |  1989-03-02  |  3KB  |  91 lines

  1. /**********************************************************************/
  2. /* MSCCOMP - this file contains macros for automating the compile and */
  3. /*  error-search procedures under Microsoft 4.0. To compile the       */
  4. /*  current buffer, press ALT C. To search for errors, press CTRL N.  */
  5. /*                                                                    */
  6. /* Written by Marc Adler of MAGMA SYSTEMS.  January 1987              */
  7. /**********************************************************************/
  8.  
  9. #define ALT_C   174
  10. #define CTRL_N  14
  11.  
  12. #define NO      0
  13. #define YES     1
  14.  
  15. int reached_eof;
  16.  
  17. init()
  18. {
  19.   assign_key("compile",    ALT_C);
  20.   assign_key("next_error", CTRL_N);
  21. }
  22.  
  23. compile()
  24. {
  25.   string currfile, extension;
  26.   string errmsg;
  27.   int    i;
  28.  
  29.   errmsg = "Error - the file is not a C file. <Hit ENTER to continue>";
  30.   
  31.   currfile = filename();
  32.  
  33.   /* Make sure that the current buffer is a C file */
  34.   if ((i = index(currfile, ".")) > 0)           /* get the extension */
  35.   {
  36.     extension = substr(currfile, i+1, 3);
  37.     if (extension != "c" && extension != "C")   /* is it a C file?   */
  38.     {
  39.       get_tty_str(errmsg);                      /* NO!!! Error!!!    */
  40.       return;
  41.     }
  42.   }
  43.   else              /* the buffer has no extension, so it's an error */
  44.   {
  45.     get_tty_str(errmsg);
  46.     return;
  47.   }
  48.  
  49.   writefile(currfile);      /* save the current version & compile it */
  50.   set_buffer_modified(currbuf(), 0);
  51.   os_command(sprintf("cl /C /AL /Zi /J %s > errs", currfile));
  52.   next_error();             /* see if there are errors               */
  53. }
  54.  
  55. next_error()
  56. {
  57.   int id, old_id;
  58.   int n;
  59.   string cl, foo;
  60.  
  61.   old_id = currbuf();           /* save the id of the source buffer */
  62.  
  63.   if ((id = find_buffer("errs")) == 0)
  64.   {
  65.     id = create_buffer("errs");
  66.     reached_eof = NO;
  67.   }
  68.   id = setcurrbuf(id);
  69.  
  70.   /* Microsoft C Ver.4.0 puts out error messages in this format : */
  71.   /*      filename(line #) : messagetype error# message           */
  72.   if (reached_eof == NO && fsearch("([0-9][0-9]*) \\: ?*error") > 0)
  73.   {
  74.     n = atoi(substr(cl = currline(), currcol()+1, 5));  /* get line # */
  75.     gobol();                    /* move to the next error */
  76.     if (!down())
  77.       reached_eof = YES;
  78.     show_buffer(old_id);        /* go to the source buffer and */
  79.     goline(n);                  /*  move to the offending line */
  80.     message(cl);                /* display the error message   */
  81.     get_tty_char();             /* and let the user acknowledge*/
  82.   }
  83.  
  84.   else          /* Reached the end of the error file */
  85.   {
  86.     foo = get_tty_str("NO MORE ERRORS");
  87.     delete_buffer(id);          /* get rid of the error buffer */
  88.     show_buffer(old_id);        /* and set the current buffer  */
  89.   }
  90. }
  91.