Example #1
0
int main() {
    cl_int err;
    cl_kernel kernel;
    cl_program program;
    cl_mem buffer;
    cl_ulong ans;
    int i;
    char *source;
    size_t localws[3];
    size_t globalws[3];

    initopencl();
    source=getsource("pe001.cl");
    /* create a program object and load source code into it */
    program=clCreateProgramWithSource(context,1,(const char **)&source,NULL,&err);
    if(CL_SUCCESS!=err) clerror("error creating program",err);
    /* builds a program associated with a program object */
    if(CL_SUCCESS!=(err=clBuildProgram(program,1,devices+DEVICEID,NULL,NULL,NULL)))
        clerror("error building program",err);
    /* create kernel object from built program */
    kernel=clCreateKernel(program,"pe001",&err);
    if(CL_SUCCESS!=err) clerror("error creating kernel",err);
    free(source);

    /* create memory buffer: one cl_ulong for each kernel, a total of MAX=N/KERNEL */
    buffer=clCreateBuffer(context,CL_MEM_READ_WRITE,MAX*sizeof(cl_ulong),NULL,&err);
    if(CL_SUCCESS!=err) clerror("error creating buffer",err);

    /* set up kernel arguments */
    if(CL_SUCCESS!=(err=clSetKernelArg(kernel,0,sizeof(cl_mem),&buffer))) clerror("error setting kernel argument 0",err);

    globalws[0]=MAX;
    localws[0]=LOCAL;

    /* run kernel */
    if(CL_SUCCESS!=(err=clEnqueueNDRangeKernel(queue,kernel,1,NULL,globalws,localws,0,NULL,NULL)))
        clerror("error running kernel",err);
    /* wait until kernel has finished */
    if(CL_SUCCESS!=(err=clFinish(queue))) clerror("error waiting for queue",err);

    /* copy to host memory */
    if(CL_SUCCESS!=(err=clEnqueueReadBuffer(queue,buffer,CL_TRUE,0,MAX*sizeof(cl_ulong),a,0,NULL,NULL)))
        clerror("error copying result to host",err);
    if(CL_SUCCESS!=(err=clFinish(queue))) clerror("error waiting for queue",err);

    /* assemble final answer */
    ans=0;
    for(i=0; i<ACTUAL/KERNEL; i++) ans+=a[i];
    printf("ans: "LL"\n",ans);

    /* TODO deallocate buffer */

    clReleaseKernel(kernel);
    clReleaseProgram(program);
    shutdownopencl();
    return 0;
}
int main()
{
 char source[MAX] ;//入力データ
 char target[MAX] ;//全角データ
 int numchar ;//入力文字数

 /*テキストを読み込む*/
 numchar=getsource(source) ;

 /*全角文字のみ取り出す*/
 getwidechar(target,source,numchar) ;

 /*3-gramの出力*/
 outputtarget(target) ;

 return 0 ;
}
Example #3
0
/**
*
* _edit(debug, loc):
*
* Invoke an editor.
*
**/
PUBLIC void _edit(DEBUG *debug, LOCATION loc)
{
    DISPLAY *display = debug->display;
    char *editor;
    char lineopt[20];
#ifndef BUG
    int  proc_id;
#endif
    (void)sprintf(lineopt, "-g%d", loc.line);
    if ((editor = getvar(debug->env.Envv, "EDITOR")) == NULL) editor = "emacs";
    /* ACE: The name stored with the source should be the full name, thus
            eliminating the need to fiddle the current directory.
    */

#ifdef OLDCODE
    chdir(debug->env.Objv[0]->Name);
#endif
    /*
    -- crf : 12/08/91 - clean up use of Environment Objv
    */
    chdir(debug->env.Objv[OV_Cdir]->Name);

    dstart(display);
    if ((proc_id = vfork()) == 0)
    {
        dup2(fileno(display->filein), 0);
        dup2(fileno(display->fileout), 1);
        dup2(fileno(display->fileout), 2);
        execlp(editor, editor, lineopt, getsource(loc.module)->name, NULL);
        perror(editor);
        _exit(1);
    }
#ifndef BUG
    {
        int t_state,terror;
        do
        {
            terror = wait(&t_state);
        }
        until((terror == proc_id) || (terror == -1));

    }
#endif
    dend(display, FALSE);

}
Example #4
0
static int
onematch(Match_t* mp, int g, char* s, char* p, char* e, char* r, int flags)
{
	register int 	pc;
	register int 	sc;
	register int	n;
	register int	icase;
	char*		olds;
	char*		oldp;

	icase = flags & STR_ICASE;
	do
	{
		olds = s;
		sc = getsource(s, e);
		if (icase && isupper(sc))
			sc = tolower(sc);
		oldp = p;
		switch (pc = mbgetchar(p))
		{
		case '(':
		case '*':
		case '?':
		case '+':
		case '@':
		case '!':
			if (pc == '(' || *p == '(')
			{
				char*	subp;
				int	oldg;

				s = olds;
				subp = p + (pc != '(');
				oldg = g;
				n = ++g;
				if (g < MAXGROUP && (!r || g > mp->current.groups))
					mp->current.beg[g] = mp->current.end[g] = 0;
				if (!(p = gobble(mp, subp, 0, &g, !r)))
					return 0;
				if (pc == '*' || pc == '?' || pc == '+' && oldp == r)
				{
					if (onematch(mp, g, s, p, e, NiL, flags))
						return 1;
					if (!sc || !getsource(s, e))
					{
						mp->current.groups = oldg;
						return 0;
					}
				}
				if (pc == '*' || pc == '+')
				{
					p = oldp;
					sc = n - 1;
				}
				else
					sc = g;
				pc = (pc != '!');
				do
				{
					if (grpmatch(mp, n, olds, subp, s, flags) == pc)
					{
						if (n < MAXGROUP)
						{
							if (!mp->current.beg[n] || mp->current.beg[n] > olds)
								mp->current.beg[n] = olds;
							if (s > mp->current.end[n])
								mp->current.end[n] = s;
						}
						if (onematch(mp, sc, s, p, e, oldp, flags))
						{
							if (p == oldp && n < MAXGROUP)
							{
								if (!mp->current.beg[n] || mp->current.beg[n] > olds)
									mp->current.beg[n] = olds;
								if (s > mp->current.end[n])
									mp->current.end[n] = s;
							}
							return 1;
						}
					}
				} while (s < e && mbgetchar(s));
				mp->current.groups = oldg;
				return 0;
			}
			else if (pc == '*')
			{
				/*
				 * several stars are the same as one
				 */

				while (*p == '*' && *(p + 1) != '(')
					p++;
				oldp = p;
				switch (pc = mbgetchar(p))
				{
				case '@':
				case '!':
				case '+':
					n = *p == '(';
					break;
				case '(':
				case '[':
				case '?':
				case '*':
					n = 1;
					break;
				case 0:
				case '|':
				case '&':
				case ')':
					mp->current.next_s = (flags & STR_MAXIMAL) ? e : olds;
					mp->next_p = oldp;
					mp->current.groups = g;
					if (!pc && (!mp->best.next_s || (flags & STR_MAXIMAL) && mp->current.next_s > mp->best.next_s || !(flags & STR_MAXIMAL) && mp->current.next_s < mp->best.next_s))
						mp->best = mp->current;
					return 1;
				case '\\':
					if (!(pc = mbgetchar(p)))
						return 0;
					if (pc >= '0' && pc <= '9')
					{
						n = pc - '0';
						if (n <= g && mp->current.beg[n])
							pc = *mp->current.beg[n];
					}
					/*FALLTHROUGH*/
				default:
					if (icase && isupper(pc))
						pc = tolower(pc);
					n = 0;
					break;
				}
				p = oldp;
				for (;;)
				{
					if ((n || pc == sc) && onematch(mp, g, olds, p, e, NiL, flags))
						return 1;
					if (!sc)
						return 0;
					olds = s;
					sc = getsource(s, e);
					if ((flags & STR_ICASE) && isupper(sc))
						sc = tolower(sc);
				}
			}
			else if (pc != '?' && pc != sc)
				return 0;
			break;
		case 0:
			if (!(flags & STR_MAXIMAL))
				sc = 0;
			/*FALLTHROUGH*/
		case '|':
		case '&':
		case ')':
			if (!sc)
			{
				mp->current.next_s = olds;
				mp->next_p = oldp;
				mp->current.groups = g;
			}
			if (!pc && (!mp->best.next_s || (flags & STR_MAXIMAL) && olds > mp->best.next_s || !(flags & STR_MAXIMAL) && olds < mp->best.next_s))
			{
				mp->best = mp->current;
				mp->best.next_s = olds;
				mp->best.groups = g;
			}
			return !sc;
		case '[':
			{
				/*UNDENT...*/

	int	invert;
	int	x;
	int	ok = 0;
	char*	range;

	if (!sc)
		return 0;
	range = 0;
	n = 0;
	if (invert = *p == '!')
		p++;
	for (;;)
	{
		oldp = p;
		if (!(pc = mbgetchar(p)))
			return 0;
		else if (pc == '[' && (*p == ':' || *p == '=' || *p == '.'))
		{
			x = 0;
			n = mbgetchar(p);
			oldp = p;
			for (;;)
			{
				if (!(pc = mbgetchar(p)))
					return 0;
				if (pc == n && *p == ']')
					break;
				x++;
			}
			mbgetchar(p);
			if (ok)
				/*NOP*/;
			else if (n == ':')
			{
				switch (HASHNKEY5(x, oldp[0], oldp[1], oldp[2], oldp[3], oldp[4]))
				{
				case HASHNKEY5(5,'a','l','n','u','m'):
					if (isalnum(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'a','l','p','h','a'):
					if (isalpha(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'b','l','a','n','k'):
					if (isblank(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'c','n','t','r','l'):
					if (iscntrl(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'d','i','g','i','t'):
					if (isdigit(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'g','r','a','p','h'):
					if (isgraph(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'l','o','w','e','r'):
					if (islower(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'p','r','i','n','t'):
					if (isprint(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'p','u','n','c','t'):
					if (ispunct(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'s','p','a','c','e'):
					if (isspace(sc))
						ok = 1;
					break;
				case HASHNKEY5(5,'u','p','p','e','r'):
					if (icase ? islower(sc) : isupper(sc))
						ok = 1;
					break;
				case HASHNKEY5(6,'x','d','i','g','i'):
					if (oldp[5] == 't' && isxdigit(sc))
						ok = 1;
					break;
				}
			}
			else if (range)
				goto getrange;
			else if (*p == '-' && *(p + 1) != ']')
			{
				mbgetchar(p);
				range = oldp;
			}
			else if (isalpha(*oldp) && isalpha(*olds) && tolower(*oldp) == tolower(*olds) || sc == mbgetchar(oldp))
				ok = 1;
			n = 1;
		}
		else if (pc == ']' && n)
		{
			if (ok != invert)
				break;
			return 0;
		}
		else if (pc == '\\' && (oldp = p, !(pc = mbgetchar(p))))
			return 0;
		else if (ok)
			/*NOP*/;
		else if (range)
		{
		getrange:
			if (icase && isupper(pc))
				pc = tolower(pc);
			x = mbgetchar(range);
			if (icase && isupper(x))
				x = tolower(x);
			if (sc == x || sc == pc || sc > x && sc < pc)
				ok = 1;
			if (*p == '-' && *(p + 1) != ']')
			{
				mbgetchar(p);
				range = oldp;
			}
			else
				range = 0;
			n = 1;
		}
		else if (*p == '-' && *(p + 1) != ']')
		{
			mbgetchar(p);
			range = oldp;
			n = 1;
		}
		else
		{
			if (icase && isupper(pc))
				pc = tolower(pc);
			if (sc == pc)
				ok = 1;
			n = pc;
		}
	}

				/*...INDENT*/
			}
			break;
		case '\\':
			if (!(pc = mbgetchar(p)))
				return 0;
			if (pc >= '0' && pc <= '9')
			{
				n = pc - '0';
				if (n <= g && (oldp = mp->current.beg[n]))
				{
					while (oldp < mp->current.end[n])
						if (!*olds || *olds++ != *oldp++)
							return 0;
					s = olds;
					break;
				}
			}
			/*FALLTHROUGH*/
		default:
			if (icase && isupper(pc))
				pc = tolower(pc);
			if (pc != sc)
				return 0;
			break;
		}
	} while (sc);
	return 0;
}
Example #5
0
int is_mvi(int v) {
    return ((v >> 6) == 0) && ISMEM((getsource(v)));
}
Example #6
0
int is_mov(int v) {
    if (ISMEM(getsource(v)) && ISMEM(getdest(v))) return 0; ///BOTH SOURCE AND DEST CAN'T BE MEMORY
    return ((v >> 6) & 0x03) == 0x01;
}
Example #7
0
File: pe184.c Project: manish05/TCR
int main() {
	cl_int err;
	cl_kernel kernel;
	cl_program program;
	cl_mem buffer;
	cl_ulong ans,cur;
	int i,x3,y3;
	char *source;
	size_t localws[3];
	size_t globalws[3];

	initopencl();
	source=getsource("pe184.cl");
	/* create a program object and load source code into it */
	program=clCreateProgramWithSource(context,1,(const char **)&source,NULL,&err);
	if(CL_SUCCESS!=err) clerror("error creating program",err);
	/* builds a program associated with a program object */
	if(CL_SUCCESS!=(err=clBuildProgram(program,1,devices+DEVICEID,NULL,NULL,NULL)))
		clerror("error building program",err);
	/* create kernel object from built program */
	kernel=clCreateKernel(program,"pe184",&err);
	if(CL_SUCCESS!=err) clerror("error creating kernel",err);
	free(source);

	/* create memory buffer: one cl_ulong for each kernel, a total of MAX=N/KERNEL */
	buffer=clCreateBuffer(context,CL_MEM_READ_WRITE,N2*N2*sizeof(cl_uint),NULL,&err);
	if(CL_SUCCESS!=err) clerror("error creating buffer",err);

	globalws[0]=N2;
	globalws[1]=N2;
	globalws[2]=1;

	localws[0]=N2;
	localws[1]=1;
	localws[2]=1;

	ans=0;
	for(x3=0;x3<N;x3++) {
		for(y3=0;y3<N;y3++) if(x3*x3+y3*y3<N*N) {
			/* set up kernel arguments */
			if(CL_SUCCESS!=(err=clSetKernelArg(kernel,0,sizeof(cl_mem),&buffer))) clerror("error setting kernel argument 0",err);
			if(CL_SUCCESS!=(err=clSetKernelArg(kernel,1,sizeof(cl_int),&x3))) clerror("error setting kernel argument 1",err);
			if(CL_SUCCESS!=(err=clSetKernelArg(kernel,2,sizeof(cl_int),&y3))) clerror("error setting kernel argument 2",err);

			/* run kernel */
			if(CL_SUCCESS!=(err=clEnqueueNDRangeKernel(queue,kernel,3,NULL,globalws,localws,0,NULL,NULL)))
				clerror("error running kernel",err);
			/* wait until kernel has finished */
			if(CL_SUCCESS!=(err=clFinish(queue))) clerror("error waiting for queue",err);

			/* copy to host memory */
			if(CL_SUCCESS!=(err=clEnqueueReadBuffer(queue,buffer,CL_TRUE,0,N2*N2*sizeof(cl_uint),a,0,NULL,NULL)))
				clerror("error copying result to host",err);
			if(CL_SUCCESS!=(err=clFinish(queue))) clerror("error waiting for queue",err);

			/* assemble final answer */
			for(cur=i=0;i<N2*N2;i++) cur+=a[i];
			if(x3) cur*=2;
			if(y3) cur*=2;
			ans+=cur;
		}
		printf("done x3=%d/%d\n",x3+1,N);
	}
	printf("answer: "LL"\n",ans/6);

	clReleaseMemObject(buffer);
	clReleaseKernel(kernel);
	clReleaseProgram(program);
	shutdownopencl();
	return 0;
}
Example #8
0
/* Read an event from the tracing output file.
 */

#if MP_GUI_SUPPORT
static
int
readevent(XtPointer p)
#else /* MP_GUI_SUPPORT */
static
int
readevent(void)
#endif /* MP_GUI_SUPPORT */
{
    char s[4];
    allocation *f;
    char *g, *h;
    void *a;
    size_t i, l, m;
    unsigned long n, t, u;

    if (refill(1))
        switch (*bufferpos)
        {
          case 'A':
            bufferpos++;
            bufferlen--;
            currentevent++;
            n = getuleb128();
            a = (void *) getuleb128();
            l = getuleb128();
            getsource(&t, &g, &h, &u);
            f = newalloc(n, currentevent, a, l);
            stats.acount++;
            stats.atotal += l;
            if (stats.pcount < stats.acount - stats.fcount)
                stats.pcount = stats.acount - stats.fcount;
            if (stats.ptotal < stats.atotal - stats.ftotal)
                stats.ptotal = stats.atotal - stats.ftotal;
            if ((stats.lsize == 0) || (stats.lsize > l))
                stats.lsize = l;
            if (stats.usize < l)
                stats.usize = l;
            if (verbose)
            {
                fprintf(stdout, "%6lu  alloc   %6lu  " MP_POINTER "  %8lu"
                        "          %6lu  %8lu\n", currentevent, n, a, l,
                        stats.acount - stats.fcount,
                        stats.atotal - stats.ftotal);
                if (displaysource)
                    printsource(t, g, h, u);
            }
            if (hatffile != NULL)
                fprintf(hatffile, "1 %lu 0x%lx\n", l, a);
            if (f->entry != NULL)
            {
                if ((m = slotentry(f)) > maxslots)
                    maxslots = m;
                fprintf(simfile, "    {%lu, %lu, 0},\n", m, l);
            }
#if MP_GUI_SUPPORT
            if (usegui)
            {
                if (addrbase == NULL)
                    addrbase = (void *) __mp_rounddown((unsigned long) a, 1024);
                drawmemory(a, l, algc);
                return 0;
            }
#endif /* MP_GUI_SUPPORT */
            return 1;
          case 'R':
            bufferpos++;
            bufferlen--;
            currentevent++;
            n = getuleb128();
            a = (void *) getuleb128();
            l = getuleb128();
            getsource(&t, &g, &h, &u);
            if (f = (allocation *) __mp_search(alloctree.root, n))
            {
                if (f->time != 0)
                    fprintf(stderr, "%s: Allocation index `%lu' has already "
                            "been freed\n", progname, n);
                stats.acount++;
                stats.atotal += l;
                stats.fcount++;
                stats.ftotal += f->size;
                if (stats.pcount < stats.acount - stats.fcount)
                    stats.pcount = stats.acount - stats.fcount;
                if (stats.ptotal < stats.atotal - stats.ftotal)
                    stats.ptotal = stats.atotal - stats.ftotal;
                if ((stats.lsize == 0) || (stats.lsize > l))
                    stats.lsize = l;
                if (stats.usize < l)
                    stats.usize = l;
                if (verbose)
                {
                    fprintf(stdout, "%6lu  realloc %6lu  " MP_POINTER
                            "  %8lu          %6lu  %8lu\n", currentevent, n, a,
                            l, stats.acount - stats.fcount,
                            stats.atotal - stats.ftotal);
                    if (displaysource)
                        printsource(t, g, h, u);
                }
                if (hatffile != NULL)
                    fprintf(hatffile, "4 %lu 0x%lx 0x%lx\n", l, f->addr, a);
                if (f->entry != NULL)
                {
                    m = slotentry(f);
                    fprintf(simfile, "    {%lu, %lu, 1},\n", m, l);
                }
#if MP_GUI_SUPPORT
                if (usegui)
                {
                    drawmemory(f->addr, f->size, frgc);
                    drawmemory(a, l, algc);
                }
#endif /* MP_GUI_SUPPORT */
                f->addr = a;
                f->size = l;
            }
            else
                fprintf(stderr, "%s: Unknown allocation index `%lu'\n",
                        progname, n);
#if MP_GUI_SUPPORT
            if (usegui)
                return 0;
#endif /* MP_GUI_SUPPORT */
            return 1;
          case 'F':
            bufferpos++;
            bufferlen--;
            currentevent++;
            n = getuleb128();
            getsource(&t, &g, &h, &u);
            if (f = (allocation *) __mp_search(alloctree.root, n))
            {
                if (f->time != 0)
                    fprintf(stderr, "%s: Allocation index `%lu' has already "
                            "been freed\n", progname, n);
                f->time = currentevent - f->event;
                stats.fcount++;
                stats.ftotal += f->size;
                if (verbose)
                {
                    fprintf(stdout, "%6lu  free    %6lu  " MP_POINTER "  %8lu  "
                            "%6lu  %6lu  %8lu\n", currentevent, n, f->addr,
                            f->size, f->time, stats.acount - stats.fcount,
                            stats.atotal - stats.ftotal);
                    if (displaysource)
                        printsource(t, g, h, u);
                }
                if (hatffile != NULL)
                    fprintf(hatffile, "2 0x%lx\n", f->addr);
                if (f->entry != NULL)
                {
                    fprintf(simfile, "    {%lu, 0, 0},\n", slotentry(f));
                    __mp_freeslot(&table, f->entry);
                    f->entry = NULL;
                }
#if MP_GUI_SUPPORT
                if (usegui)
                    drawmemory(f->addr, f->size, frgc);
#endif /* MP_GUI_SUPPORT */
            }
            else
                fprintf(stderr, "%s: Unknown allocation index `%lu'\n",
                        progname, n);
#if MP_GUI_SUPPORT
            if (usegui)
                return 0;
#endif /* MP_GUI_SUPPORT */
            return 1;
          case 'H':
            bufferpos++;
            bufferlen--;
            a = (void *) getuleb128();
            l = getuleb128();
            if (verbose)
                fprintf(stdout, "        reserve         " MP_POINTER
                        "  %8lu\n", a, l);
            stats.rcount++;
            stats.rtotal += l;
#if MP_GUI_SUPPORT
            if (usegui)
            {
                if (addrbase == NULL)
                    addrbase = (void *) __mp_rounddown((unsigned long) a, 1024);
                drawmemory(a, l, frgc);
                return 0;
            }
#endif /* MP_GUI_SUPPORT */
            return 1;
          case 'I':
            bufferpos++;
            bufferlen--;
            a = (void *) getuleb128();
            l = getuleb128();
            if (verbose)
                fprintf(stdout, "        internal        " MP_POINTER
                        "  %8lu\n", a, l);
            stats.icount++;
            stats.itotal += l;
#if MP_GUI_SUPPORT
            if (usegui)
            {
                drawmemory(a, l, ingc);
                return 0;
            }
#endif /* MP_GUI_SUPPORT */
            return 1;
          default:
            break;
        }
    if ((hatffile != NULL) && (hatffile != stdout) && (hatffile != stderr))
        fclose(hatffile);
    if (simfile != NULL)
    {
        fputs("    {0, 0, 0}\n};\n\n\n", simfile);
        fputs("int main(void)\n{\n", simfile);
        fprintf(simfile, "    void *p[%lu];\n", maxslots);
        fputs("    event *e;\n\n", simfile);
        fputs("    for (e = events; e->index != 0; e++)\n", simfile);
        fputs("        if (e->resize)\n", simfile);
        fputs("        {\n", simfile);
        fputs("            if ((p[e->index - 1] = realloc(p[e->index - 1], "
              "e->size)) == NULL)\n", simfile);
        fputs("            {\n", simfile);
        fputs("                fputs(\"out of memory\\n\", stderr);\n",
                                     simfile);
        fputs("                exit(EXIT_FAILURE);\n", simfile);
        fputs("            }\n", simfile);
        fputs("        }\n", simfile);
        fputs("        else if (e->size == 0)\n", simfile);
        fputs("            free(p[e->index - 1]);\n", simfile);
        fputs("        else if ((p[e->index - 1] = malloc(e->size)) == NULL)\n",
              simfile);
        fputs("        {\n", simfile);
        fputs("            fputs(\"out of memory\\n\", stderr);\n", simfile);
        fputs("            exit(EXIT_FAILURE);\n", simfile);
        fputs("        }\n", simfile);
        fputs("    return EXIT_SUCCESS;\n}\n", simfile);
        if ((simfile != stdout) && (simfile != stderr))
            fclose(simfile);
    }
    getentry(s, sizeof(char), 4, 0);
    if (memcmp(s, MP_TRACEMAGIC, 4) != 0)
    {
        fprintf(stderr, "%s: Invalid file format\n", progname);
        exit(EXIT_FAILURE);
    }
    if (verbose)
        fputc('\n', stdout);
    showstats();
    for (i = 0; i < MP_NAMECACHE_SIZE; i++)
    {
        if (funcnames[i] != NULL)
            free(funcnames[i]);
        if (filenames[i] != NULL)
            free(filenames[i]);
    }
    freeallocs();
    fclose(tracefile);
#if MP_GUI_SUPPORT
    if (usegui)
        return 1;
#endif /* MP_GUI_SUPPORT */
    return 0;
}
Example #9
0
void credits2(void)
{
    int i, ch;
    int p;
    int plast = -1;
    clrscr();

    centerprint(aa_imgwidth(context) / 2, aa_imgheight(context) / 3, 3, 128, "The", 0);
    centerprint(aa_imgwidth(context) / 2, 2 * aa_imgheight(context) / 3, 3, 128, "END", 0);
    drawptr = decrand;
    params->randomval = 50;
    timestuff(0, NULL, draw, 5000000);
    drawptr = NULL;
    params->randomval = 0;
    drawptr = pryc;
    timestuff(0, NULL, draw, MAXTIME);
    drawptr = NULL;
    clrscr();
    draw();
    load_song("bb3.s3m");
    bbupdate();
    starttime = endtime = TIME;
    play();
    bbwait(1);
    for (i = 0; i < LOGOHEIGHT; i++) {
	aa_puts(context, aa_scrwidth(context) / 2 - 2, LOGOY + i, AA_BOLD, "8  8");
	if (i)
	    aa_puts(context, aa_scrwidth(context) / 2 - 2, LOGOY + i - 1, AA_NORMAL, "8  8");
	bbflushwait(100000);
    }
    aa_puts(context, aa_scrwidth(context) / 2 - 2, LOGOY + i - 1, AA_NORMAL, "8  8");

#define LWIDTH

    for (i = aa_scrwidth(context) / 2; i; i--) {
	display8();
	displaya(i);
	bbflushwait(10000);
    }
    for (; i < 100; i++) {
	textclrscr();
	displaya(10 * sin(i * M_PI / 100));
	display8();
	bbflushwait(10000);
    }
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_DIM, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_NORMAL, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_BOLD, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_NORMAL, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    bbwait(1000000);
    for (i = LOGOY; i > 1; i--) {
	textclrscr();
	displogo(i);
	bbflushwait(30000);
    }

    source = malloc(aa_imgwidth(context) * (aa_imgheight(context)));
    target = malloc(aa_imgwidth(context) * (aa_imgheight(context)));
    params->dither = AA_NONE;
    format(dual ? aa_scrwidth(context) / 2 : aa_scrwidth(context));
    p = 0;
    while (1) {
	if (p != plast) {
	    getsource();
	    displaytext(p);
	    gettarget();
	    morph();
	    displaytext(p);
	    aa_flush(context);
        emscripten_sleep(1);
	    plast = p;
	}
      again:
    emscripten_sleep(100);
#ifndef __DJGPP__
	//ch = aa_getkey(context, 100);
    ch = AA_NONE;
#else
	while ((ch = bbupdate()) == AA_NONE) ;
#endif

	switch (ch) {
	case '1':
	    load_song("bb.s3m");
	    bbupdate();
	    play();
	    break;
	case '2':
	    load_song("bb2.s3m");
	    bbupdate();
	    play();
	    break;
	case '3':
	    load_song("bb3.s3m");
	    bbupdate();
	    play();
	    break;

	case 'b':
	case 'k':
	case 'B':
	case 'K':
	case AA_BACKSPACE:
	case AA_UP:
	    p -= (aa_scrheight(context) - YSTART) / 2 * (dual + 1);
	    if (p < 0)
		p = 0;
	    break;
	case AA_DOWN:
	case AA_LEFT:
	case 'f':
	case 'F':
	case ' ':
	case 'j':
	case 'J':
	    p += (aa_scrheight(context) - YSTART) / 2 * (dual + 1);
	    if (p > textsize)
		p = textsize;
	    break;
	case 'q':
	case 'Q':
	case AA_ESC:
	    finish_stuff = 0;
	    backconvert(0, 0, aa_scrwidth(context), aa_scrheight(context));
	    bbupdate();
	    starttime = endtime = TIME;
	    drawptr = decbright;
	    timestuff(0, NULL, draw, 1000000);
	    textclrscr();
	    drawptr = NULL;
	    aa_flush(context);
        emscripten_sleep(1);
	    free(source);
	    free(target);
	    return;
	default:
	    goto again;
	}
	bbupdate();
	starttime = endtime = TIME;
    }
}