예제 #1
0
void colorsearch(char *name)

{

	popmembertype m;

	int tabunbr,tabuminnbr,tabusize;

	int maxiter, tabusteps;

        char info[256];
        long lseconds, lmicrosecs;
        int j,pid;

        /* process id */
        pid = getpid();
        printf("Process pid = %d\n",pid);


	printf("TABU CONTROL INFORMATION\n");

	printf("Maximum Iterations for tabu: ");
	scanf("%d",&maxiter);

	printf("Enter number of neighbors ");
	scanf("%d",&tabunbr);
	printf("%d\n",tabunbr);
	if (tabunbr > MAXTABULIST) {
		printf("ERROR: Cannot exceed %d\n",MAXTABULIST);
		exit(1);
	}

	printf("Enter minimum number of neighbors ");
	scanf("%d",&tabuminnbr);
	printf("%d\n",tabuminnbr);

	printf("Enter tabu list size ");
	scanf("%d",&tabusize);
	printf("%d\n",tabusize);
	if (tabusize > MAXTABU) {
		printf("Tabu size must be no more than %d\n",MAXTABU);
		exit(1);
	}
	if (tabusize < 1) {
		printf("Tabu size must be > 0\n");
		exit(1);
	}

	printf("Enter the target color you  want to try for: ");
	scanf("%hu",&targetK);
	printf("%hu\n",targetK);

	printf("If target not achieved, how many increases allowed: ");
	scanf("%d",&tabusteps);
	printf("%d\n",tabusteps);


	/* compute degree sequences */
	computedeg();


	getacoloring(&m, name, &j); /* open the color file for this graph
			and get the desired coloring */

	verifycolor(&m);

	/* NEEDED target color  as parameter; allow trivial start */

	getcolorinfo(&m);

	memtopart(&m);

	tabucol(maxiter, tabunbr, tabuminnbr, tabusize, tabusteps);

	parttomem(&m);

	greedy(&m, 0, order, MAXVERTEX, SIMPLEG,1);

	getcolorinfo(&m);
	
	printinfo(&m);

	verifycolor(&m);

        i = getrusage(RUSAGE_SELF,&tmp);
        lseconds = tmp.ru_utime.tv_sec-seconds;
        lmicrosecs = tmp.ru_utime.tv_usec-microsecs;

        sprintf(info, "TABU[%d] cpu = %5.2f pid = %d",
                j,lseconds+(lmicrosecs/1000000.0) , pid);

        fileres(name, &m,info);


	/* printcoloring(&m); */
	

}
예제 #2
0
파일: fbpdf.c 프로젝트: litcave/fbpdf
static void mainloop(void)
{
	int step = srows / PAGESTEPS;
	int hstep = scols / PAGESTEPS;
	int c;
	term_setup();
	signal(SIGCONT, sigcont);
	loadpage(num);
	srow = prow;
	scol = -scols / 2;
	draw();
	while ((c = readkey()) != -1) {
		if (c == 'q')
			break;
		if (c == 'e' && reload())
			break;
		switch (c) {	/* commands that do not require redrawing */
		case 'o':
			numdiff = num - getcount(num);
			break;
		case 'Z':
			zoom_def = getcount(zoom);
			break;
		case 'i':
			printinfo();
			break;
		case 27:
			count = 0;
			break;
		case 'm':
			setmark(readkey());
			break;
		case 'd':
			sleep(getcount(1));
			break;
		default:
			if (isdigit(c))
				count = count * 10 + c - '0';
		}
		switch (c) {	/* commands that require redrawing */
		case CTRLKEY('f'):
		case 'J':
			if (!loadpage(num + getcount(1)))
				srow = prow;
			break;
		case CTRLKEY('b'):
		case 'K':
			if (!loadpage(num - getcount(1)))
				srow = prow;
			break;
		case 'G':
			setmark('\'');
			if (!loadpage(getcount(doc_pages(doc) - numdiff) + numdiff))
				srow = prow;
			break;
		case 'O':
			numdiff = num - getcount(num);
			setmark('\'');
			if (!loadpage(num + numdiff))
				srow = prow;
			break;
		case 'z':
			zoom_page(getcount(zoom_def));
			break;
		case 'w':
			zoom_page(pcols ? zoom * scols / pcols : zoom);
			break;
		case 'W':
			if (lmargin() < rmargin())
				zoom_page(zoom * (scols - hstep) /
					(rmargin() - lmargin()));
			break;
		case 'f':
			zoom_page(prows ? zoom * srows / prows : zoom);
			break;
		case 'r':
			rotate = getcount(0);
			if (!loadpage(num))
				srow = prow;
			break;
		case '`':
		case '\'':
			jmpmark(readkey(), c == '`');
			break;
		case 'j':
			srow += step * getcount(1);
			break;
		case 'k':
			srow -= step * getcount(1);
			break;
		case 'l':
			scol += hstep * getcount(1);
			break;
		case 'h':
			scol -= hstep * getcount(1);
			break;
		case 'H':
			srow = prow;
			break;
		case 'L':
			srow = prow + prows - srows;
			break;
		case 'M':
			srow = prow + prows / 2 - srows / 2;
			break;
		case 'C':
			scol = -scols / 2;
			break;
		case ' ':
		case CTRLKEY('d'):
			srow += srows * getcount(1) - step;
			break;
		case 127:
		case CTRLKEY('u'):
			srow -= srows * getcount(1) - step;
			break;
		case '[':
			scol = pcol;
			break;
		case ']':
			scol = pcol + pcols - scols;
			break;
		case '{':
			scol = pcol + lmargin() - hstep / 2;
			break;
		case '}':
			scol = pcol + rmargin() + hstep / 2 - scols;
			break;
		case CTRLKEY('l'):
			break;
		case 'I':
			invert = !invert;
			loadpage(num);
			break;
		default:	/* no need to redraw */
			continue;
		}
		srow = MAX(prow - srows + MARGIN, MIN(prow + prows - MARGIN, srow));
		scol = MAX(pcol - scols + MARGIN, MIN(pcol + pcols - MARGIN, scol));
		draw();
	}
	term_cleanup();
}
예제 #3
0
파일: mupdfinfo.c 프로젝트: UIKit0/mupdf
static void
showinfo(char *filename, int show, char *pagelist)
{
	int page, spage, epage;
	char *spec, *dash;
	int allpages;

	if (!xref)
		infousage();

	allpages = !strcmp(pagelist, "1-");

	spec = fz_strsep(&pagelist, ",");
	while (spec)
	{
		dash = strchr(spec, '-');

		if (dash == spec)
			spage = epage = pagecount;
		else
			spage = epage = atoi(spec);

		if (dash)
		{
			if (strlen(dash) > 1)
				epage = atoi(dash + 1);
			else
				epage = pagecount;
		}

		if (spage > epage)
			page = spage, spage = epage, epage = page;

		if (spage < 1)
			spage = 1;
		if (epage > pagecount)
			epage = pagecount;
		if (spage > pagecount)
			spage = pagecount;

		if (allpages)
			printf("Retrieving info from pages %d-%d...\n", spage, epage);
		if (spage >= 1)
		{
			for (page = spage; page <= epage; page++)
			{
				gatherpageinfo(page);
				if (!allpages)
				{
					printf("Page %d:\n", page);
					printinfo(filename, show, page);
					printf("\n");
				}
			}
		}

		spec = fz_strsep(&pagelist, ",");
	}

	if (allpages)
		printinfo(filename, show, -1);
}
예제 #4
0
int audiosourceffmpeg_loadFFmpeg(void) {
    if (ffmpegopened != 0) {
        if (ffmpegopened == 1) {
            return 1;
        }
        return 0;
    }

    // Load libraries
#ifndef WINDOWS
#ifndef MAC
    // Unix/Linux
    avutilptr = library_LoadSearch("libavutil");
    avcodecptr = library_LoadSearch("libavcodec");
    avformatptr = library_LoadSearch("libavformat");
#else
    // Mac
    void *ffmpegptr = library_LoadSearch("ffmpegsumo");
    avutilptr = ffmpegptr;
    avcodecptr = ffmpegptr;
    avformatptr = ffmpegptr;
#endif
#else
    // Windows ffmpegsumo variant (Google Chrome):
    void *ffmpegptr = library_LoadSearch("ffmpegsumo");
    if (ffmpegptr) {
        avutilptr = ffmpegptr;
        avcodecptr = ffmpegptr;
        avformatptr = ffmpegptr;
    }
    // Windows normal variant:
    if (!ffmpegptr) {
        avutilptr = library_LoadSearch("avutil");
        avcodecptr = library_LoadSearch("avcodec");
        avformatptr = library_LoadSearch("avformat");
    }
#endif

    // Check library load state
    if (!avcodecptr || !avformatptr || !avutilptr) {
#ifdef FFMPEGDEBUG
        printinfo("[FFmpeg-debug] A FFmpeg lib pointer is not present");
#endif
        if (avcodecptr) {
            library_Close(avcodecptr);
        }else{
#ifdef FFMPEGDEBUG
            printinfo("[FFmpeg-debug] avcodecptr NOT present");
#endif
        }
        if (avformatptr) {
#ifndef MAC
            library_Close(avformatptr);
#endif
        }else{
#ifdef FFMPEGDEBUG
            printinfo("[FFmpeg-debug] avformatptr NOT present");
#endif
        }
        if (avutilptr) {
#ifndef MAC
            library_Close(avutilptr);
#endif
        }else{
#ifdef FFMPEGDEBUG
            printinfo("[FFmpeg-debug] avutilptr NOT present");
#endif
        }

#ifdef FFMPEGDEBUG
        printinfo("[FFmpeg-debug] Library not found or cannot be loaded, "
            "FFmpeg support will be unavailable");
#endif
        ffmpegopened = -1;
        return 0;
    }

    // Load functions
    if (!audiosourceffmpeg_loadFFmpegFunctions()) {
        library_Close(avcodecptr);
        library_Close(avformatptr);
#ifdef FFMPEGDEBUG
        printinfo("[FFmpeg-debug] Library misses one or more expected "
            "symbols. FFmpeg support will be unavailable");
#endif
        ffmpegopened = -1;
        return 0;
    }

    // Initialise FFmpeg
    if (!audiosourceffmpeg_initFFmpeg()) {
        library_Close(avcodecptr);
        library_Close(avformatptr);
#ifdef FFMPEGDEBUG
        printinfo("[FFmpeg-debug] Library initialisation failed. FFmpeg "
            "support will be unavailable");
#endif
        ffmpegopened = -1;
        return 0;
    }

#ifdef FFMPEGDEBUG
    printinfo("[FFmpeg-debug] Library successfully loaded.");
#endif
    ffmpegopened = 1;
    return 1;
}
예제 #5
0
static int audiosourceffmpeg_read(struct audiosource *source, char *buffer, unsigned int bytes) {
    struct audiosourceffmpeg_internaldata *idata = source->internaldata;

    if (idata->eof) {
        return -1;
    }

    if (!audiosourceffmpeg_loadFFmpeg()) {
        audiosourceffmpeg_fatalError(source);
        return -1;
    }

    if (!idata->codeccontext) {
        // Get format context
        idata->formatcontext = ffmpeg_avformat_alloc_context();
        if (!idata->formatcontext) {
            audiosourceffmpeg_fatalError(source);
            return -1;
        }

        // av_dict_set(&codec_opts, "request_channels", "2", 0);
        // opts = setup_find_stream_info_opts(ic, codec_opts);

        // Get IO context and buffers
        if (!idata->aviobuf) {
            idata->aviobuf = ffmpeg_av_malloc(AVIOBUFSIZE);
            if (!idata->aviobuf) {
                audiosourceffmpeg_fatalError(source);
                return -1;
            }
        }
        idata->iocontext = ffmpeg_avio_alloc_context(idata->aviobuf, AVIOBUFSIZE, 0, source, ffmpegreader, NULL, NULL);
        if (!idata->iocontext) {
            audiosourceffmpeg_fatalError(source);
            return -1;
        }
        idata->formatcontext->pb = idata->iocontext;
        idata->formatcontext->iformat = NULL;

        // Read format
        if (ffmpeg_avformat_open_input(
                &idata->formatcontext, "", NULL, NULL) != 0) {
            audiosourceffmpeg_fatalError(source);
            return -1;
        }

        // Read detailed stream info
        int i = 0;
        if (ffmpeg_avformat_find_stream_info) {
            // new FFmpeg with avformat_find_stream_info
            if ((i = ffmpeg_avformat_find_stream_info(idata->formatcontext,
            NULL)) < 0) {
                audiosourceffmpeg_fatalError(source);
                return -1;
            }
        } else {
            // old FFmpeg
            if (ffmpeg_av_find_stream_info(idata->formatcontext) < 0) {
                audiosourceffmpeg_fatalError(source);
                return -1;
            }
        }

        // Find best stream
        int stream;
        if (ffmpeg_av_find_best_stream) {
            // use the awesome FFmpeg function
            stream = ffmpeg_av_find_best_stream(idata->formatcontext,
            AVMEDIA_TYPE_AUDIO, -1, -1, &idata->audiocodec, 0);
        } else {
            // simply take the first audio stream
            unsigned int i = 0;
            stream = 0;
            while (i < idata->formatcontext->nb_streams) {
                if (idata->formatcontext->streams[i]->codec->codec_type
                        == AVMEDIA_TYPE_AUDIO) {
                    stream = i;
                    break;
                }
                i++;
            }
        }
        if (stream < 0) {
            audiosourceffmpeg_fatalError(source);
            return -1;
        }

        // Get codec context
        struct AVCodecContext* c =
            idata->formatcontext->streams[stream]->codec;

        // Find best codec, we don't trust av_find_best_stream on this for now
        idata->audiocodec = ffmpeg_avcodec_find_decoder(c->codec_id);
        if (!idata->audiocodec) {
            // Format is recognised, but codec unsupported
            audiosourceffmpeg_fatalError(source);
            return -1;
        }

        // If this isn't an audio stream, we don't want it:
        if (c->codec_type != AVMEDIA_TYPE_AUDIO) {
            audiosourceffmpeg_fatalError(source);
            return -1;
        }

        // Get our actual codec context:
        /*if (ffmpeg_avcodec_alloc_context3) {
            // new FFmpeg with avcodec_alloc_context3
            idata->codeccontext = ffmpeg_avcodec_alloc_context3(idata->audiocodec);
        } else {
            // old FFmpeg
            idata->codeccontext = ffmpeg_avcodec_alloc_context();
        }*/
        idata->codeccontext = c;

        // Initialise codec. XXX avcodec_open2 is not thread-safe!
        if (ffmpeg_avcodec_open2(idata->codeccontext, idata->audiocodec, NULL) < 0) {
            audiosourceffmpeg_fatalError(source);
            return -1;
        }

        // Allocate buffer for finished, decoded data
        if (!idata->decodedbuf) {
            idata->decodedbuf = ffmpeg_av_malloc(DECODEDBUFSIZE);
            if (!idata->decodedbuf) {
                audiosourceffmpeg_fatalError(source);
                return -1;
            }
        }

        // Remember format data
        source->channels = c->channels;
        source->samplerate = c->sample_rate;
        switch (c->sample_fmt) {
        case AV_SAMPLE_FMT_U8:
            source->format = AUDIOSOURCEFORMAT_U8;
            break;
        case AV_SAMPLE_FMT_S16:
            source->format = AUDIOSOURCEFORMAT_S16LE;
            break;
        case AV_SAMPLE_FMT_FLT:
            source->format = AUDIOSOURCEFORMAT_F32LE;
            break;
        default:
            audiosourceffmpeg_fatalError(source);
            return -1;
        }
        if (source->channels <= 1 || source->samplerate <= 0) {
#ifdef FFMPEGDEBUG
            printwarning("[FFmpeg-debug] format probing failed: channels "
                "or sample rate unknown or unsupported");
#endif
            // not a known format apparently
            audiosourceffmpeg_fatalError(source);
            return -1;
        }
#ifdef FFMPEGDEBUG
        printinfo("[FFmpeg-debug] audiostream initialised: rate: %d, "
            "channels: %d, format: %d", source->samplerate, source->channels,
            source->format);
#endif
    }

    // we need to return how many bytes we read, so remember it here:
    int writtenbytes = 0;

    // we might have some decoded bytes left:
    if (idata->decodedbufbytes > 0 && bytes > 0) {
        // see how many we want to copy and how many we can actually copy:
        int copybytes = bytes;

        if (copybytes > idata->decodedbufbytes) {
            copybytes = idata->decodedbufbytes;
        }

        // copy bytes to passed buffer:
        memcpy(buffer, idata->decodedbuf, copybytes);
        buffer += copybytes;

        // trim copied bytes from our internal buffer of decoded data:
        if (copybytes < idata->decodedbufbytes) {
            memmove(idata->decodedbuf, idata->decodedbuf + copybytes,
                DECODEDBUFSIZE - copybytes);
        }

        idata->decodedbufbytes -= copybytes;
        bytes -= copybytes;
        writtenbytes += copybytes;
    }

    while (bytes > 0 && !idata->packetseof) {
        int packetresult = -1;
        if (!idata->packetseof) { // fetch new packet
            packetresult = ffmpeg_av_read_frame(idata->formatcontext,
                &idata->packet);
        }
        if (packetresult == 0) {
            // decode with FFmpeg:
            int len,gotframe;
            char *outputbuf __attribute__ ((aligned(16)));
            int bufsize = 0;
            // old variant: decode_audio3:
            if (!ffmpeg_avcodec_decode_audio4) {
                if (!idata->tempbuf) {
                    idata->tempbuf = ffmpeg_av_malloc(
                    AVCODEC_MAX_AUDIO_FRAME_SIZE + 32);
                    outputbuf = idata->tempbuf;
                }

                bufsize = AVCODEC_MAX_AUDIO_FRAME_SIZE + 16;
                gotframe = 0;
                len = ffmpeg_avcodec_decode_audio3(
                    idata->codeccontext,
                    (int16_t*)outputbuf,
                    &bufsize,
                    &idata->packet
                );
                if (len > 0) {
                    gotframe = 1;
                }
            } else {
                // new variant: decode_audio4:
                len = ffmpeg_avcodec_decode_audio4(
                    idata->codeccontext,
                    idata->decodedframe,
                    &gotframe,
                    &idata->packet
                );
            }

            if (len < 0) {
                // A decode error occured:
#ifdef FFMPEGDEBUG
                char errbuf[512] = "Unknown";
                if (ffmpeg_av_strerror) {
                    ffmpeg_av_strerror(len, errbuf, sizeof(errbuf)-1);
                }
                errbuf[sizeof(errbuf)-1] = 0;
                printwarning("[FFmpeg-debug] avcodec_decode_audio3 error: "
                    "%s",errbuf);
#endif
                if (ffmpeg_av_read_frame(
                        idata->formatcontext, &idata->packet) < 0) {
                    // buggy FFmpeg EOF
#ifdef FFMPEGDEBUG
                    printwarning("[FFmpeg-debug] buggy FFmpeg EOF");
#endif
                    idata->packetseof = 1;
                    return writtenbytes;
                }
                audiosourceffmpeg_fatalError(source);
                return -1;
            }else{
                if (len == 0) {
                    idata->packetseof = 1;
                }
            }

            // return data if we have some
            if (gotframe) {
                int framesize;  // amount of bytes
                const char *p;  // pointer to byte data
                if (!ffmpeg_avcodec_decode_audio4) {
                    // old variant: decode_audio3:
                    framesize = bufsize;
                    p = outputbuf;
                } else {
                    // new variant: decode_audio4:
                    framesize = ffmpeg_av_samples_get_buffer_size(
                    NULL,
                    idata->codeccontext->channels,
                    idata->decodedframe->nb_samples,
                    idata->codeccontext->sample_fmt,
                    1);
                    p = (char*)idata->decodedframe->data[0];
                }

                // first, export as much as we can
                if (bytes > 0) {
                    // ideally, we would copy the whole frame:
                    unsigned int copybytes = framesize;

                    // practically, we don't want more than what is specified
                    // in 'bytes':
                    if (copybytes > bytes) {
                        copybytes = bytes;
                    }

                    // copy the bytes, move the buffers accordingly:
                    memcpy(buffer, p, copybytes);
                    buffer += copybytes;
                    bytes -= copybytes;
                    framesize -= copybytes;
                    p += copybytes;
                    writtenbytes += copybytes;
                }

                // maximal preserval size:
                if (framesize > DECODEDBUFSIZE) {
                    // we will simply crop the frame.
                    // evil but the show must go on
                    framesize = DECODEDBUFSIZE;
                }

                // if we have any bytes left, preserve them now:
                if (framesize > 0) {
                    memcpy(idata->decodedbuf + idata->decodedbufbytes, p,
                        framesize);
                    idata->decodedbufbytes += framesize;
                }
            }
        }else{
예제 #6
0
// Initialise the given connection struct and open the connection
void connections_Init(struct connection* c, const char* target, int port, int linebuffered, int lowdelay, int canautoclose, void (*autoclosecallback)(struct connection* c), void* userdata) {
    int oldluaref = c->luarefcount;
    memset(c, 0, sizeof(*c));
    c->luarefcount = oldluaref;
    c->socket = -1;
    c->error = -1;
    c->canautoclose = canautoclose;
    c->autoclosecallback = autoclosecallback;
    c->userdata = userdata;
    c->lowdelay = lowdelay;
    c->targetport = port;
    c->linebuffered = linebuffered;
    c->lastreadtime = time_getMilliseconds();
    if (connectionlist) {
        c->next = connectionlist;
    }
    connectionlist = c;
#ifdef CONNECTIONSDEBUG
    printinfo("[connections] Adding connection to list");
#endif
    // initialise socket system (just in case it's not done yet):
    if (!so_Startup()) {
        c->error = CONNECTIONERROR_INITIALISATIONFAILED;
        return;
    }
    // with an empty target, we simply won't do anything except instant-error:
    if (!target) {
        c->error = CONNECTIONERROR_NOSUCHHOST;
        return;
    }
    // allocate buffers:
    c->inbuf = malloc(CONNECTIONINBUFSIZE);
    if (!c->inbuf) {
        c->error = CONNECTIONERROR_INITIALISATIONFAILED;
        return;
    }
    c->inbufsize = CONNECTIONINBUFSIZE;
    c->outbuf = malloc(CONNECTIONOUTBUFSIZE);
    if (!c->outbuf) {
        c->error = CONNECTIONERROR_INITIALISATIONFAILED;
        return;
    }
    c->outbufsize = CONNECTIONOUTBUFSIZE;
    // get a socket
    if (isipv4ip(target)) { // only take ipv4 when it's obvious
        if (!connections_SetSocket(c, IPTYPE_IPV4)) {
            c->error = CONNECTIONERROR_INITIALISATIONFAILED;
            return;
        }
    } else { // otherwise, try ipv6 first
        if (!connections_SetSocket(c, IPTYPE_IPV6)) {
            c->error = CONNECTIONERROR_INITIALISATIONFAILED;
            return;
        }
    }
    // we probably need to resolve the host first:
    if (!isipv4ip(target) && !isipv6ip(target)) {
        c->hostresolveptr = hostresolv_LookupRequest(target, 0);
        c->hostresolveptrv6 = hostresolv_LookupRequest(target, 1);
        if (!c->hostresolveptrv6) { // we really want v6 resolution, so we work well with ipv6-only
            if (c->hostresolveptr) {
                hostresolv_CancelRequest(c->hostresolveptr);
            }
            c->hostresolveptr = NULL;
        }
#ifdef CONNECTIONSDEBUG
        printinfo("[connections] resolving target: %s",target);
#endif
        return;
    }
    // connect:
    int result = connections_TryConnect(c, target);
    if (!result) {
        return;
    }
    // we want to know when ready for writing, since that means we're connected:
    so_SelectWantWrite(c->socket, 1);
#ifdef CONNECTIONSDEBUG
    printinfo("[connections] connecting to ip: %s", target);
#endif
}
예제 #7
0
// Check all connections for events, updates etc
int connections_CheckAll(int (*connectedcallback)(struct connection* c), int (*readcallback)(struct connection* c, char* data, unsigned int datalength), int (*errorcallback)(struct connection* c, int error)) {
    // initialise socket system (just in case it's not done yet):
    if (!so_Startup()) {
        return 1;
    }
    struct connection* c = connectionlist;
    while (c) {
        struct connection* cnext = c->next;
        // don't process connections with errors
        if (c->error >= 0) {
            if (!c->errorreported) {
                c->errorreported = 1;
                if (errorcallback) {
                    if (!errorcallback(c, c->error)) {
                        // an error occured. proceed to next connect:
                        c = cnext;
                        continue;
                    }
                }
            }
        }
        // check for auto close:
        if (c->canautoclose && c->wantautoclose &&
                (c->error >= 0 || c->lastreadtime + 30000 <
                time_getMilliseconds()) && !c->closewhensent) {
            if (c->error >= 0) { // connection already error'd, we can get rid of it:
#ifdef CONNECTIONSDEBUG
                printinfo("[connections] autoclosing connection %d", c->socket);
#endif
                c->autoclosecallback(c);
                connections_Close(c);
                c = cnext;
            } else {
                // make the connection error:
                connections_E(c, errorcallback,
                CONNECTIONERROR_CONNECTIONAUTOCLOSE);
            }
            continue;
        }
        // check for close after send:
        if (c->outbufbytes <= 0 && c->closewhensent) {
            if (c->luarefcount <= 0) {
#ifdef CONNECTIONSDEBUG
                printinfo("[connections] closing connection %d "
                "since data is sent", c->socket);
#endif
                connections_Close(c);
            } else {
                // lua still has a reference, don't close
            }
            c = cnext;
            continue;
        }
        // check host resolve requests first:
        if (c->error < 0 && !c->closewhensent && (c->hostresolveptr || c->hostresolveptrv6)) {
            int rqstate1 = RESOLVESTATUS_SUCCESS;
            if (c->hostresolveptr) {
                rqstate1 = hostresolv_GetRequestStatus(c->hostresolveptr);
            }
            int rqstate2 = RESOLVESTATUS_SUCCESS;
            if (c->hostresolveptrv6) {
                rqstate2 = hostresolv_GetRequestStatus(c->hostresolveptrv6);
            }
            if (rqstate1 != RESOLVESTATUS_PENDING &&
                    rqstate2 != RESOLVESTATUS_PENDING) {
                // requests are done, get ips:
                char* ipv4 = NULL;
                char* ipv6 = NULL;

                // ipv4 ip:
                const char* p = NULL;
                if (rqstate1 == RESOLVESTATUS_SUCCESS && c->hostresolveptr) {
                    p = hostresolv_GetRequestResult(c->hostresolveptr);
                }
                if (p) {
                    ipv4 = strdup(p);
                }

                // ipv6 ip:
                p = NULL;
                if (rqstate2 == RESOLVESTATUS_SUCCESS && c->hostresolveptrv6) {
                    p = hostresolv_GetRequestResult(c->hostresolveptrv6);
                }
                if (p) {
                    ipv6 = strdup(p);
                }

                // free requests:
                if (c->hostresolveptr) {
                    hostresolv_CancelRequest(c->hostresolveptr);
                }
                if (c->hostresolveptrv6) {
                    hostresolv_CancelRequest(c->hostresolveptrv6);
                }
                c->hostresolveptr = NULL;
                c->hostresolveptrv6 = NULL;

#ifdef CONNECTIONSDEBUG
                printinfo("[connections] resolved host, results: v4: %s, v6: %s", ipv4, ipv6);
#endif

                // if we got a v6 ip, connect there first:
                int result;
                if (ipv6) {
                    // Prefer an IPv6 connection:
                    result = connections_TryConnect(c, ipv6);
                    free(ipv6);
                    if (!result) {
                        if (ipv4) {
                            c->error = -1;
                            // Try an IPv4 connection:
                            result = connections_TryConnect(c, ipv4);
                            free(ipv4);
                            if (!result) {
                                connections_E(c, errorcallback,
                                CONNECTIONERROR_CONNECTIONFAILED);
                            }
                        }
                        c = cnext;
                        continue;
                    }
                    // ok we are about to connect, preserve v4 ip for later trying in case it fails:
                    c->retryv4ip =  ipv4;

                    // then continue:
                    c = cnext;
                    continue;
                } else {
                    if (ipv4) {
                        // Attempt an IPv4 connection:
                        result = connections_TryConnect(c, ipv4);
                        if (result) {
                            free(ipv4);
                            c = cnext;
                            continue;
                        }

                        // Didn't work, so nothing we can do:
                        free(ipv4);
                        connections_E(c, errorcallback,
                        CONNECTIONERROR_CONNECTIONFAILED);
                    } else {
                        connections_E(c, errorcallback,
                        CONNECTIONERROR_NOSUCHHOST);
                    }
                    c = cnext;
                    continue;
                }
            }
        }
        // if the connection is attempting to connect, check if it succeeded:
        if (c->error < 0 && !c->closewhensent && !c->connected &&
                c->socket >= 0) {
            if (so_SelectSaysWrite(c->socket, &c->sslptr)) {
                if (c->outbufbytes <= 0) {
                    so_SelectWantWrite(c->socket, 0);
                }
                if (so_CheckIfConnected(c->socket, &c->sslptr)) {
#ifdef CONNECTIONSDEBUG
                    printinfo("[connections] now connected");
#endif

                    c->connected = 1;
                    if (connectedcallback) {
                        if (!connectedcallback(c)) {
                            // a callback error occured.
                            // we will simply continue.
                        }
                    }
                } else {
                    // we aren't connected!
                    if (c->retryv4ip) { // we tried ipv6, now try ipv4
#ifdef CONNECTIONSDEBUG
                        printinfo("[connections] retrying v4 after v6 "
                            "fail...");
#endif
                        // attempt to connect:
                        int result = connections_TryConnect(c, c->retryv4ip);
                        free(c->retryv4ip);
                        c->retryv4ip = NULL;
                        if (!result) {
                            connections_E(c, errorcallback,
                            CONNECTIONERROR_CONNECTIONFAILED);
                        }
                        c = cnext;
                        continue;
                    }
#ifdef CONNECTIONSDEBUG
                    printinfo("[connections] connection couldn't be "
                        "established");
#endif
                    connections_E(c, errorcallback,
                    CONNECTIONERROR_CONNECTIONFAILED);
                    c = cnext;
                    continue;
                }
            }
        }
        // read things if we can:
        if (c->error < 0 && c->socket >= 0 && !c->closewhensent &&
                c->connected) {
            if (so_SelectSaysRead(c->socket, &c->sslptr)) {
                if (c->inbufbytes >= c->inbufsize && c->linebuffered == 1) {
                    // we will break this mega line into two:
                    // first, send without line processing:
                    c->linebuffered = 0;
                    int closed = 0;
                    if (!connections_ProcessReceivedData(c, readcallback,
                            &closed)) {
                        // an error occured in te read callback.
                        // we will simply continue.
                    }
                    if (closed) { // connection was closed by callback
                        c = cnext;
                        continue;
                    }
                    if (c->error >= 0) { // lua closed this connection
                        c = cnext;
                        continue;
                    }
                    // then, turn it back on:
                    c->linebuffered = 1;
                }
                // read new bytes into the buffer:
                int r = so_ReceiveSSLData(c->socket, c->inbuf + c->inbufbytes,
                    c->inbufsize - c->inbufbytes, &c->sslptr);
                if (r == 0)  {
                    // connection closed. send out all data we still have:
                    if (c->inbufbytes > 0) {
                        int closed = 0;
                        if (!connections_ProcessReceivedData(
                        c, readcallback, &closed)) {
                            // an error occured in the read callback.
                            // we will simply continue.
                        }
                        if (closed) { // connection was closed by callback
                            c = cnext;
                            continue;
                        }
                    }
                    // then error:
                    connections_E(c, errorcallback,
                    CONNECTIONERROR_CONNECTIONCLOSED);
#ifdef CONNECTIONSDEBUG
                    printinfo("[connections] receive on %d returned "
                        "end of stream", c->socket);
#endif
                    c = cnext;
                    continue;
                }
                if (r > 0) { // we successfully received new bytes
                    c->inbufbytes += r;
                    c->lastreadtime = time_getMilliseconds();
                    int closed = 0;
                    if (!connections_ProcessReceivedData(c, readcallback,
                            &closed)) {
                        // an error occured in the read callback.
                        // we will simply continue.
                    }
                    if (closed) { // connection was closed by callback
                        c = cnext;
                        continue;
                    }
                }
            }
        }
        // write things if we can:
        if ((c->error < 0 ||
                (c->closewhensent)) && c->connected
                && c->outbufbytes > 0 && c->socket >= 0) {
            if (so_SelectSaysWrite(c->socket, &c->sslptr)) {
                int r = so_SendSSLData(c->socket, c->outbuf + c->outbufoffset,
                c->outbufbytes, &c->sslptr);
                if (r == 0) {
                    // connection closed:
                    connections_E(c, errorcallback,
                    CONNECTIONERROR_CONNECTIONCLOSED);
#ifdef CONNECTIONSDEBUG
                    printinfo("[connections] send returned end of stream");
#endif
                    c = cnext;
                    continue;
                }
                // remove sent bytes from buffer:
                if (r > 0) {
                    c->outbufbytes -= r;
                    c->outbufoffset += r;
                    so_SelectWantWrite(c->socket, 1);
                    if (c->outbufbytes <= 0) {
                        c->outbufoffset = 0;
                        so_SelectWantWrite(c->socket, 0);
                    } else {
                        if (c->outbufoffset > CONNECTIONOUTBUFSIZE/2) {
                            // move buffer contents back to beginning
                            memmove(c->outbuf, c->outbuf + c->outbufoffset, c->outbufbytes);
                            c->outbufoffset = 0;
                        }
                    }
                }
            }
        }

        // check for close after send:
        if (c->outbufbytes <= 0 && c->closewhensent) {
            if (c->luarefcount <= 0) {
#ifdef CONNECTIONSDEBUG
                printinfo("[connections] closing connection %d since data is sent", c->socket);
#endif
                connections_Close(c);
            } else {
                // lua still has a reference, but close at least the socket:
                so_CloseSSLSocket(c->socket, &c->sslptr);
                c->socket = -1;
            }
            c = cnext;
            continue;
        }

        c = cnext;
    }
    return 1;
}
예제 #8
0
void colorsearch(char *name)
/* 
	This version uses the greedy, this routine 
	asks for the various parameters.
*/

{
	popmembertype m;
	greedytype initGreedy;
	int	vordering,kempewh;
	char	usekempe[5];
	int i;

	int *secondary;

        char info[256];
        long lseconds, lmicrosecs;
        int pid;

	/* process id */
	pid = getpid();
	printf("Process pid = %d\n",pid);

	printf("GREEDY TYPE SELECTION\n");
	printf("\t%1d\tSimple Greedy\n",SIMPLEG);
	printf("\t%1d\tLargest First Greedy\n",LARGESTG);
	printf("\t%1d\tSmallest First Greedy\n",SMALLESTG);
	printf("\t%1d\tRandom Sequence Greedy\n",RANDSEQG);
	printf("\t%1d\tReverse Order Greedy\n",REVERSEG);
	printf("\t%1d\tStir Color Greedy\n",STIRGRDY);
	
	printf("Which for this program ");
	scanf("%d",&initGreedy);
	printf("%d\n",initGreedy);
	if ((initGreedy >= MAXGRDY) || (initGreedy < 1)){
		printf("GREEDY: Illegal Greedy type\n");
		exit(1);
	}

	printf("Initial Vertex Ordering:\n\t1 -- inorder\n\t2 -- random\n");
	printf("\t3 -- decreasing degree\n\t4 -- increasing degree\n");
	printf("\t5 -- LBFS random\n\t6 -- LBFS decreasing degree\n");
	printf("\t7 -- LBFS increasing degree\n");

	printf("Using: ");
	scanf("%d",&vordering);
	printf("%d\n",vordering);

	switch(vordering) {
		case 1 :
			for(i=0;i<order;i++) m.vc[i].vertex = i;
			break;
		case 2 : 
			for(i=0;i<order;i++) m.vc[i].vertex = i;
			permute(&m,0,order); 
			break;
		case 3 : 
			for(i=0;i<order;i++) m.vc[i].vertex = i;
			computedeg();
			qsort((char *) m.vc,(int) order,
                          sizeof(struct vrtxandclr), (compfunc)decdeg);
			break; 
		case 4: 
			for(i=0;i<order;i++) m.vc[i].vertex = i;
			computedeg();
			qsort((char *) m.vc,(int) order,
                          sizeof(struct vrtxandclr),(compfunc)incdeg);
			break;
		case 5: 
			secondary = (int *)malloc(order*sizeof(int));
			for(i=0;i<order;i++) secondary[i] = random();
			lbfs(&m,secondary);
			free(secondary);
			break;
		case 6:
			secondary = (int *) malloc(order*sizeof(int));
			computedeg();
			for(i=0;i<order;i++) secondary[i] = degseq[i];
			lbfs(&m,secondary);
			free(secondary);
			break;
		case 7: 
			secondary = (int *) malloc(order*sizeof(int));
			computedeg();
			for(i=0;i<order;i++) secondary[i] = order - degseq[i];
			lbfs(&m,secondary);
			free(secondary);
			break;
		default : {
			printf("GREEDY: Illegal Vertex Ordering\n");
			exit(1);
		}
	}

	printf("Use kempe reductions y/n ");
	scanf("%s",usekempe);
	printf("%s\n",usekempe);
	if  ( usekempe[0] == 'y') {
		kempewh = 0;
	} else if (usekempe[0] == 'n' ) {
		kempewh = 1;
	} else {
		printf("GREEDY: illegal input for Kempe selection\n");
		exit(1);
	}

	greedy(&m, 0, order, MAXVERTEX, initGreedy, kempewh);

	getcolorinfo(&m);
	
	printinfo(&m);

	verifycolor(&m);

        i = getrusage(RUSAGE_SELF,&tmp);
        lseconds = tmp.ru_utime.tv_sec-seconds;
        lmicrosecs = tmp.ru_utime.tv_usec-microsecs;

        sprintf(info, "GREEDY cpu = %5.2f pid = %d",
                lseconds+(lmicrosecs/1000000.0) , pid);

        fileres(name, &m,info);



	/* printcoloring(&m); */
	

}
예제 #9
0
파일: ex_2-01.c 프로젝트: gsher/edu
/* A program to display the maximum and minimum values of signed and 
 * unsigned char, short, int, and long variables, by symbolic constants
 * and by computation. */
main()
{
	/* UNSIGNED CHAR */
	printinfo("UNSIGNED CHAR", UCHAR_MAX, 0);

	unsigned char uc_min, uc_max, uc_comparison;
	uc_min = uc_max = uc_comparison = 0;
	++uc_comparison;
	while(uc_comparison > uc_max) { ++uc_comparison; ++uc_max; }

	uc_comparison = 0;
	--uc_comparison;
	while(uc_comparison < uc_min) { --uc_comparison; --uc_min; }

	printinfo("CALC UNSIGNED CHAR", uc_max, uc_min);

	/* SIGNED CHAR */
	printinfo("SIGNED CHAR", SCHAR_MAX, SCHAR_MIN);

	signed char sc_min, sc_max, sc_comparison;
	sc_min = sc_max = sc_comparison = 0;
	++sc_comparison;
	while(sc_comparison > sc_max) { ++sc_comparison; ++sc_max; }

	sc_comparison = 0;
	--sc_comparison;
	while(sc_comparison < sc_min) { --sc_comparison; --sc_min; }
	printinfo("CALC SIGNED CHAR", sc_max, sc_min);

	/* UNSIGNED SHORT */
	printinfo("UNSIGNED SHORT", USHRT_MAX, 0);

	unsigned short us_min, us_max, us_comparison;
	us_min = us_max = us_comparison = 0;
	++us_comparison;
	while(us_comparison > us_max) { ++us_comparison; ++us_max; }

	us_comparison = 0;
	--us_comparison;
	while(us_comparison < us_min) { --us_comparison; --us_min; }

	printinfo("CALC UNSIGNED SHORT", us_max, us_min);

	/* SIGNED SHORT */
	printinfo("SIGNED SHORT", SHRT_MAX, SHRT_MIN);

	signed short ss_min, ss_max, ss_comparison;
	ss_min = ss_max = ss_comparison = 0;
	++ss_comparison;
	while(ss_comparison > ss_max) { ++ss_comparison; ++ss_max; }

	ss_comparison = 0;
	--ss_comparison;
	while(ss_comparison < ss_min) { --ss_comparison; --ss_min; }

	printinfo("CALC SIGNED SHORT", ss_max, ss_min);

	/* UNSIGNED INT */
	printf("UNSIGNED INT\n");
	printf("\tmax: %u\n", UINT_MAX);
	printf("\tmin: %u\n", 0);

	unsigned int ui_min, ui_max, ui_comparison;
	ui_min = ui_max = ui_comparison = 0;
	++ui_comparison;
	while(ui_comparison > ui_max) { ++ui_comparison; ++ui_max; }

	ui_comparison = 0;
	--ui_comparison;
	while(ui_comparison < ui_min) { --ui_comparison; --ui_min; }

	printf("CALC UNSIGNED INT\n");
	printf("\tmax: %u\n", ui_max);
	printf("\tmin: %u\n", ui_min);

	/* SIGNED INT */
	printinfo("SIGNED INT", INT_MAX, INT_MIN);

	signed int si_min, si_max, si_comparison;
	si_min = si_max = si_comparison = 0;
	++si_comparison;
	while(si_comparison > si_max) { ++si_comparison; ++si_max; }

	si_comparison = 0;
	--si_comparison;
	while(si_comparison < si_min) { --si_comparison; --si_min; }

	printinfo("CALC SIGNED INT", si_max, si_min);

	/* UNSIGNED LONG */
	printf("UNSIGNED LONG\n");
	printf("\tmax: %lu\n", ULONG_MAX);
	printf("\tmin: %d\n", 0);

	unsigned long ul_min, ul_max, ul_comparison;
	ul_min = ul_max = ul_comparison = 0;
	++ul_comparison;
	while(ul_comparison > ul_max) { ++ul_comparison; ++ul_max; }

	ul_comparison = 0;
	--ul_comparison;
	while(ul_comparison < ul_min) { --ul_comparison; --ul_min; }

	printf("CALC UNSIGNED LONG\n");
	printf("\tmax: %lu\n", ul_max);
	printf("\tmin: %lu\n", ul_min);

	/* SIGNED LONG */
	printf("SIGNED LONG\n");
	printf("\tmax: %ld\n", LONG_MAX);
	printf("\tmin: %ld\n", LONG_MIN);

	signed long sl_min, sl_max, sl_comparison;
	sl_min = sl_max = sl_comparison = 0;
	++sl_comparison;
	while(sl_comparison > sl_max) { ++sl_comparison; ++sl_max; }

	sl_comparison = 0;
	--sl_comparison;
	while(sl_comparison < sl_min) { --sl_comparison; --sl_min; }

	printf("SIGNED LONG\n");
	printf("\tmax: %ld\n", sl_max);
	printf("\tmin: %ld\n", sl_min);
}
예제 #10
0
int main()
{
    list_parent L1;
    list_child L2;
    addressp p,r,s;
    addressc q;
    infotype_parent x1,cari1;
    infotype_child x2, cari2;
    createListChild(L2);
    createListParent(L1);
    int pil,pol;
    char lagi='Y';

    while (lagi=='Y'){
        system("cls");
        cout << endl;
        cout << " ========================================================= \n";
        cout << " *          RESTAURANT MANAGEMENT APPLICATION            * \n"
             << " ========================================================= \n"
             << " *         1. Tambah Rumah Makan                         * \n"
             << " *         2. Edit Rumah Makan                           * \n"
             << " *         3. Cari Rumah Makan Berdasarkan Id            * \n"
             << " *         4. Cari Menu Berdasarkan Id                   * \n"
             << " *         5. Tambah Menu Suatu Rumah Makan              * \n"
             << " *         6. Hapus Menu Suatu Rumah Makan               * \n"
             << " *         7. Hapus Rumah Makan Beserta Menu             * \n"
             << " *         8. Lihat List Menu Suatu Rumah Makan          * \n"
             << " *         9. Lihat List Rumah Makan                     * \n"
             << " *        10. Sort Rumah Makan by Id                     * \n"
             << " *        11. Menu Favorit Suatu Rumah Makan             * \n"
             << " *        12. Keuntungan Suatu Rumah Makan               * \n"
             << " *        13. Menu Terbanyak                             * \n"
             << " *        14. Keluar                                     * \n"
             << " ========================================================= \n \n"
             << " ========================================================= \n"
             << " *         Masukkan Pilihan Anda :                       * \n";
        cout << " ========================================================= \n";
        gotoxy(35,21); cin >> pil;
        cin.ignore();

        if (pil >1 || pil <10){
            pol=pil;
        }
        else{
            lagi='Y';
        }

        switch (pol){
            case 1:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*             TAMBAH RUMAH MAKAN                   * \n"
                     << "==================================================== \n";
                cout << endl;
                TambahRumahMakan(x1);
                p=alokasiParent(x1);
                r=first(L1);

                s=CariRumahMakan(L1,x1);
                if(s==nil){
                    insertLastParent(L1,p);
                    cout << endl;
                    cout << "   INSERT DATA SUKSES ! \n ";
                }
                else{
                    cout << "   ID RUMAH MAKAN SAMA ! \n";
                }

                getch();
                break;


            case 2:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*                EDIT RUMAH MAKAN                  * \n"
                     << "==================================================== \n";
                cout << endl;

                cout << "    List Id Rumah Makan : "; printIdRumahMakan(L1);
                cout << endl;
                cout << "    Masukkan Id Rumah Makan : ";
                getline(cin,cari1.id);
                p=CariRumahMakan(L1,cari1);

                if (p==nil){
                    cout << endl;
                    cout << "    ID RUMAH MAKAN TIDAK DITEMUKAN ";
                }
                else{
                    cout << endl;
                    editRumahMakan(L1,p);
                }
                getch();
                break;

            case 3:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*        CARI RUMAH MAKAN BERDASARKAN ID           * \n"
                     << "==================================================== \n";
                cout << endl;
                cout << "    Masukkan ID :  ";
                getline(cin,cari1.id);

                p=CariRumahMakan(L1,cari1);
                if (p==nil){
                    cout << endl << endl;
                    cout << "    ID RUMAH MAKAN TIDAK DITEMUKAN \n";
                }
                else{
                    cout << endl;
                    cout << "    RUMAH MAKAN DITEMUKAN \n \n";

                    cout << "    ID Rumah Makan     : " << info(p).id << endl;
                    cout << "    Nama Rumah Makan   : " << info(p).nama << endl;
                    cout << "    Alamat Rumah Makan : " << info(p).alamat << endl;
                    cout << "    Tanggal Pembuatan  : " << info(p).tanggal << endl;
                    cout << "    Pajak Rumah Makan  : " << info(p).pajak << endl << endl << endl;
                }
                getch();
                break;


            case 4:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*             CARI MENU BERDASARKAN ID             * \n"
                     << "==================================================== \n";
                cout << endl;

                cout << "    List Id Rumah Makan : "; printIdRumahMakan(L1);
                cout << endl;

                cout << "    Masukkan Id Rumah Makan : ";
                getline(cin,x1.id);
                cout << "    Masukkan Id Menu        : ";
                getline(cin,x2.id);

                p=CariRumahMakan(L1,x1);
                q=cariMenu2(L1,p,x2);

                cout << endl << endl;
                if (p==nil){
                    cout << "    RUMAH MAKAN TIDAK DITEMUKAN \n";
                }
                else{
                    if(q!=nil){
                        cout << "    MENU DITEMUKAN \n \n";

                        cout << "    ID Menu   : " << info(q).id << endl;
                        cout << "    Nama Menu : " << info(q).nama << endl;
                        cout << "    Harga     : " << info(q).harga << endl;
                    }
                    else{
                        cout << endl;
                        cout << "    MENU TIDAK DITEMUKAN \n \n";
                    }
                }
                getch();
                break;


            case 5:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*         TAMBAH MENU SUATU RUMAH MAKAN            * \n"
                     << "==================================================== \n";
                cout << endl;

                cout << "    List Id Rumah Makan : "; printIdRumahMakan(L1);
                cout << endl;
                TambahMenuSuatuRumahMakan(L1,x2);
                getch();
                break;

            case 6:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*          HAPUS MENU SUATU RUMAH MAKAN            * \n"
                     << "==================================================== \n";
                cout << endl;

                cout << "    List Id Rumah Makan : "; printIdRumahMakan(L1);
                cout << endl;
                hapusMenuRumahMakan(L1);
                getch();
                break;

            case 7:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*         HAPUS RUMAH MAKAN BESERTA MENU           * \n"
                     << "==================================================== \n";
                cout << endl;

                cout << "    List Id Rumah Makan : "; printIdRumahMakan(L1);
                cout << endl;
                hapusRumahMakan(L1);
                getch();
                break;

            case 8:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*        LIHAT LIST MENU SUATU RUMAH MAKAN         * \n"
                     << "==================================================== \n";
                cout << endl;

                cout << "    List Id Rumah Makan : "; printIdRumahMakan(L1);
                cout << endl;
                lihatMenuRumahMakan(L1);
                getch();
                break;


            case 9:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*               LIHAT LIST RUMAH MAKAN             * \n"
                     << "==================================================== \n";
                cout << endl;

                printinfo(L1);
                getch();
                break;

            case 10:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*              SORT RUMAH MAKAN BY ID              * \n"
                     << "==================================================== \n";
                cout << endl;

                if (first(L1)==nil){
                    cout << endl;
                    cout << "    LIST MASIH KOSONG \n";
                }
                else{
                    char Sort;
                    Sort='W';

                    while (Sort!='Y' && Sort !='N'){
                        cout << "    Sort Rumah Makan By Id ? Y/N : ";
                        cin >> Sort;
                    }

                    if (Sort=='Y'){
                        sortRumahMakanById(L1);
                        cout << "    SORT RUMAH MAKAN BERHASIL ! \n";
                        cout << endl;
                        printinfo(L1);
                    }
                }

                getch();
                break;

            case 11:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*         MENU FAVORIT SUATU RUMAH MAKAN           * \n"
                     << "==================================================== \n";
                cout << endl;

                cout << "    List Id Rumah Makan : "; printIdRumahMakan(L1);
                cout << endl;

                cout << "    Masukkan Id Rumah Makan : ";
                getline(cin,cari1.id);

                p=CariRumahMakan(L1,cari1);
                cout << endl;
                if (p==nil){
                    cout << "    RUMAH MAKAN TIDAK ADA \n";
                }
                else{
                    cout << "    RUMAH MAKAN DITEMUKAN ! \n \n";

                    q=menuFavorit(L1,p);
                    if (q==nil){
                        cout << "   MENU KOSONG \n";
                    }
                    else{
                        cout << "    Menu Favorit : " << info(q).nama <<endl;
                        cout << "    Terjual      : " << info(q).terjual << endl << endl;
                    }
                }
                getch();
                break;

            case 12:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*          KEUNTUNGAN SUATU RUMAH MAKAN            * \n"
                     << "==================================================== \n";
                cout << endl;

                cout << "    List Id Rumah Makan : "; printIdRumahMakan(L1);
                cout << endl;

                cout << "    Masukkan Id Rumah Makan : ";
                getline(cin,cari1.id);

                p=CariRumahMakan(L1,cari1);

                cout << endl;
                if (p==nil){
                    cout << "    RUMAH MAKAN TIDAK ADA \n";
                }
                else{
                    int x;
                    x=profitRumahMakan(L1,p);
                    cout << "    Keuntungan Rumah Makan " << info(p).nama << " adalah " << x;
                }

                getch();
                break;

            case 13:
                system("cls");
                cout << endl;
                cout << "==================================================== \n"
                     << "*                  MENU TERBANYAK                  * \n"
                     << "==================================================== \n";
                cout << endl;

                if (first(L1)==nil){
                    cout << "    RUMAH MAKAN TIDAK ADA \n";
                }
                else{
                    p=first(L1);
                    int x=MenuTerbanyak(L1,p);
                    if (x==0){
                        cout << "    MENU TIDAK ADA \n";
                    }
                    else{
                        cout << "    Rumah Makan " << info(p).nama << " Memiliki Menu " << endl;
                        cout << "    Terbanyak, yaitu " << x << " Buah Menu";
                    }
                }

                getch();
                break;

            case 14:
                lagi='N';
                break;

            default:
                lagi='Y';

        }
    }

    getch();
    return 0;
}