Exemplo n.º 1
0
Arquivo: asm.c Projeto: drcz/drczlang
int main(int ac,char **av) {
  int mempoolsize=1024*1024;
  SE *code;
  int c;

  if(ac>1) {
    while((c=getopt(ac,av,"vh?p:"))!=-1) {
      switch(c) {
      case 'v': versioninfo(stdout,av[0]); return 0;
      case '?': case 'h': versioninfo(stdout,av[0]); helpinfo(stdout,av[0]); return 0;
      case 'p':	mempoolsize=atoi(optarg); break;
      default: helpinfo(stdout,av[0]); return 1;
      }
    }
  }

  init_mempool(mempoolsize);
  init_symbols_list();
  gather_symbols((code=read_se(stdin)));
  assemble(code,stdout,1);
  printf("\n");
  return 0;
}
Exemplo n.º 2
0
int main(int argc, char* argv[])
{
    long size;
    char *filedata;
    term_size terminal;
    ModPlugFile *f2;
    int mlen;
    struct timeval tvstart;
    struct timeval tv;
    struct timeval tvpause, tvunpause;
    struct timeval tvptotal;
    char status[161];
    char songname[41];
    char notpaus[4];

    int loop=0; // kontest
    
    int songsplayed = 0;

    int nFiles = 0, fnOffset[100];
    int i;

    ModPlug_Settings settings;
    ModPlug_GetSettings(&settings);

    ao_device *device;
    ao_sample_format format = {0};
    int default_driver;
    
    ao_initialize();
    default_driver = ao_default_driver_id();

    for (i=1; i<argc; i++) {
     /* check if arguments need to be parsed */
     if (argv[i][0] == '-') {
      if (strstr(argv[i],"-h")) {
        printf("\n");
        help(argv[0],0);
      } else if (strstr(argv[i],"-v")) {
	versioninfo();
        exit(0);
      } else if (strstr(argv[i],"-l")) {
        loop=1;
        continue;
      } else if (strstr(argv[i],"-ao")) {
        default_driver = ao_driver_id(argv[++i]);
        continue;
      }
      if (argv[i][1] == '-') { // not a song
        if (strstr(argv[i],"--help")) {
          help(argv[0],0);
        } else if (strstr(argv[i],"--version")) {
	  versioninfo();
	  exit(0);
	}
        continue;
       }
      }
      /* "valid" filename - store it */
      fnOffset[nFiles++] = i;
    }

    format.bits = 16;
    format.channels = 2;
    format.rate = 44100;
    format.byte_format = AO_FMT_LITTLE;
//	printf("Default driver = %i\n", default_driver);

    char buffer[128];
    int result, nread;
    struct pollfd pollfds;
    int timeout = 1;            /* Timeout in msec. */
    int pause=0;
    int mono=0;
    int bits=0;
    int song;

    // [rev--dly--] [sur--dly--] [bas--rng--]
    int rev=0;    // a
    int revdly=0; // s
    int sur=0;    // d
    int surdly=0; // y
    int bas=0;    // x
    int basrng=0; // c

    /* Initialize pollfds; we're looking at input, stdin */
    pollfds.fd = 0;             /* stdin */
    pollfds.events = POLLIN;    /* Wait for input */

    if (argc==1) {
	help(argv[0],1);
    }

    if (!get_term_size(STDIN_FILENO,&terminal)) {
	fprintf(stderr,"warning: failed to get terminal size\n");
    }
    
    srand(time(NULL));

for (song=0; song<nFiles; song++) {

    char *filename = argv[fnOffset[song]];

/* -- Open driver -- */
    if (default_driver == ao_driver_id("wav")) {
        device = ao_open_file(default_driver, "output.wav", 1, &format, NULL /*no options*/);
    } else {
        device = ao_open_live(default_driver, &format, NULL /* no options */);
    }
    if (device == NULL) {
 	fprintf(stderr, "Error opening device. (%s)\n", filename);
	fprintf(stderr, "ERROR: %i\n", errno);
        return 1;
    }
    printf("%s ",filename);
    printf("[%d/%d]",song+1,nFiles);

    filedata = getFileData(filename, &size);
    if (filedata == NULL) continue;
    printf(" [%ld]\n",size);

    // Note: All "Basic Settings" must be set before ModPlug_Load.
    settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; /* RESAMP */
    settings.mChannels = 2;
    settings.mBits = 16;
    settings.mFrequency = 44100;
    settings.mStereoSeparation = 128;
    settings.mMaxMixChannels = 256;
    /* insert more setting changes here */
    ModPlug_SetSettings(&settings);

    f2 = ModPlug_Load(filedata, size);
    if (!f2) {
	printf("could not load %s\n", filename);
	close(audio_fd);
	free(filedata); /* ? */
    } else {
      songsplayed++;
/*    settings.mFlags=MODPLUG_ENABLE_OVERSAMPLING | \
                    MODPLUG_ENABLE_NOISE_REDUCTION | \
		    MODPLUG_ENABLE_REVERB | \
		    MODPLUG_ENABLE_MEGABASS | \
		    MODPLUG_ENABLE_SURROUND;*/

//    settings.mReverbDepth = 100; /* 0 - 100 */ *   [REV--DLY--]
//    settings.mReverbDelay = 200; /* 40 - 200 ms  00-FF */ 
//    settings.mSurroundDepth = 100; /* 0 - 100 */   [SUR--DLY--]
//    settings.mSurroundDelay = 40; /* 5 - 40 ms */  
//    settings.mBassAmount  = 100; /* 0 - 100 */     [BAS--RNG--]
//    settings.mBassRange   = 100; /* 10 - 100 hz */ 
// [REV--DLY--] [SUR--DLY--] [BAS--RNG--]
// [rev--dly--] [sur--dly--] [bas--rng--]


    set_keypress();
    strcpy(songname, ModPlug_GetName(f2));

    /* if no modplug "name" - use last 41 characters of filename */
    if (strlen(songname)==0) {
        int l = strlen(filename);
	char *st = filename;
        if (l >= 41) st = filename + l - 41;
        strncpy(songname,st,41);
        songname[40] = 0;
    }
    sprintf(status,"playing %s (%%d.%%d/%d\") (%%d/%%d/%%d)    \b\b\b\b",songname,ModPlug_GetLength(f2)/1000);
    if (loop) sprintf(status,"looping %s (%%d.%%d/%d\") (%%d/%%d/%%d)    \b\b\b\b",songname,ModPlug_GetLength(f2)/1000);

    gettimeofday(&tvstart,NULL);
    tvptotal.tv_sec=tvptotal.tv_usec=0;
    mlen=1;
    
    while(mlen!=0) {
	if (mlen==0) { break; }

	if (!pause) {
	    gettimeofday(&tv,NULL);
	    mlen = ModPlug_Read(f2,audio_buffer,BUF_SIZE);
            if (mlen > 0 && ao_play(device, audio_buffer, mlen) == 0) {
		perror("audio write");
		exit(1);
    	    }
        }
        printf(status,tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec,tv.tv_usec/100000,format.rate,format.channels,settings.mBits/*,rev,revdly,sur,surdly,bas,basrng*/);
	fflush(stdout);

	if ((mlen==0) && (loop==1)) {
	    /*printf("LOOPING NOW\n");*/
	    ModPlug_Seek(f2,0);
	    gettimeofday(&tvstart,NULL);
	    mlen=ModPlug_Read(f2,audio_buffer,BUF_SIZE);
	    tvptotal.tv_sec=tvptotal.tv_usec=0;
	}

        result = poll(&pollfds, 1, timeout);
        switch (result) {
        case 0:
            /*printf(".");*/
            break;
        case -1:
            perror("select");
            exit(1);

        default:
            if (pollfds.revents && POLLIN) {
	        nread = read(0, buffer, 1); /* s/nread/1/2 */
                if (nread == 0) {
                    printf("keyboard done\n");
                    exit(0);
               } else {
                    buffer[nread] = 0;
                    /* printf("%s", buffer); */

		    if (buffer[0]=='q') { mlen=0; song=nFiles;  } /* quit */

		    if (buffer[0]=='f') {
			if ((tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec+10) < (ModPlug_GetLength(f2)/1000)) {
			    ModPlug_Seek(f2,(tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec)*1000+10000);
			    tvstart.tv_sec-=10;
			}
		    } /* forward 10" */

		    if (buffer[0]=='b') {
			if ((tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec-10) > 0) {
			    ModPlug_Seek(f2,(tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec)*1000-10000);
			    tvstart.tv_sec+=10;
			}
		    } /* backward 10" */
		    
		    /*
		    if (buffer[0]=='i') {
			printf("\n");
		    } */

/*
		    if (buffer[0]=='a') {
			rev++; settings.mReverbDepth=rev;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='A') {
			rev--; settings.mReverbDepth=rev;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='s') {
			revdly++; settings.mReverbDelay=revdly;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='S') {
			revdly--; settings.mReverbDelay=revdly;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='d') {
			sur++; settings.mSurroundDepth=sur;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='D') {
			sur--; settings.mSurroundDepth=sur;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='y') {
			surdly++; settings.mSurroundDelay=surdly;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='Y') {
			surdly--; settings.mSurroundDelay=surdly;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='x') {
			bas++; settings.mBassAmount=bas;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='X') {
			bas--; settings.mBassAmount=bas;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='c') {
			basrng++; settings.mBassRange=basrng;
			ModPlug_SetSettings(&settings);
		    }
		    if (buffer[0]=='C') {
			basrng--; settings.mBassRange=basrng;
			ModPlug_SetSettings(&settings);
		    }
*/
		    
		    if (buffer[0]=='n') {
			if (song<argc) { mlen=0; pause=0; }
		    }

		    if (buffer[0]=='N') {
			if (song>1) { song-=2; mlen=0; pause=0; }
		    }
		    
		    if (buffer[0]=='r') {
			song=(int) ((float)(argc-1)*rand()/(RAND_MAX+1.0));
			mlen=0; pause=0;
//			ioctl(audio_fd,SNDCTL_DSP_RESET,0);
			/* printf("\n[%d?]\n",song+1); */
		    }
		    
		    /*if (buffer[0]=='R') {
			song=(int) ((float)(argc-1)*rand()/(RAND_MAX+1.0));
			mlen=0; pause=0;
		    }*/
		    
/*		    if (buffer[0]=='m') {
			// mono/stereo 
			mono^=1;
			if (mono) format.channels=1; else format.channels=2;
			ioctl(audio_fd,SNDCTL_DSP_RESET,0);
			if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
			    perror("SNDCTL_DSP_CHANNELS");
			    exit(1);
			}
			if (mono) settings.mChannels=1; else settings.mChannels=2;
			ModPlug_SetSettings(&settings);
			f2=ModPlug_Load(d,size);
			ModPlug_Seek(f2,(tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec)*1000+10000);
		    }
		    */
		    if (buffer[0]=='l') {
			loop^=1;
			if (loop) {
			    memcpy(status+4,"loop",4);
			} else {
			    memcpy(status+4,"play",4);
			}
		    } /* loop */
		    
		    if (buffer[0]=='p') {
			pause^=1;
			if (pause) {
			    gettimeofday(&tvpause,NULL);
			    memcpy(notpaus,status+4,4);
			    memcpy(status+4,"paus",4);
			} else {
			    gettimeofday(&tvunpause,NULL);
			    memcpy(status+4,notpaus,4);
			    tvptotal.tv_sec+=tvunpause.tv_sec-tvpause.tv_sec;
			    tvptotal.tv_usec+=tvunpause.tv_usec-tvpause.tv_usec;
			    /* printf(status,tv.tv_sec-tvstart.tv_sec,tv.tv_usec/100000); */
			}
		    } /* pause */
                }
            }
        }
    }
    printf("\n");

    reset_keypress();
    ModPlug_Unload(f2);
    ao_close(device);
    fprintf(stderr, "Closing audio device.\n");
    free(filedata);
    } /* valid module */
    
} /* for */
    ao_shutdown();

    return 0;
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: drcz/drczlang
int main(int ac, char **av) {
  FILE *codefile=stdin;
  int  mempoolsize=1024*1024;
  int c;
  SE *prog,*result;

  silent=0;

  if(ac<2) {
    versioninfo(stderr,av[0]);
    helpinfo(stderr,av[0]);
    return 1;
  }

  while((c=getopt(ac,av,"svch?p:"))!=-1) {
    switch(c) {

    case 's':
      silent=1;
      break;

    case 'c':
      conscellinfo(stdout,av[0]);
      return 0;

    case 'v':
      versioninfo(stdout,av[0]);
      return 0;

    case '?':
    case 'h':
      versioninfo(stdout,av[0]);
      helpinfo(stdout,av[0]);
      return 0;

    case 'p':
      mempoolsize=atoi(optarg);
      break;

    default:      
      // versioninfo(stderr,av[0]);
      // helpinfo(stdout,av[0]);
      return 1;      
    }
  }

  if((codefile=fopen(av[optind],"r"))) {
    if(silent!=1) printf("Initializing mempool (%d cells)...\n",mempoolsize);
    init_mempool(mempoolsize);

    if(silent!=1) printf("Loading code from %s...\n",av[optind]);
    prog=read_se(codefile);

    if(silent!=1) printf("Allocating %d env-slot(s) for environments...\n",numval(car(prog)));
    Dreg=(SE **)malloc(sizeof(SE *)*numval(car(prog)));

    Rreg=NIL;
    Creg=NIL;

    C_push(cdr(prog));

    if(silent!=1) printf("Running the machine.\n");
    result=run();

    if(silent!=1) printf("Result: ");
    write_se(result,stdout);
    printf("\n"); // ?

    if(silent!=1) printf("\nAuf wiedersehen!\n");
    return 0;

  } else fprintf(stderr,"Could not open file %s.\n",av[optind]);

  return 1;
}
Exemplo n.º 4
0
/*
* Comand line arguments parsing
*/
int optparse(struct _config *config, char argc, char ** argv, char ** envp)
{
	int	option_index = 0;
	char	optac;
	int	longopt, rc = 0;

	struct option long_options[] = {
		{"version",0,&longopt,1},
		{"config",1,0,'c'},
		{"no-daemon",0,0,'n'},
		{"verbose",0,0,'v'},
		{"help",0,0,'h'},
		{"pid",1,0,'f'},
		{"key",1,0,'k'},
		{"pwd",1,0,'w'},
		{"port",1,0,'p'},
		{"dsslport",1,0,'D'},
		{"ip",1,0,'i'},
		{"src-interface",1,0,'s'},
		{"dst-interface",1,0,'d'},
		{0,0,0,0}
	};

	while ((optac = getopt_long (argc,argv,"vnhw:f:k:s:d:p:D:i:c::",long_options,&option_index)) != -1)
		switch (optac)
		{
			case 'c':
				if (optarg == NULL)
					strcpy(config->config, DEFAULT_CONFIG_FILE);
				else
					strcpy(config->config, optarg);

				if (load_config(config->config, config) == -1)
				{
					fprintf(stderr,"ERROR: Can't load config file \"%s\".", config->config);
					return(-1);
				}
				break;
			case 'v':
				config->loglevel = 1;
				break;
			case 'n':
				config->daemon = 0;
				break;
			case 'h':
				usage();
				return(1);
				break;
			case 'f':
				strcpy(config->pidfilename, optarg);
				break;
			case 0:
				if (longopt == 1)
				{
					versioninfo();
					exit(EXIT_SUCCESS);
				}
				longopt = 0;
				break;
			default:
			
				if (!config->cmdl)
				{
					usage();
					return(-1);
				}
				
				if (config->index == 0)
				{
					config->cap[0] = malloc(sizeof(struct _cap));
					memset(config->cap[0],0,sizeof(struct _cap));
					config->index=1;
				}
				
				switch (optac)
				{
					case 'k':
						strcpy(config->cap[0]->keyfile, optarg);
						break;
					case 'w':
						strcpy(config->cap[0]->pwd, optarg);
						break;
					case 's':
						if (getmac(optarg, config->cap[0]->src_interface_mac) != -1)
						{
							strcpy(config->cap[0]->src_interface, optarg);
						} else
						{
							fprintf(stderr,"ERROR: %s fetching interface information error: " \
							"Device not found.\n", optarg);
							return(-1);
						}
						break;
					case 'd':
						if (getmac(optarg, config->cap[0]->dst_interface_mac) != -1)
							strcpy(config->cap[0]->dst_interface, optarg);
						else
						{
							fprintf(stderr, "ERROR: %s fetching interface information error: " \
							"Device not found.\n", optarg);
							return(-1);
						}
						break;
					case 'p':
						config->cap[0]->port = (uint16_t) atoi(optarg);
						if (config->cap[0]->port == 0) // it will always < 65535 due to limited range of data type
						{ 
							fprintf(stderr, "Invalid TCP port value \"%d\".\n", \
							config->cap[0]->port);
							return(-1);
						}
						break;
					 case 'D':
                                                config->cap[0]->dsslport = (uint16_t) atoi(optarg);
                                                if (config->cap[0]->dsslport == 0) // it will always < 65535 due to limited range of data type
                                                {
                                                        fprintf(stderr, "Invalid DSSL TCP port value \"%d\".\n", \
                                                        config->cap[0]->dsslport);
                                                        return(-1);
                                                }
                                                break;
					case 'i':
						if (inet_aton(optarg, &config->cap[0]->server_ip) == 0)
						{
							fprintf(stderr, "Invalid IP address format \"%s\".\n", optarg);
							return(-1);
						}
						break;
					default:
						usage();
						return(-1);
				}
				

			break;
		}
		return(0);
}