void deathlog_command(const char *arg, struct session *ses) { FILE *fh; char fname[BUFFER_SIZE], text[BUFFER_SIZE], temp[BUFFER_SIZE], lfname[BUFFER_SIZE]; if (*arg) { arg = get_arg_in_braces(arg, temp, 0); arg = get_arg_in_braces(arg, text, 1); substitute_vars(temp, fname); substitute_myvars(fname, temp, ses); expand_filename(temp, fname, lfname); substitute_vars(text, temp); substitute_myvars(temp, text, ses); if ((fh = fopen(lfname, "a"))) { cfprintf(fh, "%s\n", text); fclose(fh); } else tintin_eprintf(ses, "#ERROR: COULDN'T OPEN FILE {%s}.", fname); } else tintin_eprintf(ses, "#ERROR: valid syntax is: #deathlog <file> <text>"); }
/** * Sets a string-valued option. * * An error string (function-internal constant, do NOT free) * is returned if the type of the option does not correspond to * the function which is called. Upon success, NULL is returned. * * set_string_option_value does NOT strdup the value! * * @param opt_name The name of the option to set. * @param value Its new value. * @return NULL if all OK; otherwise a string describing the problem. */ char * set_string_option_value(char *opt_name, char *value) { int opt; opt = find_option(opt_name); if (opt < 0) return "No such option"; else if (cqpoptions[opt].type == OptContext) return set_context_option_value(opt_name, value, 1); else if (cqpoptions[opt].type != OptString) return "Wrong option type (tried to set integer-valued variable to string value)"; else if (validate_string_option_value(opt, value)) { /* free the old value */ if (*((char **)cqpoptions[opt].address)) free(*((char **)cqpoptions[opt].address)); if (strcmp(cqpoptions[opt].opt_name, "Registry") == 0 || strcmp(cqpoptions[opt].opt_name, "LocalCorpusDirectory") == 0) { *((char **)cqpoptions[opt].address) = expand_filename(value); free(value); } else *((char **)cqpoptions[opt].address) = value; execute_side_effects(opt); return NULL; } else return "Illegal value for this option"; }
// fifo_init_internal(path) // If path is NULL, reopen existing fifo, else open anew. static int fifo_init_internal(const char *fifo_path) { if (fifo_path) { fifo_deinit(); fifo_name = expand_filename(fifo_path); if (!check_fifo(fifo_name)) { scr_LogPrint(LPRINT_LOGNORM, "WARNING: Cannot create the FIFO. " "%s already exists and is not a pipe", fifo_name); g_free(fifo_name); fifo_name = NULL; return -1; } } else if (fifo_name) g_source_remove_by_user_data(fifo_channel); else return -1; if (!attach_fifo(fifo_name)) { scr_LogPrint(LPRINT_LOGNORM, "Error: Cannot open fifo"); return -1; } setenv(FIFO_ENV_NAME, fifo_name, 1); scr_LogPrint(LPRINT_LOGNORM, "FIFO initialized (%s)", fifo_path); return 1; }
static JingleFT* _new(const gchar *name) { struct stat fileinfo; GError *err = NULL; gchar *filename = expand_filename(name); // expand ~ to HOME JingleFT *jft = g_new0(JingleFT, 1); jft->desc = g_strdup(name); jft->type = JINGLE_FT_OFFER; jft->name = g_path_get_basename(filename); jft->transmit = 0; jft->hash = NULL; jft->md5 = NULL; jft->state = JINGLE_FT_PENDING; jft->dir = JINGLE_FT_OUTGOING; jft->date = 0; jft->size = 0; // Add the jft to the list JingleFTInfo *jftinf = g_new0(JingleFTInfo, 1); jftinf->index = _next_index(); jftinf->jft = jft; info_list = g_slist_append(info_list, jftinf); if (g_stat(filename, &fileinfo) != 0) { scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: unable to stat %s", filename); jft->state = JINGLE_FT_ERROR; return NULL; } if (!S_ISREG(fileinfo.st_mode) || S_ISLNK(fileinfo.st_mode)) { scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: File doesn't exist!"); jft->state = JINGLE_FT_ERROR; return NULL; } jft->date = fileinfo.st_mtime; jft->size = fileinfo.st_size; jft->outfile = g_io_channel_new_file(filename, "r", &err); if (jft->outfile == NULL || err != NULL) { scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: %s %s", err->message, name); g_error_free(err); jft->state = JINGLE_FT_ERROR; return NULL; } g_io_channel_set_encoding(jft->outfile, NULL, &err); if (jft->outfile == NULL || err != NULL) { scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: %s %s", err->message, name); g_error_free(err); jft->state = JINGLE_FT_ERROR; return NULL; } return jft; }
static const gchar * parse_cert_option_as_pem (JsonObject *options, const gchar *option, GString *pem) { const gchar *problem = NULL; const gchar *file; const gchar *data; gchar *path; problem = parse_option_file_or_data (options, option, &file, &data); if (problem) return problem; if (file) { path = expand_filename (file); /* For now we assume file contents are PEM */ problem = load_pem_contents (path, option, pem); g_free (path); } else if (data) { /* Format this as PEM of the given type */ g_string_append (pem, data); g_string_append_c (pem, '\n'); } return problem; }
static gboolean parse_cert_option_as_pem (CockpitChannel *self, JsonObject *options, const gchar *option, GString *pem) { gboolean ret = TRUE; const gchar *file; const gchar *data; gchar *path; if (!parse_option_file_or_data (self, options, option, &file, &data)) return FALSE; if (file) { path = expand_filename (file); /* For now we assume file contents are PEM */ ret = load_pem_contents (self, path, option, pem); g_free (path); } else if (data) { /* Format this as PEM of the given type */ g_string_append (pem, data); g_string_append_c (pem, '\n'); } return ret; }
static Boolean test_expand_filename(int verbose) { char cwd[10240]; char *currpath, *testpath1, *testpath2; currpath = xstrdup(getcwd(cwd, 10240)); testpath1 = expand_filename(__FILE__, USE_CWD_PATH); globals.dvi_file.dirname = xstrdup(cwd); globals.dvi_file.dirname = xstrcat(globals.dvi_file.dirname, "/"); testpath2 = expand_filename(__FILE__, USE_DVI_PATH); if (__FILE__[0] == '/') { free(currpath); currpath = xstrdup(__FILE__); } else { currpath = xstrcat(currpath, "/"); currpath = xstrcat(currpath, __FILE__); } return test_str_equality(verbose, testpath1, currpath) \ && test_str_equality(verbose, testpath2, currpath); }
void unlink_command(const char *arg, struct session *ses) { char file[BUFFER_SIZE], temp[BUFFER_SIZE], lstr[BUFFER_SIZE]; if (*arg) { arg = get_arg_in_braces(arg, temp, 1); substitute_vars(temp, file); substitute_myvars(file, temp, ses); expand_filename(temp, file, lstr); unlink(lstr); } else tintin_eprintf(ses, "#ERROR: valid syntax is: #unlink <filename>"); }
char * expand_filename_append_dvi(const char *filename, expandPathTypeT type, Boolean must_exist) { char canonical_path[MAXPATHLEN + 1]; char *normalized_fname = filename_append_dvi(filename); char *expanded_fname = expand_filename(normalized_fname, type); if (must_exist) { char *canonical_name = REALPATH(expanded_fname, canonical_path); free(normalized_fname); free(expanded_fname); return xstrdup(canonical_name); } else { free(normalized_fname); return expanded_fname; } }
/* Return the pathname part of filename. This can be NULL. */ char * pathname_part (char *filename) { char *result = NULL; int i; filename = expand_filename (filename, ""); i = skip_directory_part (filename); if (i) { result = xmalloc (1 + i); strncpy (result, filename, i); result[i] = 0; } free (filename); return result; }
/** Create an empty file named <b>filename</b>. if <b>createdir</b> is true, * then the full path to <b>filename</b> will be created. Returns true on * success, or false on error and <b>errmsg</b> will be set. */ bool touch_file(const QString &filename, bool createdir, QString *errmsg) { /* Expand the file's path if it starts with a shortcut, like "~/" or * "%APPDATA%" */ QString expanded = expand_filename(filename); /* If the file's path doesn't exist and we're supposed to create it, do that * now. */ if (createdir && !create_path(QFileInfo(expanded).absolutePath())) { return false; } /* Touch the file */ QFile file(expanded); if (!QFileInfo(expanded).exists()) { if (!file.open(QIODevice::WriteOnly)) { return err(errmsg, file.errorString()); } } return true; }
VIOAPI VIO_Status start_volume_input( VIO_STR filename, int n_dimensions, VIO_STR dim_names[], nc_type volume_nc_data_type, VIO_BOOL volume_signed_flag, VIO_Real volume_voxel_min, VIO_Real volume_voxel_max, VIO_BOOL create_volume_flag, VIO_Volume *volume, minc_input_options *options, volume_input_struct *input_info ) { VIO_Status status; int d; VIO_STR expanded_filename; minc_input_options default_options; status = VIO_OK; if( options == (minc_input_options *) NULL ) { set_default_minc_input_options( &default_options ); options = &default_options; } if( create_volume_flag || *volume == (VIO_Volume) NULL ) { if( n_dimensions < 1 || n_dimensions > VIO_MAX_DIMENSIONS ) { n_dimensions = VIO_MAX_DIMENSIONS; } if( dim_names == (VIO_STR *) NULL ) dim_names = get_default_dim_names( n_dimensions ); *volume = create_volume( n_dimensions, dim_names, volume_nc_data_type, volume_signed_flag, volume_voxel_min, volume_voxel_max ); } else if( n_dimensions != get_volume_n_dimensions( *volume ) && volume_is_alloced( *volume ) ) { free_volume_data( *volume ); } expanded_filename = expand_filename( filename ); if (filename_extension_matches( expanded_filename, FREE_ENDING ) ) { input_info->file_format = FREE_FORMAT; } #ifdef LIBMINC_NIFTI_SUPPORT else if (filename_extension_matches( expanded_filename, "mgh" ) || filename_extension_matches( expanded_filename, "mgz" ) ) { input_info->file_format = MGH_FORMAT; /* FreeSurfer */ } else if (filename_extension_matches( expanded_filename, "nii" ) || filename_extension_matches( expanded_filename, "hdr" )) { input_info->file_format = NII_FORMAT; /* NIfTI-1 */ } else if (filename_extension_matches( expanded_filename, "nhdr" ) || filename_extension_matches( expanded_filename, "nrrd" )) { input_info->file_format = NRRD_FORMAT; /* NRRD */ } #endif /*LIBMINC_NIFTI_SUPPORT*/ else { #if defined(HAVE_MINC1) && defined(HAVE_MINC2) if(options->prefer_minc2_api) { #endif #if defined(HAVE_MINC2) input_info->file_format = MNC2_FORMAT; #endif #if defined(HAVE_MINC1) && defined(HAVE_MINC2) } else { #endif #ifdef HAVE_MINC1 input_info->file_format = MNC_FORMAT; #endif #if defined(HAVE_MINC1) && defined(HAVE_MINC2) } #endif } switch( input_info->file_format ) { #ifdef HAVE_MINC1 case MNC_FORMAT: if( !file_exists( expanded_filename ) ) { file_exists_as_compressed( expanded_filename, &expanded_filename ); } input_info->minc_file = initialize_minc_input( expanded_filename, *volume, options ); if( input_info->minc_file == (Minc_file) NULL ) status = VIO_ERROR; else { for_less( d, 0, VIO_MAX_DIMENSIONS ) input_info->axis_index_from_file[d] = d; } break; #endif /*HAVE_MINC1*/ #ifdef HAVE_MINC2 case MNC2_FORMAT: input_info->minc_file = initialize_minc2_input( expanded_filename, *volume, options ); if( input_info->minc_file == (Minc_file) NULL ) status = VIO_ERROR; else { for_less( d, 0, VIO_MAX_DIMENSIONS ) input_info->axis_index_from_file[d] = d; } break; #endif /*HAVE_MINC2*/ case FREE_FORMAT: status = initialize_free_format_input( expanded_filename, *volume, input_info ); break; #ifdef LIBMINC_NIFTI_SUPPORT case MGH_FORMAT: status = initialize_mgh_format_input( expanded_filename, *volume, input_info ); break; case NII_FORMAT: status = initialize_nifti_format_input( expanded_filename, *volume, input_info ); break; case NRRD_FORMAT: status = initialize_nrrd_format_input( expanded_filename, *volume, input_info ); break; #endif /*LIBMINC_NIFTI_SUPPORT*/ default: /*Unsupported file format*/ status = VIO_ERROR; break; } if( status != VIO_OK && create_volume_flag ) delete_volume( *volume ); delete_string( expanded_filename ); return( status ); }
/* * save_copy() - Append a copy of the message contained in "filename" to * the file specified by "copy_file". This routine simply gets all of * the filenames right, and then invokes "save_mssg()" to do * the dirty work. */ int save_copy(const char *fname_dest, const char *fname_mssg, const SEND_HEADER *shdr, int form) { char buffer[SLEN], /* read buffer */ savename[SLEN], /* name of file saving into */ msg_buffer[SLEN]; char *return_alias; int is_ordinary_file; int err; /* presume fname_dest is okay as is for now */ strcpy(savename, fname_dest); /* if save_by_name or save_by_alias wanted */ if((strcmp(fname_dest, "=") == 0) || (strcmp(fname_dest, "=?") == 0)) { if ((save_by_alias && (return_alias = address_to_alias(shdr->expanded_to)) != NULL)) strcpy(buffer, return_alias); else if (save_by_name) get_return_name(shdr->expanded_to, buffer, TRUE); else get_return_name(shdr->to, buffer, TRUE); if (strlen(buffer) == 0) { /* can't get file name from 'to' -- use sent_mail instead */ dprint(3, (debugfile, "Warning: get_return_name couldn't break down %s\n", shdr->to)); show_error(catgets(elm_msg_cat, ElmSet, ElmCannotDetermineToName, "Cannot determine `to' name to save by! Saving to \"sent\" folder %s instead."), sent_mail); strcpy(savename, "<"); if (sleepmsg > 0) sleep(sleepmsg); } else sprintf(savename, "=%s", buffer); /* good! */ } expand_filename(savename); /* * If saving conditionally by logname but folder doesn't * exist save to sent folder instead. */ if((strcmp(fname_dest, "=?") == 0) && (access(savename, WRITE_ACCESS) != 0)) { dprint(5, (debugfile, "Conditional save by name: file %s doesn't exist - using \"<\".\n", savename)); strcpy(savename, "<"); expand_filename(savename); } /* * Allow options * confirm_files, confirm_folders, * confirm_append and confirm_create * to control where the actual copy * should be saved. */ is_ordinary_file = strncmp (savename, folders, strlen(folders)); if (elm_access(savename, ACCESS_EXISTS)== 0) { /* already there!! */ if (confirm_append || (confirm_files && is_ordinary_file)) { /* * OK in batch mode it may be impossible * to ask the user to confirm. So we have * to use sent_mail anyway. */ if (!OPMODE_IS_INTERACTIVE(opmode)) { strcpy(savename, sent_mail); } else { if (is_ordinary_file) sprintf(msg_buffer, catgets(elm_msg_cat, ElmSet, ElmConfirmFilesAppend, "Append to an existing file `%s'?"), savename); else sprintf(msg_buffer, catgets(elm_msg_cat, ElmSet, ElmConfirmFolderAppend, "Append to mail folder `%s'?"), savename); /* FOO - does this really need to be "clear-and-center" ? */ if (!enter_yn(msg_buffer, FALSE, LINES-2, TRUE)) { strcpy(savename, sent_mail); PutLine(LINES-2, 0, catgets(elm_msg_cat, ElmSet, ElmSavingToInstead, "Alright - saving to `%s' instead"), savename); FlushOutput(); if (sleepmsg > 0) sleep(sleepmsg); ClearLine (LINES-2); } } } } else { if (confirm_create || (confirm_folders && !is_ordinary_file)) { /* * OK in batch mode it may be impossible * to ask the user to confirm. So we have * to use sent_mail anyway. */ if (!OPMODE_IS_INTERACTIVE(opmode)) { strcpy(savename, sent_mail); } else { if (is_ordinary_file) sprintf(msg_buffer, catgets(elm_msg_cat, ElmSet, ElmConfirmFilesCreate, "Create a new file `%s'?"), savename); else sprintf(msg_buffer, catgets(elm_msg_cat, ElmSet, ElmConfirmFolderCreate, "Create a new mail folder `%s'?"), savename); /* FOO - does this really need to be "clear-and-center" ? */ if (!enter_yn(msg_buffer, FALSE, LINES-2, TRUE)) { strcpy(savename, sent_mail); PutLine(LINES-2, 0, catgets(elm_msg_cat, ElmSet, ElmSavingToInstead, "Alright - saving to `%s' instead"), savename); FlushOutput(); if (sleepmsg > 0) sleep(sleepmsg); ClearLine (LINES-2); } } } } if ((err = can_open(savename, "a"))) { dprint(2, (debugfile, "Error: attempt to autosave to a file that can't be appended to!\n")); dprint(2, (debugfile, "\tfilename = \"%s\"\n", savename)); dprint(2, (debugfile, "** %s **\n", strerror(err))); /* Lets try sent_mail before giving up */ if(strcmp(sent_mail, savename) == 0) { /* we are ALREADY using sent_mail! */ show_error(catgets(elm_msg_cat, ElmSet, ElmCannotSaveTo, "Cannot save to %s!"), savename); return(FALSE); } if ((err = can_open(sent_mail, "a"))) { dprint(2, (debugfile, "Error: attempt to autosave to a file that can't be appended to!\n")); dprint(2, (debugfile, "\tfilename = \"%s\"\n", sent_mail)); dprint(2, (debugfile, "** %s **\n", strerror(err))); show_error(catgets(elm_msg_cat, ElmSet, ElmCannotSaveToNorSent, "Cannot save to %s nor to \"sent\" folder %s!"), savename, sent_mail); return(FALSE); } show_error(catgets(elm_msg_cat, ElmSet, ElmCannotSaveToSavingInstead, "Cannot save to %s! Saving to \"sent\" folder %s instead."), savename, sent_mail); if (sleepmsg > 0) sleep(sleepmsg); strcpy(savename, sent_mail); } return save_mssg(savename, fname_mssg, shdr, form); }
/************************************************************************ * * * User has entered a filename. If it is a directory, go into that * * directory and list all directory files. Otherwise, return to * * the user function call. * * */ static void file_execute_proc(void) { static char markers[] = "/"; /* List of spurious symbols at end of names */ char fullname[MAXPATHLEN]; char filename[MAXPATHLEN]; char *p; /* Temp */ char *q; char *uname; /* user seleted filename */ int i; struct stat statbuf; /* status of a file */ uname = (char *) xv_get(fhdl->filename, PANEL_VALUE); if (*uname == NULL){ err_msg("No file name entered"); return; } if (expand_filename(uname, filename) == NULL){ err_msg("Can't expand filename"); return; } // Strip off any trailing markers while ( (p=strpbrk(filename+strlen(filename)-1, markers)) && (p > filename)) // Don't remove everything { *p = 0; } if (*filename == '/'){ // We have given a full path name strcpy(fullname, filename); }else{ strcpy(fullname, dirname); strcat(fullname, "/"); strcat(fullname, filename); } // Avoid uncontrolled pathname growth // Remove excess slashes ("//" is same as "/") while (p=strstr(fullname, "//")){ // Move portion of string beyond first "/" down one place do{ *p = *(p+1); } while (*p++); } // Remove "/./" elements while (p=strstr(fullname, "/./")){ // Move portion of string beyond "/." down two places do{ *p = *(p+2); } while (*p++); } // Remove trailing "/." i = strlen(fullname); if (strcmp(fullname+i-2, "/.") == 0){ // Filename ends in "/."; cut it off fullname[i-2] = 0; } // Remove "/../" elements (along with preceding element) while (p=strstr(fullname, "/../")){ q = p + 3; // Point to following "/" while ( (*(--p) != '/') && (p > fullname) ); // Point to previous "/" do{ *p = *q++; // Move following stuff down } while (*p++); } // Remove trailing "/.." (along with preceding element) i = strlen(fullname); if (strcmp(fullname+i-3, "/..") == 0){ // Filename ends in "/.."; cut off last two elements for (i=0; (i<2) && (p=strrchr(fullname, '/')); i++){ *p = 0; } } // Make sure something is left of the name if ( *fullname == 0 ){ strcpy(fullname, "/"); } int staterr; if ((staterr=stat(fullname, &statbuf)) == 0 && (statbuf.st_mode & S_IFMT) == S_IFDIR) { strcpy(dirname, fullname); /* Get the files */ if (file_listing(dirname) == NOT_OK){ err_msg("Error in file_listing"); return; } /* Update the directory message */ show_dir_path(short_path(dirname)); xv_set(fhdl->filename, PANEL_VALUE, "", NULL); /* Remember new default directory */ if (curfinfo){ free(curfinfo->dirpath); curfinfo->dirpath = strdup(dirname); } }else{ if (curfinfo == NULL){ err_msg("No registered function"); return; } /* in this case we will only load/save one file */ if (xv_get(fhdl->load_but, PANEL_SHOW_ITEM) == TRUE){ if (staterr){ err_msg("Can't find file: %s", short_path(fullname)); return; }else if ((statbuf.st_mode & S_IFMT) != S_IFREG){ err_msg("Error: Invalid file or directory."); return; }else{ if (curfinfo->loadfunc){ curfinfo->loadfunc(dirname, filename); } } }else{ if (curfinfo->savefunc && (staterr||confirm_overwrite(filename))){ curfinfo->savefunc(dirname, filename); } } } }
char * output_name_from_input_name (char *name) { return expand_filename (NULL, name); }
static const gchar * parse_cert_option_as_database (JsonObject *options, const gchar *option, GTlsDatabase **database) { gboolean temporary = FALSE; GError *error = NULL; const gchar *problem; const gchar *file; const gchar *data; gchar *path; gint fd; problem = parse_option_file_or_data (options, option, &file, &data); if (problem) return problem; if (file) { path = expand_filename (file); problem = NULL; } else if (data) { temporary = TRUE; path = g_build_filename (g_get_user_runtime_dir (), "cockpit-bridge-cert-authority.XXXXXX", NULL); fd = g_mkstemp (path); if (fd < 0) { g_warning ("couldn't create temporary directory: %s: %s", path, g_strerror (errno)); problem = "internal-error"; } else { close (fd); if (!g_file_set_contents (path, data, -1, &error)) { g_warning ("couldn't write temporary data to: %s: %s", path, error->message); problem = "internal-error"; g_clear_error (&error); } } } else { /* Not specified */ *database = NULL; return NULL; } if (problem == NULL) { *database = g_tls_file_database_new (path, &error); if (error) { g_warning ("couldn't load certificate data: %s: %s", path, error->message); problem = "internal-error"; g_clear_error (&error); } } /* Leave around when problem, for debugging */ if (temporary && problem == NULL) g_unlink (path); g_free (path); return problem; }
int main(int argc, char *argv[]) { char opt, *framename, *listname, *outname, *e_outname, buffer[BUFSIZ]; int n, row, col, cX, cY, npatch, npxi, npxt, nprof; int flag_autoname, flag_verbose, status, bitmask[YAR][XAR]; long xsize, ysize, lowleft[DIM], upright[DIM], increment[DIM] = {1L, 1L}, framesize[DIM]; float mask_val, cutoff, framefragment[YAR][XAR]; struct star* patchstars; FILE *listfile; fitsfile *frame, *maskedframe; extern char *optarg; extern int opterr; framename = NULL; listname = NULL; outname = NULL; mask_val = DEFAULT_MASK; cutoff = DEFAULT_CUTOFF; flag_autoname = 1; flag_verbose = 0; opterr = 0; while ((opt=getopt(argc, argv, "f:l:o:m:c:v")) != -1) { switch (opt) { case 'f': framename = optarg; break; case 'l': listname = optarg; break; case 'o': flag_autoname = 0; outname = optarg; break; case 'm': mask_val = atof(optarg); break; case 'c': cutoff = atof(optarg); break; case 'v': flag_verbose = 1; break; default: usage(argv); } } /* check mandatory parameters: */ if (framename == NULL || listname == NULL) usage(argv); if (cutoff < 0.0) { fprintf(stderr, " WARNING: invalid cut-off value (%.1f ADU), using default (%.1f ADU)\n", cutoff, DEFAULT_CUTOFF); cutoff = DEFAULT_CUTOFF; } /* read ID and coordinates from any single-lined Daophot output, detect and skip the header if necessary: */ if ((listfile=fopen(listname, "r")) == NULL) { file_read_error(listname); } else { npatch = line_count(listfile); if (has_daophot_header(listfile) == 1) { npatch -= DAO_HEADER_SIZE; line_skip(listfile, DAO_HEADER_SIZE); } if (npatch <= 0) { fclose(listfile); fprintf(stderr, " couldn't read contents of '%s', exiting.\n\n", listname); exit(EXIT_FAILURE); } patchstars = calloc(npatch, sizeof(struct star)); if (patchstars == NULL) { fclose(listfile); memory_error(); } for (n=0; n < npatch; n++) { fgets(buffer, BUFSIZ, listfile); sscanf(buffer, "%d %lf %lf", &patchstars[n].num, &patchstars[n].X, &patchstars[n].Y); } fclose(listfile); } status = 0; fits_open_file(&frame, framename, READONLY, &status); if (status != 0) { free(patchstars); file_read_error(framename); } fits_get_img_size(frame, DIM, framesize, &status); fits_print_error(status); xsize = framesize[0]; ysize = framesize[1]; printf(" %s: %ld x %ld pixels\n", framename, xsize, ysize); printf(" %s: %d stars in the list\n", listname, npatch); printf(" mask value: %.1f ADU\n", mask_val); printf(" cut-off level: %.1f ADU\n", cutoff); if (flag_autoname == 1) { outname = expand_filename(framename, "-msk", 0, 0); if (outname == NULL) { free(patchstars); fits_close_file(frame, &status); memory_error(); } } printf(" output file: %s\n", outname); /* force cfitsio to overwrite already existing file (prepend ! to the filename) */ e_outname = prepend_bang(outname); if (e_outname == NULL) { free(patchstars); fits_close_file(frame, &status); memory_error(); } /* create output (masked) frame: */ fits_create_file(&maskedframe, e_outname, &status); fits_print_error(status); free(e_outname); if (flag_autoname == 1) /* only necessary if outname was created automatically */ free(outname); fits_copy_file(frame, maskedframe, 1, 1, 1, &status); fits_print_error(status); npxt = 0; nprof = 0; /* process the stars in the list: */ for (n=0; n < npatch; n++) { if (flag_verbose == 1) printf("\n star #%d:\n", patchstars[n].num); /* cfitsio doesn't understand fractional pixels, round the coordinates to nearest integer: */ cX = rint(patchstars[n].X); cY = rint(patchstars[n].Y); /* make sure center is in the picture, skip this star if it is not: */ if (cX < 1 || cY < 1 || cX > xsize || cY > ysize) { printf(" star #%d is outside the frame (%d,%d), skipping.\n", patchstars[n].num, cX, cY); continue; } /* * in fitsio pixel index runs from 1 to N, not from 0 to N-1. * consider XAR=21 (reading 10 pixels right and left from center), XSIZE=2044. * example 1: star with x=10. fitsio will reach and try to read pixel at x=0, ILLEGAL. * example 2: star with x=2034. fitsio will reach and try to read pixel at x=2044, LEGAL. * we have to use LESS OR EQUAL when checking lower and left boundary, * for upper and right boundary only using GREATER is fine */ else if (cX <= (XAR-1)/2 || cY <= (YAR-1)/2 || cX > xsize-(XAR-1)/2 || cY > ysize-(YAR-1)/2) { printf(" star #%d is too close to the edge or partially outside the frame (%d,%d), skipping.\n", patchstars[n].num, cX, cY); continue; } if (flag_verbose == 1) printf(" coordinates of star #%d center in current frame: (%d,%d)\n", patchstars[n].num, cX, cY); /* compute the coordinates of lower left and upper right pixel: */ lowleft[0] = cX - (XAR-1)/2; lowleft[1] = cY - (YAR-1)/2; upright[0] = cX + (XAR-1)/2; upright[1] = cY + (YAR-1)/2; /* load frame fragment with the star into table: */ fits_read_subset(frame, TFLOAT, lowleft, upright, increment, 0, framefragment, 0, &status); fits_print_error(status); /* initialise the bitmask with zeros: */ for (row=0; row < YAR; row++) for (col=0; col < XAR; col++) bitmask[row][col] = 0; /* detect holes and write to bitmask: */ for (row=YAR-1; row >= 0; row--) examine_row(framefragment, bitmask, row, cutoff); for (col=0; col < XAR; col++) examine_col(framefragment, bitmask, col, cutoff); npxi = apply_bitmask(framefragment, bitmask, mask_val); npxt += npxi; if (npxi > 0) ++nprof; if (flag_verbose == 1) { printf("\n"); print_bitmask(bitmask); printf("\n star %d: %d pixels masked\n", patchstars[n].num, npxi); } /* write the modified frame subsection to output frame: */ fits_write_subset(maskedframe, TFLOAT, lowleft, upright, framefragment, &status); fits_print_error(status); } printf(" %d pixels were masked in %d stars.\n", npxt, nprof); fits_close_file(frame, &status); fits_print_error(status); fits_close_file(maskedframe, &status); fits_print_error(status); free(patchstars); return 0; }
int main(int c, char **v) { crypto_pk_t *env; char *str; RSA *rsa; int wantdigest=0; int fname_idx; char *fname=NULL; init_logging(); if (c < 2) { fprintf(stderr, "Hi. I'm tor-checkkey. Tell me a filename that " "has a PEM-encoded RSA public key (like in a cert) and I'll " "dump the modulus. Use the --digest option too and I'll " "dump the digest.\n"); return 1; } if (crypto_global_init(0, NULL, NULL)) { fprintf(stderr, "Couldn't initialize crypto library.\n"); return 1; } if (!strcmp(v[1], "--digest")) { wantdigest = 1; fname_idx = 2; if (c<3) { fprintf(stderr, "too few arguments"); return 1; } } else { wantdigest = 0; fname_idx = 1; } fname = expand_filename(v[fname_idx]); str = read_file_to_str(fname, 0, NULL); tor_free(fname); if (!str) { fprintf(stderr, "Couldn't read %s\n", v[fname_idx]); return 1; } env = crypto_pk_new(); if (crypto_pk_read_public_key_from_string(env, str, strlen(str))<0) { fprintf(stderr, "Couldn't parse key.\n"); return 1; } tor_free(str); if (wantdigest) { char digest[HEX_DIGEST_LEN+1]; if (crypto_pk_get_fingerprint(env, digest, 0)<0) return 1; printf("%s\n",digest); } else { rsa = crypto_pk_get_rsa_(env); str = BN_bn2hex(rsa->n); printf("%s\n", str); } return 0; }
char * authorized_keys_file2(struct passwd *pw) { return expand_filename(options.authorized_keys_file2, pw); }