int main(int argc, char *argv[]) { struct tm *currenttime; time_t caltime; char filename[30]="\0", fileorig[17]="\0"; if (argc != 3) { printf("Usage: makefits inputdatafile inputheaderfile\n"); printf("\n"); printf("Examples:\n"); printf("\n") ; printf("makefits in.dat[ul2560,2048:4] header.fit\n"); printf("\n"); printf("Note that it may be necessary to enclose the input data file name\n"); printf("in single quote characters on the Unix command line.\n"); return(0); } caltime = time ( NULL ); currenttime = gmtime( &caltime ); /* S = Spacecraft (a,b,d) (d is for "development", or anything that is not associated with one or the other s/c); T = a digit representing telescope: 1=EUVI, 2=COR1, 3=COR2, 4=HI1, 5=HI2, 6=GT, 0=generic "development"; L = a digit representing number of images used to create this image, 0 if > 9; */ sprintf (filename, "d01_%04i%02i%02i_%02i%02i%02i.fts", (*currenttime).tm_year+1900, (*currenttime).tm_mon+1, (*currenttime).tm_mday, (*currenttime).tm_hour, (*currenttime).tm_min, (*currenttime).tm_sec); printf ("%s\n",filename); fitscopy ( argv[1], filename ); appendheader ( filename, argv[2] ); addkey ( filename, "FILENAME", filename ); if (!strcspn (argv[1], "[")) strcpy(fileorig, argv[1]); else strncpy(fileorig, argv[1], (strcspn (argv[1], "["))); addkey ( filename, "FILEORIG", fileorig ); return(0); }
int read_ini ( char *inifilename, char *fitsfilename ) { int status = 0; /* CFITSIO status value MUST be initialized to zero! */ FILE *fp; size_t length; char readline[MAX_LINE_LENGTH]; char value[MAX_DESC_LENGTH]; char keyword[MAX_KEYWORD_LENGTH]; #ifdef DEBUG printf ("INI filename: %s\n", inifilename); #endif if (( fp = fopen ( inifilename, "r" )) == NULL ) { printf ("Cannot open file.\n"); exit(1); } while ( !feof (fp) ) { strncpy ( value, "", MAX_DESC_LENGTH ); //fill with NULLs to erase and reset value fgets ( readline, MAX_LINE_LENGTH, fp ); readline[strlen(readline)-1] = '\0'; //crop trailing \n // printf ("----------------\n%s\n", readline); length = strcspn ( readline, " " ); //find first (only?) space strncpy ( value, readline, length ); //pick off first part // printf (" The value is :%s:\n", value ); strcpy ( keyword, &readline[length+1] ); //pick off last part // printf (" The keyword is :%s:\n", keyword ); if ( !strcmp (keyword, "int_time")) addkey ( fitsfilename, keyword, value ); if ( !strcmp (keyword, "quietTime")) addkey ( fitsfilename, keyword, value ); if ( !strcmp (keyword, "sysClock")) addkey ( fitsfilename, keyword, value ); } fclose ( fp ); /* if error occured, print out error message */ if (status) fits_report_error(stderr, status); return(status); }
void EventBallFltk::Handle(int evt){ int key; x=Fl::event_x(); y=Fl::event_y(); if(evt==FL_LEAVE){ Reset(); return; } keymod=0; if(Fl::event_state(FL_SHIFT)) keymod|=KM_SHIFT; if(Fl::event_state(FL_CTRL)) keymod|=KM_CTRL; if(Fl::event_state(FL_ALT)) keymod|=KM_ALT; switch( evt){ case FL_KEYDOWN: key=Fl::event_key(); if(key!=65505 && // shift key!=65507 && // ctrl key!=65513) // alt addkey(key); lastev=K_DOWN; break; case FL_KEYUP: rmkey(Fl::event_key()); lastev=K_UP; break; case FL_PUSH: lastev=M_DOWN; key = Fl::event_button(); msbtn |= (0x1<<(key-1)); break; case FL_RELEASE: lastev=M_UP; key = Fl::event_button(); msbtn &= !(0x1<<(key-1)); break; case FL_DRAG: lastev=M_DRAG; break; default: lastev=NONE; break; } }
void add_typedefs_from_file(char *str) { FILE *file; char line[BUFSIZ]; if ((file = fopen(param_start, "r")) == NULL) { fprintf(stderr, "indent: cannot open file %s\n", str); exit(1); } while ((fgets(line, BUFSIZ, file)) != NULL) { /* Remove trailing whitespace */ *(line + strcspn(line, " \t\n\r")) = '\0'; addkey(strdup(line), 4); } fclose(file); }
void addkeyfile (const TCHAR *path) { struct zfile *f; int keysize; uae_u8 *keybuf; f = zfile_fopen (path, L"rb", ZFD_NORMAL); if (!f) return; zfile_fseek (f, 0, SEEK_END); keysize = zfile_ftell (f); if (keysize > 0) { zfile_fseek (f, 0, SEEK_SET); keybuf = xmalloc (uae_u8, keysize); zfile_fread (keybuf, 1, keysize, f); addkey (keybuf, keysize, path); } zfile_fclose (f); }
int read_footer ( char *imgfile, char *fitsfile, short xsize, short ysize, short bytecount, short offset ) { FILE *fp; char temp[FLEN_COMMENT]; int i; int status = 0; /* CFITSIO status value MUST be initialized to zero! */ if (( fp = fopen ( imgfile, "rb" )) == NULL ) { printf ("Cannot open file"); exit(1); } if ( fseek ( fp, (bytecount*xsize*ysize)+offset, SEEK_SET)) { printf ("Failed Seek"); } else { while ( !feof(fp) ) { strncpy(temp, "", FLEN_COMMENT); fgets ( temp, FLEN_COMMENT, fp ); for (i=0; i<FLEN_COMMENT; i++) { if ( !isprint(temp[i])) temp[i]='\0'; } addkey ( fitsfile, "COMMENT", temp ); #ifdef DEBUG printf ( "Adding COMMENT from bottom of IMG file:\n" ); printf ( "%s\n", temp ); #endif } } fclose(fp); /* if error occured, print out error message */ if (status) fits_report_error(stderr, status); return(status); }
void set_option(char *arg) { struct pro *p; arg++; /* ignore leading "-" */ for (p = pro; p->p_name; p++) if (*p->p_name == *arg && eqin(p->p_name, arg)) goto found; errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1); found: switch (p->p_type) { case PRO_SPECIAL: switch (p->p_special) { case IGN: break; case CLI: if (*param_start == 0) goto need_param; ps.case_indent = atof(param_start); break; case STDIN: if (input == 0) input = stdin; if (output == 0) output = stdout; break; case KEY: if (*param_start == 0) goto need_param; { char *str = strdup(param_start); if (str == NULL) err(1, NULL); addkey(str, 4); } break; default: errx(1, "set_option: internal error: p_special %d", p->p_special); } break; case PRO_BOOL: if (p->p_special == OFF) *p->p_obj = false; else *p->p_obj = true; break; case PRO_INT: if (!isdigit(*param_start)) { need_param: errx(1, "%s: ``%s'' requires a parameter", option_source, arg - 1); } *p->p_obj = atoi(param_start); break; case PRO_FONT: parsefont((struct fstate *) p->p_obj, param_start); break; default: errx(1, "set_option: internal error: p_type %d", p->p_type); } }
/* * Process formated input containing registry data adding keys to the * registry */ static void input_process(void) { /* Read and add keys */ char *name; char type[100]; unsigned char *data; int namelen, datalen; int nameidx, typeidx, dataidx = 0; enum {SNAME = 1000, STYPE, REG_BINARY2, REG_SZ_BACK, REG_SZ_HEX, REG_SZ_HEX2} state; int c; DWORD typeval; int hexcount; name = malloc(namelen = 32); data = malloc(datalen = 32); state = SNAME; nameidx = 0; line = 1; while ((c = getchar()) != EOF) { if (dataidx >= datalen) data = realloc(data, datalen *= 2); switch (state) { case SNAME: if (nameidx >= namelen) name = realloc(name, namelen *= 2); if (c == field_sep) { name[nameidx++] = '\0'; state = STYPE; typeidx = 0; } else if (c == '\n') { fprintf(stderr, "Missing type in line %d\n", line); exit(1); } else name[nameidx++] = c; break; case STYPE: if (c == field_sep) { type[typeidx++] = '\0'; dataidx = 0; if (!nameval(types, sizeof(types) / sizeof(struct s_nameval), type, &typeval)) { fprintf(stderr, "Line %d: Unrecognized type name\n", line); exit(1); } state = typeval; } else if (c == '\n') { fprintf(stderr, "Line %d: missing data\n", line); exit(1); } else type[typeidx++] = c; break; case REG_BINARY: case REG_DWORD: case REG_QWORD: case REG_LINK: case REG_RESOURCE_LIST: case REG_FULL_RESOURCE_DESCRIPTOR: case REG_RESOURCE_REQUIREMENTS_LIST: if (c == '\n') { switch (typeval) { case REG_DWORD: if (dataidx != 4) { fprintf(stderr, "Line :%d: not a four byte DWORD\n", line); exit(1); } swapbytes(data, dataidx); break; case REG_DWORD_BIG_ENDIAN: if (dataidx != 4) { fprintf(stderr, "Line :%d: not a four byte REG_DWORD_BIG_ENDIAN\n", line); exit(1); } break; case REG_QWORD: if (dataidx != 8) { fprintf(stderr, "Line :%d: not an eight byte QWORD\n", line); exit(1); } swapbytes(data, dataidx); break; } addkey: addkey(name, typeval, data, dataidx); nameidx = 0; state = SNAME; line++; break; } else if (isspace(c)) break; data[dataidx] = hexval((unsigned char)c) << 4; state = REG_BINARY2; break; case REG_BINARY2: data[dataidx++] |= hexval((unsigned char)c); state = REG_BINARY; break; case REG_SZ: case REG_MULTI_SZ: case REG_EXPAND_SZ: if (c == '\n') { data[dataidx] = '\0'; goto addkey; } else if (c == '\\') state = REG_SZ_BACK; else data[dataidx++] = c; break; case REG_SZ_BACK: switch (c) { case '\\': data[dataidx++] = '\\'; break; case 'a': data[dataidx++] = '\a'; break; case 'b': data[dataidx++] = '\b'; break; case 'f': data[dataidx++] = '\f'; break; case 't': data[dataidx++] = '\t'; break; case 'r': data[dataidx++] = '\r'; break; case 'n': data[dataidx++] = '\n'; break; case 'v': data[dataidx++] = '\v'; break; case '0': data[dataidx++] = '\0'; break; case 'x': state = REG_SZ_HEX; hexcount = 0; break; } state = REG_SZ; break; case REG_SZ_HEX: data[dataidx] = hexval((unsigned char)c) << 4; state = REG_SZ_HEX2; break; case REG_SZ_HEX2: data[dataidx++] |= hexval((unsigned char)c); state = REG_SZ; break; case REG_NONE: if (c == '\n') goto addkey; else { fprintf(stderr, "Line %d: Unexpected data\n", line); exit(1); } default: assert(0); } } }
void set_option(char *arg) { struct pro *p; arg++; /* ignore leading "-" */ for (p = pro; p->p_name; p++) if (*p->p_name == *arg && eqin(p->p_name, arg)) goto found; fprintf(stderr, "indent: %s: unknown parameter \"%s\"\n", option_source, arg - 1); exit(1); found: switch (p->p_type) { case PRO_SPECIAL: switch (p->p_special) { case IGN: break; case CLI: if (*param_start == 0) goto need_param; ps.case_indent = atof(param_start); break; case STDIN: if (input == 0) input = stdin; if (output == 0) output = stdout; break; case KEY: if (*param_start == 0) goto need_param; { char *str; str = strdup(param_start); addkey(str, 4); } break; case KEY_FILE: if (*param_start == 0) goto need_param; add_typedefs_from_file(param_start); break; case VERSION: { printf("pg_bsd_indent %s\n", INDENT_PG_VERSION); exit(0); } break; default: fprintf(stderr, "\ indent: set_option: internal error: p_special %d\n", p->p_special); exit(1); } break; case PRO_BOOL: if (p->p_special == OFF) *p->p_obj = false; else *p->p_obj = true; break; case PRO_INT: if (!isdigit((unsigned char)*param_start)) { need_param: fprintf(stderr, "indent: %s: ``%s'' requires a parameter\n", option_source, arg - 1); exit(1); } *p->p_obj = atoi(param_start); break; case PRO_FONT: parsefont((struct fstate *) p->p_obj, param_start); break; default: fprintf(stderr, "indent: set_option: internal error: p_type %d\n", p->p_type); exit(1); } }
int main( int argc, char ** argv) { char *tmp; char *profile_pathname = 0; BOOLEAN using_stdin = false; exit_values_ty exit_status; #if defined (HAVE_SETLOCALE) setlocale(LC_ALL, ""); #endif bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #if defined (_WIN32) && !defined (__CYGWIN__) /* wildcard expansion of commandline arguments, see wildexp.c */ extern void wildexp(int *argc, char ***argv); wildexp(&argc, &argv); #endif /* defined (_WIN32) && !defined (__CYGWIN__) */ #ifdef DEBUG if (debug) { debug_init(); } #endif /* 'size_t', 'wchar_t' and 'ptrdiff_t' are guarenteed to be * available in ANSI C. * * These pointers will be freed in cleanup_user_specials(). */ tmp = xmalloc(7); memcpy(tmp, "size_t", 7); addkey(tmp, rw_decl); tmp = xmalloc(8); memcpy(tmp, "wchar_t", 8); addkey(tmp, rw_decl); tmp = xmalloc(10); memcpy(tmp, "ptrdiff_t", 10); addkey(tmp, rw_decl); init_parser (); initialize_backups (); exit_status = total_success; input_files = 0; in_file_names = (char **) xmalloc(max_input_files * sizeof (char *)); set_defaults(); profile_pathname = handle_profile(argc, argv); exit_status = process_args(argc, argv, &using_stdin); if (exit_status == total_success) { if (settings.verbose && profile_pathname) { fprintf (stderr, _("Read profile %s\n"), profile_pathname); } set_defaults_after(); exit_status = indent_all(using_stdin); } if (profile_pathname) xfree(profile_pathname); xfree(in_file_names); uninit_parser(); cleanup_user_specials(); return exit_status; }
int intr_sysupdate() { SDL_Event e; int i = 0; static int last_time = 0; int now, time_diff; while (SDL_PollEvent(&e)) { switch (e.type) { case SDL_QUIT: SDL_Quit(); exit(1); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if(e.button.state == SDL_PRESSED && ((key_pressed(KEY_PL3_LEFT) && e.button.button == SDL_BUTTON_RIGHT) || (key_pressed(KEY_PL3_RIGHT) && e.button.button == SDL_BUTTON_LEFT) || (e.button.button == SDL_BUTTON_LEFT && e.button.button == SDL_BUTTON_RIGHT) || e.button.button == SDL_BUTTON_MIDDLE)) { addkey(KEY_PL3_JUMP & 0x7fff); } else if(e.button.state == SDL_RELEASED && ((key_pressed(KEY_PL3_LEFT) && e.button.button == SDL_BUTTON_RIGHT) || (key_pressed(KEY_PL3_RIGHT) && e.button.button == SDL_BUTTON_LEFT) || e.button.button == SDL_BUTTON_MIDDLE)) { addkey((KEY_PL3_JUMP & 0x7fff) | 0x8000); } if(e.button.button == SDL_BUTTON_LEFT) { SDL_Scancode scancode = KEY_PL3_LEFT; scancode &= 0x7fff; if(e.button.state == SDL_RELEASED) { if(key_pressed(KEY_PL3_JUMP) && (SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(SDL_BUTTON_RIGHT))) addkey(KEY_PL3_RIGHT & 0x7fff); else scancode |= 0x8000; } addkey(scancode); } else if(e.button.button == SDL_BUTTON_RIGHT) { SDL_Scancode scancode = KEY_PL3_RIGHT; scancode &= 0x7fff; if (e.button.state == SDL_RELEASED) { if(key_pressed(KEY_PL3_JUMP) && (SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(SDL_BUTTON_LEFT))) addkey(KEY_PL3_LEFT & 0x7fff); else scancode |= 0x8000; } addkey(scancode); } break; case SDL_KEYDOWN: case SDL_KEYUP: if (e.key.repeat != 0) { continue; } switch (e.key.keysym.scancode) { case SDL_SCANCODE_F12: if (e.type == SDL_KEYDOWN) { SDL_Quit(); exit(1); } break; case SDL_SCANCODE_F10: if (e.type == SDL_KEYDOWN) { fs_toggle(); } break; case SDL_SCANCODE_1: if (e.type == SDL_KEYUP) ai[0] = !ai[0]; /* Release keys, otherwise it will continue moving that way */ addkey((KEY_PL1_LEFT & 0x7fff) | 0x8000); addkey((KEY_PL1_RIGHT & 0x7fff) | 0x8000); addkey((KEY_PL1_JUMP & 0x7fff) | 0x8000); break; case SDL_SCANCODE_2: if (e.type == SDL_KEYUP) ai[1] = !ai[1]; /* Release keys, otherwise it will continue moving that way */ addkey((KEY_PL2_LEFT & 0x7fff) | 0x8000); addkey((KEY_PL2_RIGHT & 0x7fff) | 0x8000); addkey((KEY_PL2_JUMP & 0x7fff) | 0x8000); break; case SDL_SCANCODE_3: if (e.type == SDL_KEYUP) ai[2] = !ai[2]; /* Release keys, otherwise it will continue moving that way */ addkey((KEY_PL3_LEFT & 0x7fff) | 0x8000); addkey((KEY_PL3_RIGHT & 0x7fff) | 0x8000); addkey((KEY_PL3_JUMP & 0x7fff) | 0x8000); break; case SDL_SCANCODE_4: if (e.type == SDL_KEYUP) ai[3] = !ai[3]; /* Release keys, otherwise it will continue moving that way */ addkey((KEY_PL4_LEFT & 0x7fff) | 0x8000); addkey((KEY_PL4_RIGHT & 0x7fff) | 0x8000); addkey((KEY_PL4_JUMP & 0x7fff) | 0x8000); break; case SDL_SCANCODE_ESCAPE: if (e.type == SDL_KEYUP) addkey(1 | 0x8000); else addkey(1 & 0x7fff); break; default: e.key.keysym.scancode &= 0x7fff; if (e.type == SDL_KEYUP) e.key.keysym.scancode |= 0x8000; addkey(e.key.keysym.scancode); break; } break; default: break; } i++; } SDL_Delay(1); now = SDL_GetTicks(); time_diff = now - last_time; if (time_diff>0) { i = time_diff / (1000 / 60); if (i) { last_time = now; } else { int tmp; tmp = (1000/60) - i - 10; if (tmp>0) SDL_Delay(tmp); } } return i; }
int load_keyring (struct uae_prefs *p, const TCHAR *path) { uae_u8 *keybuf; int keysize; TCHAR tmp[MAX_PATH], *d; int keyids[] = { 0, 48, 73, -1 }; int cnt, i; free_keyring (); keybuf = target_load_keyfile (p, path, &keysize, tmp); addkey (keybuf, keysize, tmp); for (i = 0; keyids[i] >= 0; i++) { struct romdata *rd = getromdatabyid (keyids[i]); TCHAR *s; if (rd) { s = romlist_get (rd); if (s) addkeyfile (s); } } cnt = 0; for (;;) { keybuf = NULL; keysize = 0; tmp[0] = 0; switch (cnt) { case 0: if (path) _tcscpy (tmp, path); break; case 1: _tcscat (tmp, L"rom.key"); break; case 2: if (p) { _tcscpy (tmp, p->path_rom); _tcscat (tmp, L"rom.key"); } break; case 3: _tcscpy (tmp, L"roms/rom.key"); break; case 4: _tcscpy (tmp, start_path_data); _tcscat (tmp, L"rom.key"); break; case 5: _stprintf (tmp, L"%s../shared/rom/rom.key", start_path_data); break; case 6: if (p) { for (i = 0; uae_archive_extensions[i]; i++) { if (_tcsstr (p->romfile, uae_archive_extensions[i])) break; } if (!uae_archive_extensions[i]) { _tcscpy (tmp, p->romfile); d = _tcsrchr (tmp, '/'); if (!d) d = _tcsrchr (tmp, '\\'); if (d) _tcscpy (d + 1, L"rom.key"); } } break; case 7: return get_keyring (); } cnt++; if (!tmp[0]) continue; addkeyfile (tmp); } }