Esempio n. 1
0
void madef(){
        int fd, i, j;
        char *buf_str=malloc(buf_size);
        (void)umask(0);
        if((fd = open(OUTFILE , O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0){
                printf("Can't open file out.txt!\n");
                exit(-1);
        }
        // write in file matrix
        for(i=0; i < mat_size; i++){
                for(j=0; j < mat_size; j++){
                        genstr(buf_str, mat[i*mat_size+j]);
                        if( (write(fd, buf_str, buf_size)) != buf_size){
                                printf("Can't write in file!\n");
                                exit(-1);
                        }
                        if(j != (mat_size-1)){
                                if((write(fd, " ", 1)) < 0){
                                        printf("Can'r write spase!\n");
                                        exit(-1);
                                }
                        }
                }
                if(write(fd, "\n", 1)<0){
                        printf("Can't write in file!\n");
                        exit(-1);
                }
        }
        if(close(fd) < 0){
                printf("Can't close file\n");
                exit(-1);
        }
        free(buf_str);
}
Esempio n. 2
0
void madef(int n, int bs){

        int fd;
        int i,j;
        char *s;


        s=(char*)malloc(bs*sizeof(char));

        (void)umask(0);

        if((fd=open("out.txt",O_WRONLY | O_CREAT | O_TRUNC, 0666))<0){
                printf("Can't open file!\n");
                exit(-1);
        }


        // write in file matrix
        for(i=0;i<n;i++){
                for(j=0;j<n;j++){
                        genstr(bs,s,a[i*n+j]);
                        if((write(fd,s,bs))<0){
                                printf("Can't write a symbol!\n");
                                exit(-1);
                        }
                        if(j!=(n-1)){
                                if((write(fd," ",1))<0){
                                        printf("Can'r write spase!\n");
                                        exit(-1);
                                }
                        }
                }
                if(write(fd,"\n",1)<0){
                        printf("Can't write in file!\n");
                        exit(-1);
                }
        }

        if(close(fd)<0){
                printf("Can't close file\n");
                exit(-1);
        }

        free(s);
}
Esempio n. 3
0
void madef(int n,int *a,char *s2){

        int fd;
        int i,j;
        char *s;
        int bs;

        bs=gbs();

        s=(char*)malloc(bs*sizeof(char));

        (void)umask(0);

        if((fd=open("matrix.txt",O_WRONLY | O_CREAT | O_TRUNC, 0666))<0){
                printf("Can't open file!\n");
                exit(-1);
        }


        // write in file bs

        genstr(bs,s,bs);
        if((write(fd,s,bs))<0){
                printf("Can't write a symbol!\n");
                exit(-1);
        }

        if((write(fd," ",1))<0){
                printf("Can't write  spase!\n");
                exit(-1);
        }

        // write size of matrix
        if((write(fd,s2,strlen(s2)))<0){
                printf("Can't write n!\n");
                exit(-1);
        }

        if((write(fd,"\n",1))<0){
                printf("Can't write  enter!\n");
                exit(-1);
        }


        // write in file matrix
        for(i=0;i<n;i++){
                for(j=0;j<n;j++){
                        genstr(bs,s,a[i*n+j]);
                        if((write(fd,s,bs))<0){
                                printf("Can't write element of matrix!\n");
                                exit(-1);
                        }
                        if(j!=(n-1))
                                if((write(fd," ",1))<0){
                                        printf("Can't write element of matrix!\n ");
                                        exit(-1);
                                }
                }
                if(write(fd,"\n",1)<0){
                        printf("Can't write in file!\n");
                        exit(-1);
                }
        }

        free(s);

        if(close(fd)<0){
                printf("Can't close file\n");
                exit(-1);
        }


}
Esempio n. 4
0
File: main.c Progetto: kalopa/dbow
/*
 * Generate prototype statements (C structures, etc).
 */
void
doproto(char *fname, int lineno)
{
	int sf, uf, df;
	static int protodone = 0;
	struct table *tp;
	struct column *cp, *sfc, *ufc, *dfc;

	/*
	 * Make sure we only execute once...
	 */
	if (protodone)
		return;
	protodone = 1;
	/*
	 * Do any table optimizations here...
	 */
	genprolog(fname, fofp);
	if (hofp != fofp)
		genprolog(fname, hofp);
	for (tp = getnexttable(NULL); tp != NULL; tp = getnexttable(tp)) {
		/*
		 * We always need an insert function.
		 */
		if (tp->ifname == NULL)
			genfuncname(tp, NULL, NULL, DBOW_INSERT);
		/*
		 * Make sure there is at least one search, delete and
		 * update function for each table.  -2 means we haven't
		 * seen anything yet.  -1 means there is a function
		 * definition already, and 0 or better is the column
		 * name for the first primary key.
		 */
		sf = uf = df = 0;
		sfc = ufc = dfc = NULL;
		for (cp = tp->chead; cp != NULL; cp = cp->next) {
			if (sf == 0) {
				if (cp->sfname != NULL) {
					sf = 1;
					sfc = NULL;
				} else if (sfc == NULL && cp->flags & FLAG_PRIKEY)
					sfc = cp;
			}
			if (uf == 0) {
				if (cp->ufname != NULL) {
					uf = 1;
					ufc = NULL;
				} else if (ufc == NULL && cp->flags & FLAG_PRIKEY)
					ufc = cp;
			}
			if (df == 0) {
				if (cp->dfname != NULL) {
					df = 1;
					ufc = NULL;
				} else if (dfc == NULL && cp->flags & FLAG_PRIKEY)
					dfc = cp;
			}
		}
		/*
		 * Build each default function (where needed).
		 */
		if (sfc != NULL)
			genfuncname(tp, sfc->name, NULL, DBOW_SEARCH);
		if (ufc != NULL)
			genfuncname(tp, ufc->name, NULL, DBOW_UPDATE);
		if (dfc != NULL)
			genfuncname(tp, dfc->name, NULL, DBOW_DELETE);
		/*
		 * Now emit the actual M4 definitions for each table...
		 */
		gendefs(tp, fofile, fofp);
		if (fofp != hofp)
			gendefs(tp, hofile, hofp);
	}
	/*
	 * Generate the middle section, including the "m4 include"...
	 */
	genmidsect(fname, fofp);
	if (hofp != fofp)
		genmidsect(fname, hofp);
	/*
	 * Now call the code-specific prototype generator for each table.
	 */
	if (lineno > 0)
		linesync(fname, lineno, hofp);
	tp = getnexttable(NULL);
	while (tp != NULL) {
		genstr(tp, hofp);
		tp = getnexttable(tp);
	}
}