Love this site? Hate it? Leave us some comments.
*/
*/

View ezasm\main.cpp

Ezasm for linux 1.0

Submitted By: acvivek
Rating: Not rated (Rate It)


#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include "s.h"
#include "lex.yy.c"
int sym_count=0;
long int loc_ctr=0;
int line_count=0;
int err_count=0;
int sev_err=0;
FILE * list_file;
FILE * obj_file;
FILE *fp,*f1,*f2,*f3;
char l_file[20],o_file[20],b_file[20];
int noline(char l[])
{
        int i;
        if(l[0]=='\t' || l[0]=='\n') return 1;
        for(i=0;i<strlen(l);i++)
        {
                if(l[i]==' ' || l[i]=='\t');
                else return 0;
        }
}
int main(int argc,char *argv[])
{       
        extern int beg;
        int dataseg=0;
        int codeseg=0;
        int list=0;
        char *lnam;
        char *onam;
        char *bnam;
        char *lst = ".lst",*obj = ".o",*bak=".bak";
        char line[30],c;
        char data[]=".data";
        char code[]=".code";
        char proc[]=".proc";
        int i=0,ds=0,cs=0,ps=0,comment=0,z,n,j,k;
        void data_parse(char []);
        char *parse(char []);
        void proc_parse(char []);
        void macro_parse();
        void expand(char []);
        if(argc<2) {printf("\nToo few arguments \n");exit(0);}
        else
        {
                if(strcmp(argv[1],"-l")==0) {list=1;n=2;}
                else n=1;
                for(z=n;z<argc;z++)
                {
                        ds=0;cs=0;dataseg=0;codeseg=0;i=0;
                        sym_count=0;loc_ctr=0;line_count=0;err_count=0;sev_err=0;
                        fp=fopen(argv[z],"r");
                        lnam=fil_ext(argv[z]);
                        onam=fil_ext(argv[z]);
                        bnam=fil_ext(argv[z]);
                        for(k=0;k<strlen(lnam);k++)
                        l_file[k]=*(lnam+k);
                        for(j=0;j<strlen(lst);j++)
                        l_file[k++]=*(lst+j);
                        l_file[k]='\0';  
                        for(k=0;k<strlen(onam);k++)
                        o_file[k]=*(onam+k);
                        for(j=0;j<strlen(obj);j++)
                        o_file[k++]=*(obj+j);
                        o_file[k]='\0'
                        for(k=0;k<strlen(bnam);k++)
                        b_file[k]=*(bnam+k);
                        for(j=0;j<strlen(bak);j++)
                        b_file[k++]=*(bak+j);
                        b_file[k]='\0';
                        f1=fopen(argv[z],"r");
                        if(f1==NULL) {printf("\nUnable to open \n");exit(0);}
                        f2=fopen("f","w");     
                        fclose(f2);
                        f2=fopen("f","a");
                        beg=0;
                        macro_parse();
                        fclose(f1);
                        fclose(f2);
                        f2=fopen("f","r");
                        f3=fopen(b_file,"w");
                        fclose(f3);
                        f3=fopen(b_file,"a");
                        beg=3;
                        expand(b_file);   
                        list_file=fopen(l_file,"w");           
                        obj_file=fopen(o_file,"w");               
                        fp=fopen(b_file,"r");
                        if(fp==NULL) {printf("Unable to open %s",argv[z]);exit(0);}
                        printf("\nFile Name : %s\n",argv[z]);
                        while(!feof(fp))
                        {                            
                                c=fgetc(fp);
                                if(c=='\n' )
                                {                                          
                                        line_count++;
                                        line[i]='\0';
                                        if(noline(line)) {i=0;continue;}               
                                        if(strcmp(line,data)==0) {ds=1;cs=0;ps=0;dataseg=1;}
                                        else if(strcmp(line,code)==0) {cs=1;ds=0;ps=0;codeseg=1;}       
                                        else if(strcmp(line,proc)==0) {ps=1;cs=0;ds=0;}
                                        else if(ds==1)
                                        data_parse(line);
                                        else if(cs==1) parse(line);
                                        else if(ps==1) proc_parse(line);                                       
                                        i=0;       
                                }
                                else if(c==';')
                                {              
                                        line[i]='\0';               
                                        line_count++;               
                                        if(strcmp(line,data)==0) {ds=1;cs=0;dataseg=1;}
                                        else if(strcmp(line,code)==0) {cs=1;ds=0;codeseg=1;}
                                        else if(strcmp(line,proc)==0) {ps=1;cs=0;ds=0;}
                                        else if(ds==1 && strlen(line)>0)
                                        data_parse(line);
                                        else if(cs==1 && strlen(line)>0) parse(line);
                                        else if(ps==1) proc_parse(line);               
                                        i=0;
                                        char b=fgetc(fp);
                                        while(b!='\n')
                                        b=fgetc(fp);               
                                }
                                else
                                        line[i++]=c;           
                        }
                        yyin=fopen("intr","r");
                        yyout=fopen("intr","r+");              
                        yylex();
                        fclose(yyin);
                        fclose(yyout);
                        if(dataseg!=1) {printf("\nSEVERE WARNING: unassembled data segment as no .data\n");sev_err++;}
                        if(codeseg!=1) {printf("\nSEVERE WARNING: unassembled code segment as no .code\n");sev_err++;}
                        printf("\n%d Severe Warning(s) \n",sev_err);
                        printf("\n%d Error(s) \n",err_count);
                        if(err_count!=0 )
                        {
                        system("rm -f intr");
                        system("rm -f *.o *.lst");     
                        }
                        else if(err_count==0)
                        {
                                FILE * fptr=fopen("intr","r");
                                if(fptr!=NULL)
                                binhex(fptr);
                                fclose(fptr);
                                system("rm -f intr");
                                if(list!=1) system("rm -f *.lst");
                                printf("\nAssembling succesfully Complete\n");
                        }
                        fclose(fp);
                        fclose(obj_file);
                        fclose(list_file);                 
                }
        }
fclose(f3);
system("rm -f f");
return 0;
}

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings