home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Module: cmerge.c - Merge Alcyon C source and .s files */
- /* */
- /* Programmer: George R. Woodside */
- /* */
- /* Date: January 18, 1987 */
- /* */
- /* argv[1] must be the name of the .c file, and */
- /* argv[2] must be the name of the .s file. */
- /* Output is to stdout. */
- /* */
- /****************************************************************************/
-
- #include <stdio.h>
- #include <ctype.h>
- #include <osbind.h>
-
- int clno = 0; /* current line in .c file */
- int slno = 0; /* current line in .s file */
- int seek = 0; /* .c file line to seek */
-
- FILE *fp_c; /* .c file pointer */
- FILE *fp_s; /* .s file pointer */
-
- char cline[256]; /* text line from .c file */
- char sline[256]; /* text line from .s file */
- char junk[128]; /* throw away buffer for sscanf */
-
- char *flag = "*line "; /* line number reference */
- int flen; /* length to compare */
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- register int s_stat = 1; /* .s file line read status */
- register int c_stat = 1; /* .c file line read status */
-
- flen = strlen(flag); /* length to compare */
-
- if( (fp_c = fopen(argv[1],"r") ) == NULL) /* if unable to open .c file, */
- {
- printf("cmerge: Unable to open %s\n",argv[1]);
- exit(1); /* punt */
- }
-
- if( (fp_s = fopen(argv[2],"r") ) == NULL) /* if unable to open .s file, */
- {
- printf("cmerge: Unable to open %s\n",argv[2]);
- exit(1); /* punt */
- }
-
- /**************************************************************************/
- /* */
- /* Determine the first line number reference in the .s file */
- /* */
- /**************************************************************************/
-
- while(s_stat == 1) /* while non-line number line, */
- s_stat = getsline(); /* read another */
-
- if(s_stat == 0) /* if end of file, */
- {
- printf("cmerge: No line numbers in .s file\n"); /* flag error */
- exit(1); /* and punt */
- }
-
- sscanf(sline,"%s %d",&junk,&seek); /* get line number to seek */
-
- fclose(fp_s); /* close the .s file */
-
- if( (fp_s = fopen(argv[2],"r") ) == NULL) /* re-open .s file */
- {
- printf("cmerge: Unable to re-open %s\n",argv[2]);
- exit(1); /* punt */
- }
-
- while(s_stat || c_stat) /* while either file left open */
- {
- if( (clno < seek) || (s_stat == 0) ) /* if we need the .c file */
- {
- c_stat = getcline(); /* read a line */
-
- if(c_stat) /* if not end of file, */
- printf("%s",cline); /* print it */
- } /* end need .c line */
- else
- {
- s_stat = getsline(); /* read a line */
- if(s_stat == 1) /* if a text line, */
- printf("......%s",sline); /* print it */
- if(s_stat == 2) /* if a line number line, */
- sscanf(sline,"%s %d",&junk,&seek); /* get line to seek */
- } /* end need .s line */
- } /* end either file open */
- } /* end main */
-
- /****************************************************************************/
- /* */
- /* Read a line from the .s file. */
- /* Return 0 if end of file. */
- /* Return 1 if data line. */
- /* Return 2 if a line number line. */
- /* */
- /****************************************************************************/
-
- getsline()
- {
- register char *ptr;
-
- ptr = fgets(sline,255,fp_s); /* read a line */
-
- if( ptr == NULL ) /* if end of file, */
- return(0); /* say so */
-
- if(strncmp(flag,sline,flen) == 0) /* if a line number flag */
- return(2); /* indicate a number found */
- else /* otherwise, */
- return(1); /* regular data line */
- }
-
- /****************************************************************************/
- /* */
- /* Read a line from the .c file. */
- /* Update clno. */
- /* Return 0 if end of file. */
- /* */
- /****************************************************************************/
-
- getcline()
- {
- register char *ptr;
-
- ptr = fgets(cline,255,fp_c); /* read a line */
-
- clno++; /* count it */
-
- if( ptr == NULL ) /* if end of file, */
- return(0); /* say so */
- else /* otherwise, */
- return(1); /* regular data line */
- }
-
- /****************************************************************************/
- /* Kludge to cure alcyon library flaw */
- /****************************************************************************/
- never()
- {
- register char *crud;
- register int i;
-
- i = atoi(crud); /* someday they may fix this */
- }
-