⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tasm2msg.c

📁 EXAMPLE SOURCE CODE FOR TASM FILTER his filter accepts input through the standard input stream, con
💻 C
📖 第 1 页 / 共 2 页
字号:
      if (NewFile)


      {


         Type = MsgNewFile;               /* send new file indicated */


         Put(&Type,1);                    /* Put info to output stream */


         Put(CurFile,strlen(CurFile)+1);  /* along with the new name */


      }


      Type = MsgNewLine;                  /* set type to new line */


      Put(&Type,1);                       /* indicate need for new line */


      Put((char *)&i,2);                  /* put the number out */


      i = 1;                              /* set column in message box */


      Put((char *)&i,2);                  /* tab over to put message */


      Put(Line,strlen(Line)+1);           /* output the message */



   }


   else return 0;                         /* no ( on line, not MASM line */





   return 1;                              /* MASM line */


}





/*************************************************************************


Function  : ProcessTasmLine


Parameters: Line  a pointer to the current line of characters to process


Returns   : 1 if line is a Turbo Assembler line


            0 if line is not





Process through a line of input to determine if it is a Turbo Assembler


output line and convert it to information for the Turbo C++ message window.





Turbo Assembler lines which are in need of conversion are of the form:





    message-type source-file(LINE #) message-text





where type is one of: *Warning*, **Error**, **Fatal**





TASM lines are identified by the first portion of text.  If warning,


error or fatal is determined at the outset, text is output from there


as it is scanned.  Any incorrect configuration will simply abort the


scanning of the rest of the line.


*************************************************************************/


int ProcessTasmLine(char *Line)


{


   static int HavePutFile = FALSE;


   char     Type;


   unsigned i;


   char     *s;


   char     fn[MAXPATH];





   /* don't try to process a NULL line */


   if (Line[0] == 0)


      return 0;





   /* check for tasm type tags */


   if ((strncmp(Line,TasmWarningTxt,strlen(TasmWarningTxt)) == 0) ||


      (strncmp(Line,TasmErrorTxt,  strlen(TasmErrorTxt)) == 0) ||


      (strncmp(Line,TasmFatalTxt,  strlen(TasmFatalTxt)) == 0))





   {


      /* skip over type by moving string left */


      memmove(Line,&Line[strlen(TasmFatalTxt)],strlen(Line));





      /* locate the first open paren '(' filename will be characters to


	 to the left, line number will be characters to the right up to the


	 close paren ')' */


      s = strchr(Line,'(');                      /* find ( */


      if (s != NULL)                             /* if no (, invalid line */


      {


	 memmove(fn,Line,(unsigned)(s-Line));    /* save filename */


	 fn[(unsigned)(s-Line)] = 0;             /* null terminate name */


	 memmove(Line,++s,strlen(Line));         /* shift line left */


	 if (strcmp(fn,CurFile) != 0)            /* if new filename */


	 {


            Type = MsgNewFile;                   /* indicate by sending type


						    out to message window */


	    strcpy(CurFile,fn);


	    Put(&Type,1);


            Put(CurFile,strlen(CurFile)+1);      /* along with the new name */


	    HavePutFile = TRUE;


	 }


	 Type = MsgNewLine;                      /* set type to new line */


	 s = strchr(Line,')');                   /* find the close paren */


	 if (s != NULL)


	 {


            *s = 0;                              /* isolate number in string */


            i = atoi(Line);                      /* if number is found convert


						    string to integer */


	    if (i != 0)


	    {


	       Put(&Type,1);                       /* indicate need for new line */


	       Put((char *)&i,2);                  /* put the number out */


	       i = 1;                              /* set column in message box */


	       Put((char *)&i,2);                  /* tab over to put message */


	       s++;


	       memmove(Line,s,strlen(s)+1);        /* shift line */


	       while (Line[0] == ' ' && Line[0] != 0)  /* strip spaces from line */


		  memmove(Line,&Line[1],strlen(Line));


	       Put(Line,strlen(Line)+1);           /* output the message */


               return 1;              /* TASM line */


	    }


            return 0;                 /* invalid line number, not TASM line */


	 }


         return 0;                    /* no ) in line, not TASM line */


      }


      else                            /* Fatal error, no line # or filename */


      {


        if( !HavePutFile )


        {


	   /* IDE expects the first message to


	      be preceded by a filename.  Since


	      we don't have one, fake it by


	      sending a NULL file before the


	      message.


	   */


	   Type = MsgNewFile;                  /* indicate by sending type


					          out to message window */


	   *CurFile = '\0';


	   Put(&Type,1);


	   Put(CurFile,1);                     /* along with null filename */


           HavePutFile = TRUE;


        }


                       


	Type = MsgNewLine;            /* Fake line # etc.                   */


	i    = 1;


	Put(&Type,1);


	Put((char *)&i,2);


	Put((char *)&i,2);


	while (Line[0] == ' ' && Line[0] != 0)


	  memmove(Line,&Line[1],strlen(Line));


	Put(Line,strlen(Line)+1);


	return 1;


      }


   }


   else return 0;                     /* no line start message, not TASM line */


}





