int main(){ set_keypress(); pthread_create(&ntid,NULL,thr_fn1,NULL); pthread_create(&ntid,NULL,thr_fn2,NULL); sleep(2000); return 0; }
/********************************************************************************* * 语法格式: char *get_cmd(char *buf) * 实现功能: 把键盘上获取的命令储存到buf * 入口参数: char *buf * 出口参数: char *buf *********************************************************************************/ char *get_cmd(char *buf) { int len = 0; int i = 0; char tmp_buf[CMD_SIZE] = {""}; char ch; TYPE *p = head; set_keypress(); while(1) { ch = getchar(); if(ch == 27) { getchar(); if((ch = getchar()) == 65 || ch == 66) { if(ch == 65) //key up and get his_cmd { len = strlen(tmp_buf); memset(tmp_buf, 0, CMD_SIZE); strcpy(tmp_buf, p->his_cmd); //up tmp_buf[strlen(tmp_buf) - 1] = '\0'; if(p->next_b != head) //stop { p = p->next_b; } printf("\r[%s@localhost %s]$ ", getlogin(), my_dir_cu); for(i = 0; i < len; i++) //AAAAAAAAAAA { printf(" "); //erasure line memory } printf("\r[%s@localhost %s]$ %s", getlogin(), my_dir_cu, tmp_buf); fflush(stdout); } else if(ch == 66) //key down and get his_cmd { len = strlen(tmp_buf); memset(tmp_buf, 0, CMD_SIZE); if(p == head) { printf("\a"); } //if(p != head) //stop else { p = p->next_f; strcpy(tmp_buf, p->his_cmd); //down tmp_buf[strlen(tmp_buf) - 1] = '\0'; } printf("\r[%s@localhost %s]$ ", getlogin(), my_dir_cu); for(i = 0; i < len; i++) { printf(" "); //erasure line memory } printf("\r[%s@localhost %s]$ %s", getlogin(), my_dir_cu, tmp_buf); fflush(stdout); } } } else if(ch == 127) //key backspace { len = strlen(tmp_buf); if(len == 0) { printf("\a"); } //if(len != 0) else { tmp_buf[len - 1] = '\0'; //erasure single character len--; printf("\r[%s@localhost %s]$ ", getlogin(), my_dir_cu); for(i = 0; i < (len + 1); i++) { printf(" "); //erasure line memory } printf("\r[%s@localhost %s]$ %s", getlogin(), my_dir_cu, tmp_buf); fflush(stdout); } } else if(ch == 10) { strcat(tmp_buf, "\n"); // strcpy(buf, tmp_buf); //get cmd_buf printf("\n"); //necessary importantAAAAAAAAAA reset_keypress(); // break; } else { len = strlen(tmp_buf); printf("%c", ch); tmp_buf[len] = ch; len++; } } return buf; }
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,"[1Gplaying %s (%%d.%%d/%d\") (%%d/%%d/%%d) \b\b\b\b",songname,ModPlug_GetLength(f2)/1000); if (loop) sprintf(status,"[1Glooping %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; }
int main(int argc, char *argv[]) { int i, t = 0; uint32 done = 0; char ch, benchmark = 0, noinput = 0; hd_engine *engine; circle_object obj[6]; for (i = 1; i < argc; i++) { if (*argv[i] == '-') { if (strcmp("benchmark", argv[i]+1) == 0) benchmark = 1; if (strcmp("noinput", argv[i]+1) == 0) noinput = 1; } } noinput = noinput && benchmark; #ifndef IPOD if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr,"Unable to init SDL: %s\n",SDL_GetError()); exit(1); } atexit(SDL_Quit); screen = SDL_SetVideoMode(WIDTH, HEIGHT,16,SDL_SWSURFACE); if (screen == NULL) { fprintf(stderr,"Unable to init SDL video: %s\n",SDL_GetError()); exit(1); } engine = HD_Initialize (WIDTH, HEIGHT, 16, screen->pixels, update); #define IMGPREFIX "" #else HD_LCD_Init(); HD_LCD_GetInfo (0, &WIDTH, &HEIGHT, 0); screen = xmalloc (WIDTH * HEIGHT * 2); engine = HD_Initialize (WIDTH, HEIGHT, 16, screen, update); #define IMGPREFIX "" #endif obj[4].object = HD_PNG_Create (IMGPREFIX "bg.png"); obj[4].object->x = 0; obj[4].object->y = 0; obj[4].object->w = WIDTH; obj[4].object->h = HEIGHT; obj[0].object = HD_PNG_Create (IMGPREFIX "photos.png"); obj[0].object->x = 0; obj[0].object->y = 0; obj[0].object->w = 75 * WIDTH / 220; obj[0].object->h = 150 * WIDTH / 220; obj[1].object = HD_PNG_Create (IMGPREFIX "music.png"); obj[1].object->x = 0; obj[1].object->y = 0; obj[1].object->w = 75 * WIDTH / 220; obj[1].object->h = 150 * WIDTH / 220; obj[2].object = HD_PNG_Create (IMGPREFIX "dvd.png"); obj[2].object->x = 0; obj[2].object->y = 0; obj[2].object->w = 75 * WIDTH / 220; obj[2].object->h = 150 * WIDTH / 220; obj[3].object = HD_PNG_Create (IMGPREFIX "movies.png"); obj[3].object->x = 0; obj[3].object->y = 0; obj[3].object->w = 75 * WIDTH / 220; obj[3].object->h = 150 * WIDTH / 220; obj[5].object = HD_Canvas_Create (100, 100); obj[5].object->x = 100; obj[5].object->y = 100; HD_Register(engine,obj[4].object); HD_Register(engine,obj[0].object); HD_Register(engine,obj[1].object); HD_Register(engine,obj[2].object); HD_Register(engine,obj[3].object); if (obj[5].object) HD_Register(engine,obj[5].object); obj[0].position = 0; obj[1].position = 1024; obj[2].position = 2048; obj[3].position = 3072; object_topwid = ((50 * WIDTH / 220) << 16) / obj[0].object->w; object_bottomwid = ((70 * WIDTH / 220) << 16) / obj[0].object->w; if (benchmark) { HD_AnimateCircle(obj[0].object, 80 * WIDTH / 220, 50 * HEIGHT / 176, 50 * HEIGHT / 176, object_topwid, object_bottomwid, obj[0].position, 4096, -100); HD_AnimateCircle(obj[1].object, 80 * WIDTH / 220, 50 * HEIGHT / 176, 50 * HEIGHT / 176, object_topwid, object_bottomwid, obj[1].position, 4096, -100); HD_AnimateCircle(obj[2].object, 80 * WIDTH / 220, 50 * HEIGHT / 176, 50 * HEIGHT / 176, object_topwid, object_bottomwid, obj[2].position, 4096, -100); HD_AnimateCircle(obj[3].object, 80 * WIDTH / 220, 50 * HEIGHT / 176, 50 * HEIGHT / 176, object_topwid, object_bottomwid, obj[3].position, 4096, -100); } else { circle_rotate(&obj[0], 1); circle_rotate(&obj[1], 1); circle_rotate(&obj[2], 1); circle_rotate(&obj[3], 1); } #ifdef IPOD uint32 srtc = *(volatile uint32 *)0x60005010; set_keypress(); fd_set rd; struct timeval tv; int n; #endif while(!done) { if (!benchmark && (ch = check_pending()) && !obj[0].object->animating) { circle_rotate(&obj[0], ch); circle_rotate(&obj[1], ch); circle_rotate(&obj[2], ch); circle_rotate(&obj[3], ch); } #ifndef IPOD SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_SPACE: case SDLK_BACKSPACE: case SDLK_DOWN: case SDLK_UP: break; case SDLK_RIGHT: if (benchmark) break; if (obj[0].object->animating) { add_pending(1); break; } circle_rotate(&obj[0], 1); circle_rotate(&obj[1], 1); circle_rotate(&obj[2], 1); circle_rotate(&obj[3], 1); break; case SDLK_LEFT: if (benchmark) break; if (obj[0].object->animating) { add_pending(-1); break; } circle_rotate(&obj[0], -1); circle_rotate(&obj[1], -1); circle_rotate(&obj[2], -1); circle_rotate(&obj[3], -1); break; case SDLK_ESCAPE: done = 1; break; default: break; } break; case SDL_QUIT: return(0); break; default: break; } } SDL_Delay (30); #else #define SCROLL_MOD_NUM 24 // 100/25 - 1 #define SCROLL_MOD(n) \ ({ \ static int sofar = 0; \ int use = 0; \ if (++sofar >= n) { \ sofar -= n; \ use = 1; \ } \ (use == 1); \ }) if (!noinput) { FD_ZERO(&rd); FD_SET(0, &rd); tv.tv_sec = 0; tv.tv_usec = 100; n = select(0+1, &rd, NULL, NULL, &tv); if (FD_ISSET(0, &rd) && (n > 0)) { read(0, &ch, 1); switch(ch) { case 'm': done = 1; break; case 'r': if (SCROLL_MOD(SCROLL_MOD_NUM)) { if (benchmark) break; if (obj[0].object->animating) { add_pending(1); break; } circle_rotate(&obj[0], 1); circle_rotate(&obj[1], 1); circle_rotate(&obj[2], 1); circle_rotate(&obj[3], 1); } break; case 'l': if (SCROLL_MOD(SCROLL_MOD_NUM)) { if (benchmark) break; if (obj[0].object->animating) { add_pending(-1); break; } circle_rotate(&obj[0], -1); circle_rotate(&obj[1], -1); circle_rotate(&obj[2], -1); circle_rotate(&obj[3], -1); } break; case 'w': case 'f': case 'd': default: break; } } } #endif t++; if (benchmark && t > 200) done = 1; HD_Animate (engine); #ifndef IPOD if( SDL_MUSTLOCK(screen) ) SDL_LockSurface(screen); #endif HD_Render(engine); #ifndef IPOD if( SDL_MUSTLOCK(screen) ) SDL_UnlockSurface(screen); #endif } #ifdef IPOD HD_LCD_Quit(); uint32 ertc = *(volatile uint32 *)0x60005010; printf ("%d frames in %d microseconds = %d.%02d frames/sec\n", t, ertc - srtc, 1000000 * t / (ertc - srtc), (1000000 * t / ((ertc - srtc) / 100)) % 100); sleep (5); reset_keypress(); #endif HD_Deinitialize(engine); return(0); }
int print_range(int f, int l) { int a = f,b= l, height, widht, i, j, k, count_strochek, tmp; char c = 0; struct MyString *tmp_string, *tmp2string; struct MySymbol *tmp_symbol; if (is_redirected == 1) { write_Strings(stdout); return 0; } clear_terminal(); if (my_strings_start == NULL) { set_keypress(); while (1) { c = getchar(); if (c == 'q') { reset_keypress(); system("setterm -cursor on"); putchar('\n'); return 0; } } } tmp_string = my_strings_start; ioctl(0, TIOCGWINSZ, &terminal); height = terminal.ws_row-1; widht = terminal.ws_col; /*height = 5;*/ if (f > N) return -3; if (f == -1) a = 1; if ((l == -1) || (l > N)) b = N; for (i = 0; i < a-1; i++) {tmp_string = tmp_string->next_string;} if (is_wrap == 0) { tmp = N; N = b-a+1; tmp2string = my_strings_start; my_strings_start = tmp_string; j = 1; a = 1; if(update_buffer(a)!= 0) { free_buffer(); return exit_force(); } while (1) { print_buffer(j); set_keypress(); while (1) { c = getchar(); if (c == 'q') { reset_keypress(); printf("\n"); free_buffer(); N = tmp; my_strings_start = tmp2string; return 0; } if (c == '>') { reset_keypress(); clear_terminal(); j++; break; } if ((c == '<') && (j >= 2)) { reset_keypress(); clear_terminal(); j--; break; } if ((c == ' ') && (a + height <= N)) { reset_keypress(); clear_terminal(); a = a + height; free_buffer(); if(update_buffer(a)!= 0) { free_buffer(); return exit_force(); } break; } } } } else { height -= 2; system("setterm -cursor off"); i = a; count_strochek = 1; while (i <= b) { tmp_symbol = tmp_string->first_symbol; putchar('@'); j = 1; while (tmp_symbol != NULL) { if ((j == widht) && (tmp_symbol->next_symbol != NULL)) { putchar('\n'); count_strochek++; if (count_strochek > height) { set_keypress(); while (1) { c = getchar(); if (c == 'q') { reset_keypress(); system("setterm -cursor on"); printf("\n"); return 0; } if (c == ' ') { count_strochek = 1; reset_keypress(); clear_terminal(); break; } } } j = 0; } if (tmp_symbol->symbol == '\t') { for (k = 0; k < count_ofspaces_intabulation; k++) { if (j == widht) { putchar('\n'); count_strochek++; if (count_strochek > height) { set_keypress(); while (1) { c = getchar(); if (c == 'q') { reset_keypress(); system("setterm -cursor on"); putchar('\n'); return 0; } if (c == ' ') { count_strochek = 1; reset_keypress(); clear_terminal(); break; } } } j = 0; } putchar(' '); j++; } } else putchar(tmp_symbol->symbol); j++; tmp_symbol = tmp_symbol->next_symbol; } i++; count_strochek++; if (count_strochek > height) { set_keypress(); while (1) { c = getchar(); if (c == 'q') { reset_keypress(); system("setterm -cursor on"); printf("\n"); return 0; } if (c == ' ') { count_strochek = 1; reset_keypress(); clear_terminal(); tmp_string = tmp_string->next_string; break; } } continue; } tmp_string = tmp_string->next_string; putchar('\n'); } set_keypress(); while (1) { c = getchar(); if (c == 'q') { reset_keypress(); printf("\n"); break; } } } system("setterm -cursor on"); return 0; }
int main( int argc, char* argv[] ) { /* char getprm = 0, isfile = 0;*/ int i; char command = 0, argument = -1; char file[256], file2[256], Error[256], *s; #ifdef __unix__ set_keypress(); #endif file[0] = 0; file2[0] = 0; ReturnVideoInfo = TEXTVER_ReturnVideoInfo; check_event = TEXTVER_check_event; Debug = TEXTVER_Debug; eol = TEXTVER_eol; QU_getline = TEXTVER_getline; putline = TEXTVER_putline; if( argc > 1 ) { if( strcmp( argv[1], "-z" ) == 0 ) { command = 1; /* calc a ZBuffer */ } else if( strcmp( argv[1], "-i" ) == 0 ) { command = 2; /* calc an image */ } else if( strcmp( argv[1], "-p" ) == 0 ) { command = 3; /* write parameters */ } else if( strcmp( argv[1], "-c" ) == 0 ) { command = 4; /* continue calculation */ } else if( strcmp( argv[1], "-h" ) == 0 ) { command = 5; /* help */ } } if( argc > 2 ) { strcpy( file, argv[2] ); if( strrchr( file, '.' ) ) { for( i = 0; i < strlen( file ); i++ ) { file[i] = tolower( ( int )file[i] ); } if( strcmp( strrchr( file, '.' ), ".ini" ) == 0 ) { argument = 1; /* ini file */ } else if( strcmp( strrchr( file, '.' ), ".png" ) == 0 ) { argument = 2; /* png file */ } else if( strcmp( strrchr( file, '.' ), ".zpn" ) == 0 ) { argument = 3; /* zpn file */ } else if( file[0] == 0 ) { argument = 0; } strcpy( file, argv[2] ); } } if( argc > 3 ) { strcpy( file2, argv[3] ); } switch( command ) { case 1: if( argument == 0 ) { printf( "You didn´t specify an ini-file.\nUse -h for help.\n" ); endprg(); return( -1 ); } if( argument != 1 ) { printf( "The file you specified has not the suffix '.ini', but it will be assumed to\n" ); printf( "be an ini file.\n" ); } ParseAndCalculate( file, Error, 1 ); break; case 2: if( argument == 1 ) { ParseAndCalculate( file, Error, 0 ); } else if( argument == 3 ) { ImgFromZBuf( file, file2, Error ); } else { printf( "You didn´t specify an ini- or zpn-file.\nUse -h for help.\n" ); endprg(); return( -1 ); } break; case 3: if( argument == 0 ) { printf( "No file given. Use -h for help.\n" ); endprg(); return( -1 ); } GetParameters( file, Error ); break; case 4: if( argument != 2 && argument != 3 ) { printf( "Given file is neither png nor zpn.\n" ); endprg(); return( -1 ); } if( argument == 2 ) { ParseAndCalculate( file, Error, 0 ); } if( argument == 3 ) { ParseAndCalculate( file, Error, 1 ); } break; case 5: strncpy( file, argv[0], 256 ); s = strrchr( file, '/' ); if( s == NULL ) { s = strrchr( file, '\\' ); } if( s == NULL ) { s = ( char* )&file[0]; } else { s++; } printf( "\n%s %s%s%s\n%s", PROGNAME, PROGVERSION, PROGSUBVERSION, PROGSTATE, "A 3d fractal generation program\n" ); printf( "Copyright (C) 1997-2002 Dirk Meyer\n" ); printf( "email: [email protected]\n" ); printf( "WWW: http://www.physcip.uni-stuttgart.de/phy11733/index_e.html\n" ); printf( "Mailing-List: http://groups.yahoo.com/group/quat/\n" ); printf( "\nThis program is distributed under the terms of the\n" ); printf( "GNU General Public License Version 2 (See file 'COPYING' for details)\n\n" ); printf( "-z <ini-file> begin calculation of a ZBuffer\n" ); printf( "-i [<ini-file> | <zpn-file> [& <ini-file>]]\n" ); printf( " begin calculation of an image [using an ini-file | a\n" ); printf( " ZBuffer [& replacing parameters from ini-file]]\n" ); printf( "-p <png- or zpn-file> read fractal parameters from image or ZBuffer and\n" ); printf( " write them to raw data (ini)\n" ); printf( "-c <png- or zpn-file> continue calculation of image or ZBuffer\n" ); printf( "-h Show help text\n" ); endprg(); return( 0 ); default: printf( "Didn't understand the given parameters. For help use -h\n" ); endprg(); return( -1 ); } if( Error[0] != 0 ) { printf( "%s\n", Error ); } endprg(); return( 0 ); }