www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/20/00:32:28

From: P DOT Koshevoy AT m DOT cc DOT utah DOT edu (Paul Koshevoy)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Virtual memory exceeded in `new' - leave2.cpp (0/1)
Date: Thu, 19 Sep 1996 06:20:27 GMT
Organization: University of Utah
Lines: 460
Message-ID: <51s33m$8ei@news.cc.utah.edu>
References: <51s2qo$8ei AT news DOT cc DOT utah DOT edu>
NNTP-Posting-Host: ctsasync55.cc.utah.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Here is the source code:
#include <bios.h>
#include <stdlib.h>
#include <fstream.h>
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include "question.h"
#include <stdio.h>

extern char * my_pick4(char *, char *, char *);
extern char * get_part(char *, int, int);
extern int my_strncmp(char *, char *, int, int);
extern void report_error(char *);
extern char * get_skeeps(char * sample,char * sample2, int &n);
extern char * get_sample(char ** content, int num);
extern char * get_sample2(char ** content, int num);
extern void show_sample(char * sample, int pos, int len);
extern void move_cur_to(int x,int top);
extern void move_cur_from(int x);

ofstream debug("debug.txt",ios::out);

int
check(char ** content, int num, char * buff)
{
    for(int i=0; i<num;i++)
        if(strcmp(content[i],buff)==0)
	    return 0;
    return 1;
}
    
char *
get_simple(char * buff, char * skeep, int snum)
{

debug<<"in get_simple()\n";

    int len=strlen(buff);
    char * temp=new char[len+1];
    if(snum==0 || skeep==NULL)
	{
	    strcpy(temp,buff);
	    return temp;
	}
 
    int prev=0;
    temp[0]='\0';
    char * t;

    for(int i=0; i<snum;i++)
	{
	    t=get_part(buff,prev,int(skeep[i*2])-prev);
	    if(t!=NULL)
		{
		    strcat(temp,t);
		    delete [] t;
		}
	    prev=(int(skeep[i*2])+int(skeep[i*2+1]));
	}
    t=get_part(buff,prev,1024);
    strcat(temp,t);
    delete [] t;
    return temp;
}

int
check2(char ** content, int num, char * buff, char * skeep, int snum)
{
    char * buff_2=get_simple(buff,skeep,snum);
    for(int i=0 ;i<num ;i++ )
	{
	    char * temp=get_simple(content[i],skeep,snum);
	    if(strcmp(temp,buff_2)==0)
		{
		    delete [] temp;
		    delete [] buff_2;
		    return 0;
		}
	    delete [] temp;
	}
    delete [] buff_2;
    return 1;
}


int
main()
{
    char * filename;
    filename=my_pick4(filename,"*.*","select first file");
    if(filename==NULL)
	{
	    report_error("Error selecting first file");
	    exit(-100);
	}

    char * filename1;
    filename1=my_pick4(filename1,"*.*","select second file");
    if(filename1==NULL)
	{
	    report_error("Error selecting second file");
	    exit(-100);
	}

    ifstream file(filename,ios::in);
    ofstream file3;

    if(!file)
	{
	    report_error("Could not open first input file");
	    exit(-1);
	}

    ifstream file2(filename1,ios::in);
    if(!file2)
	{
	    report_error("Could not open second input file");
	    exit(-1);
	}
    char filename3[256];
    Question box(15,5,5,51,"Please enter report file filename",1);

    while(true)
    {
    box.refresh();
    gotoxy(17,7);
    textcolor(11);
    textbackground(1);
    gets(filename3);
    box.kill();
    file3.open(filename3,ios::out);
    if(!file3)
	{
	    report_error("Could not open output file");
	    continue;
	}
    break;
    }

    char * content[9999];
    char buff[1024];
    int num=0;

    while(!file.eof())
    {
	file.getline(buff,1024,'\n');
	if(check(content,num,buff))
	    {
		content[num]=new char[strlen(buff)+1];
		strcpy(content[num++],buff);
	    }
    }
    file.close();
    int n;
    int nn=0;
    char * skip=get_skeeps(get_sample(content,num)
,get_sample2(content,num),n);

//this is where trouble starts

//    char * skeep;
    char skeep[999];
    if(n!=0)
	{
//	    skeep=new char[n+1];
	    int ln=strlen(skip);
	    for(int i=0;i<ln;i++)
		{
		    if(skip[i]=='x')
			{
			    skeep[nn++]=i;
			    debug<<int(skeep[nn-1]);
			}
		}
	    skeep[n]='\0';
	}
//    else
//	skeep=NULL;

    delete [] skip;

    while(!file2.eof())
	{
	    file2.getline(buff,1024,'\n');
	    if(check2(content,num,buff,skeep,nn))
		file3<<buff<<endl;
	}
    file2.close();
    file3.close();

    for (int i=0;i<num;i++)
	delete [] content[i];

    if(skeep!=NULL)
	delete [] skeep;

    return 1;
}

void
report_error(char * message)
{
    Question box(21,5,7,40,"Error",4);
    box.refresh();
    gotoxy(23,8);
    textcolor(15);
    textbackground(4);
    cputs(message);
    getch();
    box.kill();
}

char *
get_sample(char ** content, int num)
{
    int len=strlen(content[num/2]);
    char * temp=new char[len+1];
    for(int i=0;i<len;i++)
	if(content[num/2][i]!=' ')
	    temp[i]='-';
	else
	    temp[i]=' ';
    temp[len]='\0';
    return temp;
}

char *
get_sample2(char ** content, int num)
{
    return content[num/2];
}

void
show_sample(char * sample, char * sample2, int pos, int len)
{
    textcolor(11);
    textbackground(0);
    gotoxy(5,13);
    int i=pos;
    int count=5;
    while(count<77 && i<len)
	{
	    gotoxy(count,14);
	    putch(sample[i]);
            gotoxy(count,16);
	    putch(sample2[i++]);
	    count++;
	}
}

char *
get_skeeps(char * sample, char * sample2, int &num)
{
    _setcursortype(_NOCURSOR);
    Question box(3,10,8,76,"Please mark the places to ignore",1);
    box.refresh();
    int len=strlen(sample);
    int top=0;
    show_sample(sample,sample2,top,len);
    int x=5;
    int key=0;

    int left=19200;
    int right=19712;
    int up=18432;
    int down=20480;
    int space=14624;
    int home=18176;
    int end=20224;
    int enter=7181;
    int minus=18989;
    int esc=283;

    int limit=76;
    int sel=0;

    if(len<72)
	limit=len+5;

    while(key!=enter)
	{
	    move_cur_to(x,top);
	    key=0;

	    textcolor(11);
	    gotoxy(75,11);
	    cputs("  ");
	    gotoxy(64,11);
	    cprintf("Selected: ");
	    cprintf("%i",sel);

	    while(true)
		{
		    if(_bios_keybrd(_KEYBRD_READY)!=0)
			key=_bios_keybrd(_KEYBRD_READ);
		    if(key==up || key==down || key==space || key==enter
			       || key==left || key==right || key==home
			       || key==end  || key==minus || key==esc)
			break;
		}

	    if(key==down)
		{
		    if(x!=limit)
			{
			    move_cur_from(x);
			    x=limit;
			    continue;
			}
		    else
			key=end;
		}

	    if(key==up)
		{
		    if(x!=5)
		        {
			    move_cur_from(x);
			    x=5;			
			    continue;	    
			}
		    else
			key=home;
		}

	    if(key==left)
		{
		    move_cur_from(x);
		    if(x-1>4)
			x--;
		    else
			if(top>0)
			    {
				top--;
				show_sample(sample,sample2,top,len);
			    }
		    continue;
		}

            if(key==right)
		{
		    move_cur_from(x);
		    if(x+1<77 && x+1<len-top+5)
			x++;
		    else
			if(top+1<len-72)
			    {
				top++;
				show_sample(sample,sample2,top,len);
			    }
		    continue;
		}

            if(key==home)
		{
		    move_cur_from(x);
		    x=5;
		    top=0;
		    show_sample(sample,sample2,top,len);           
		    continue;
		}

            if(key==end)
		{
		    move_cur_from(x);
		    x=76;
		    if(len<72)
			x=len+5;
		    top=len-72;
		    show_sample(sample,sample2,top,len);
		    continue;
		}
	    if(key==space)
		{
		    int p=x-5+top;
		    if(sample[p]=='x')
			{
			    if(sample2[p]!=' ')
				sample[p]='-';
			    else
				sample[p]=' ';
			    sel--;
			}
		    else
			{
			    sample[p]='x';
			    sel++;
			}
		    show_sample(sample,sample2,top,len);
		    continue;
		}

	    if(key==esc)
		{
		    key=minus;
		}

	    if(key==minus)
		{
		    for(int p=0;p<len;p++)
			if(sample[p]=='x')
			    {
				if(sample2[p]!=' ')
				    sample[p]='-';
				else
				    sample[p]=' ';
			    }
		    show_sample(sample,sample2,top,len);
		    sel=0;
		}
	}
    box.kill();
    num=sel;	
    delete [] sample2;
    return sample;
}

void
move_cur_to(int x,int top)
{

    char pos[2];
    gettext(x,14,x,14,pos);
    pos[1]=12;
    textcolor(11);
    textbackground(1);
    gotoxy(14,11);
    cputs("  ");
    gotoxy(5,11);
    cprintf("Column: ");
    cprintf("%i",x-4+top);
    textcolor(12);
    gotoxy(x,13);
    putch(char(220));
    gotoxy(x,15);
    putch(char(223));
    puttext(x,14,x,14,pos);
    gettext(x,16,x,16,pos);
    pos[1]=12;
    puttext(x,16,x,16,pos);
}

void
move_cur_from(int x)
{
    char pos[2];
    gettext(x,14,x,14,pos);
    pos[1]=11;
    textbackground(1);
    gotoxy(x,13);
    putch(' ');
    gotoxy(x,15);
    putch(' ');
    puttext(x,14,x,14,pos);
    gettext(x,16,x,16,pos);
    pos[1]=11;
    puttext(x,16,x,16,pos);
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019