/**************************************************************************


Function  : ProcessLine


Parameters: Line    character pointer to line of input data


Returns   : nothing





If line type has been determined, call correct line processor through


a function pointer.  Else try testing for both Tasm style line and Masm


style line to determine if either one is the input to the filter.


**************************************************************************/


void ProcessLine(char *Line)


{


    if (processor == NULL)


    {


       if (ProcessTasmLine(Line))            /* check for TASM line */


          processor = ProcessTasmLine;


       else


          if (ProcessNonTasmLine(Line))      /* check MASM or OPTASM style */


             processor = ProcessNonTasmLine;


    }


    else


       processor(Line);                      /* type already determined */


}








/***********************************************************************


Function  : main





Returns   : zero for successful execution


            3    if an error is encountered





The main routine allocates buffers for the input and output buffer.


Characters are then read from the input buffer building the line buffer


that will be sent to the filter processor.  Lines are read and filtered


until the end of input is reached.


***********************************************************************/


int main( void )


{


   char c;


   unsigned long core;





   setmode(1,O_BINARY);               /* set output stream to binary mode */


   core = farcoreleft();


   if (core > 64000U)


      BufSize = 64000U;


   else BufSize = (unsigned)core;     /* get available memory */


                                      /* stay under 64K */


   if ((CurInPtr = malloc(BufSize)) == NULL) /* allocate buffer space */


      exit(3);


   processor = NULL;                  /* set current processor to none */


   InBuffer = CurInPtr;               /* input buffer is first half of space */


   BufSize = BufSize/2;               /* output buffer is 2nd half */


   OutBuffer = InBuffer + BufSize;


   CurOutPtr = OutBuffer;             /* set buffer pointers */


   LinePtr = Line;


   CurBufLen = 0;


   Put(PipeId,PipeIdLen);             /* send ID string to message window */


   while ((c = NextChar()) != 0)      /* read characters */


   {


      if ((c == 13) || (c == 10))     /* build until line end */


      {


         *LinePtr = 0;


         ProcessLine(Line);           /* filter the line */


         LinePtr = Line;


      }


      /* characters are added to buffer up to 132 characters max */


      else if ((FP_OFF(LinePtr) - FP_OFF(&Line)) < 132)


      {


         *LinePtr = c;                /* add to line buffer */


         LinePtr++;


      }


   }


   *LinePtr = 0;


   ProcessLine(Line);                 /* filter last line */


   EndMark = MsgEoFile;


   Put(&EndMark,1);                   /* indicate end of input to


                                         the message window */


   flushOut((unsigned)(CurOutPtr-OutBuffer));     /* flush the buffer */


   return 0;                          /* return OK */


}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -