| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include "fitsio2.h" |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <stddef.h> |
| #include <string.h> |
|
|
| #define FILE_NOT_OPENED 104 |
|
|
| |
| #define SZ_IMPIXFILE 79 |
| #define SZ_IMHDRFILE 79 |
| #define SZ_IMTITLE 79 |
| #define LEN_IMHDR 2052 |
|
|
| |
| #define SZ_IM2PIXFILE 255 |
| #define SZ_IM2HDRFILE 255 |
| #define SZ_IM2TITLE 383 |
| #define LEN_IM2HDR 2046 |
|
|
| |
| #define IM_HDRLEN 12 |
| #define IM_PIXTYPE 16 |
| #define IM_NDIM 20 |
| #define IM_LEN 24 |
| #define IM_PHYSLEN 52 |
| #define IM_PIXOFF 88 |
| #define IM_CTIME 108 |
| #define IM_MTIME 112 |
| #define IM_LIMTIME 116 |
| #define IM_MAX 120 |
| #define IM_MIN 124 |
| #define IM_PIXFILE 412 |
| #define IM_HDRFILE 572 |
| #define IM_TITLE 732 |
|
|
| |
| #define IM2_HDRLEN 6 |
| #define IM2_PIXTYPE 10 |
| #define IM2_SWAPPED 14 |
| #define IM2_NDIM 18 |
| #define IM2_LEN 22 |
| #define IM2_PHYSLEN 50 |
| #define IM2_PIXOFF 86 |
| #define IM2_CTIME 106 |
| #define IM2_MTIME 110 |
| #define IM2_LIMTIME 114 |
| #define IM2_MAX 118 |
| #define IM2_MIN 122 |
| #define IM2_PIXFILE 126 |
| #define IM2_HDRFILE 382 |
| #define IM2_TITLE 638 |
|
|
| |
| #define TY_CHAR 2 |
| #define TY_SHORT 3 |
| #define TY_INT 4 |
| #define TY_LONG 5 |
| #define TY_REAL 6 |
| #define TY_DOUBLE 7 |
| #define TY_COMPLEX 8 |
| #define TY_POINTER 9 |
| #define TY_STRUCT 10 |
| #define TY_USHORT 11 |
| #define TY_UBYTE 12 |
|
|
| #define LEN_PIXHDR 1024 |
| #define MAXINT 2147483647 |
|
|
| static int isirafswapped(char *irafheader, int offset); |
| static int irafgeti4(char *irafheader, int offset); |
| static char *irafgetc2(char *irafheader, int offset, int nc); |
| static char *irafgetc(char *irafheader, int offset, int nc); |
| static char *iraf2str(char *irafstring, int nchar); |
| static char *irafrdhead(const char *filename, int *lihead); |
| static int irafrdimage (char **buffptr, size_t *buffsize, |
| size_t *filesize, int *status); |
| static int iraftofits (char *hdrname, char *irafheader, int nbiraf, |
| char **buffptr, size_t *nbfits, size_t *fitssize, int *status); |
| static char *same_path(char *pixname, const char *hdrname); |
|
|
| static int swaphead=0; |
| static int swapdata=0; |
|
|
| static void irafswap(int bitpix, char *string, int nbytes); |
| static void irafswap2(char *string, int nbytes); |
| static void irafswap4(char *string, int nbytes); |
| static void irafswap8(char *string, int nbytes); |
| static int pix_version (char *irafheader); |
| static int irafncmp (char *irafheader, char *teststring, int nc); |
| static int machswap(void); |
| static int head_version (char *irafheader); |
| static int hgeti4(char* hstring, char* keyword, int* val); |
| static int hgets(char* hstring, char* keyword, int lstr, char* string); |
| static char* hgetc(char* hstring, char* keyword); |
| static char* ksearch(char* hstring, char* keyword); |
| static char *blsearch (char* hstring, char* keyword); |
| static char *strsrch (char* s1, char* s2); |
| static char *strnsrch ( char* s1,char* s2,int ls1); |
| static void hputi4(char* hstring,char* keyword, int ival); |
| static void hputs(char* hstring,char* keyword,char* cval); |
| static void hputcom(char* hstring,char* keyword,char* comment); |
| static void hputl(char* hstring,char* keyword,int lval); |
| static void hputc(char* hstring,char* keyword,char* cval); |
| static int getirafpixname (const char *hdrname, char *irafheader, char *pixfilename, int *status); |
| int iraf2mem(char *filename, char **buffptr, size_t *buffsize, |
| size_t *filesize, int *status); |
|
|
| void ffpmsg(const char *err_message); |
|
|
| |
| |
| |
|
|
| |
| |
|
|
| #if defined (WIN32) |
| #if defined(cfitsio_EXPORTS) |
| #define CFITS_API __declspec(dllexport) |
| #else |
| #define CFITS_API |
| #endif |
| #else |
| #define CFITS_API |
| #endif |
|
|
| int CFITS_API fits_delete_iraf_file(const char *filename, int *status); |
|
|
|
|
| |
| int fits_delete_iraf_file(const char *filename, |
| int *status) |
|
|
| |
| |
| |
| { |
| char *irafheader; |
| int lenirafhead; |
|
|
| char pixfilename[SZ_IM2PIXFILE+1]; |
|
|
| |
| irafheader = irafrdhead(filename, &lenirafhead); |
|
|
| if (!irafheader) |
| { |
| return(*status = FILE_NOT_OPENED); |
| } |
|
|
| getirafpixname (filename, irafheader, pixfilename, status); |
|
|
| |
| free(irafheader); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| remove(filename); |
| remove(pixfilename); |
| |
| return(*status); |
| } |
|
|
| |
| int iraf2mem(char *filename, |
| char **buffptr, |
| size_t *buffsize, |
| size_t *filesize, |
| int *status) |
|
|
| |
| |
| |
| |
| { |
| char *irafheader; |
| int lenirafhead; |
|
|
| *buffptr = NULL; |
| *buffsize = 0; |
| *filesize = 0; |
|
|
| |
| irafheader = irafrdhead(filename, &lenirafhead); |
|
|
| if (!irafheader) |
| { |
| return(*status = FILE_NOT_OPENED); |
| } |
|
|
| |
| iraftofits(filename, irafheader, lenirafhead, buffptr, buffsize, filesize, |
| status); |
|
|
| |
| free(irafheader); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| *filesize = (((*filesize - 1) / 2880 ) + 1 ) * 2880; |
|
|
| |
| irafrdimage(buffptr, buffsize, filesize, status); |
|
|
| return(*status); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| static char *irafrdhead ( |
| const char *filename, |
| int *lihead) |
| { |
| FILE *fd; |
| int nbr; |
| char *irafheader; |
| char errmsg[FLEN_ERRMSG]; |
| long nbhead; |
| int nihead; |
|
|
| *lihead = 0; |
|
|
| |
| fd = fopen (filename, "rb"); |
| if (fd == NULL) { |
| ffpmsg("unable to open IRAF header file:"); |
| ffpmsg(filename); |
| return (NULL); |
| } |
|
|
| |
| if (fseek(fd, 0, 2) != 0) |
| { |
| ffpmsg("IRAFRHEAD: cannot seek in file:"); |
| ffpmsg(filename); |
| return(NULL); |
| } |
|
|
| nbhead = ftell(fd); |
| if (nbhead < 0) |
| { |
| ffpmsg("IRAFRHEAD: cannot get pos. in file:"); |
| ffpmsg(filename); |
| return(NULL); |
| } |
|
|
| if (fseek(fd, 0, 0) != 0) |
| { |
| ffpmsg("IRAFRHEAD: cannot seek to beginning of file:"); |
| ffpmsg(filename); |
| return(NULL); |
| } |
|
|
| |
| nihead = nbhead + 5000; |
| irafheader = (char *) calloc (1, nihead); |
| if (irafheader == NULL) { |
| snprintf(errmsg, FLEN_ERRMSG,"IRAFRHEAD Cannot allocate %d-byte header", |
| nihead); |
| ffpmsg(errmsg); |
| ffpmsg(filename); |
| return (NULL); |
| } |
| *lihead = nihead; |
|
|
| |
| nbr = fread (irafheader, 1, nbhead, fd); |
| fclose (fd); |
|
|
| |
| if (nbr < LEN_PIXHDR) { |
| snprintf(errmsg, FLEN_ERRMSG,"IRAFRHEAD header file: %d / %d bytes read.", |
| nbr,LEN_PIXHDR); |
| ffpmsg(errmsg); |
| ffpmsg(filename); |
| free (irafheader); |
| return (NULL); |
| } |
|
|
| return (irafheader); |
| } |
| |
| static int irafrdimage ( |
| char **buffptr, |
| size_t *buffsize, |
| size_t *filesize, |
| int *status) |
| { |
| FILE *fd; |
| char *bang; |
| int nax = 1, naxis1 = 1, naxis2 = 1, naxis3 = 1, naxis4 = 1, npaxis1 = 1, npaxis2; |
| int bitpix, bytepix, i; |
| char *fitsheader, *image; |
| int nbr, nbimage, nbaxis, nbl, nbdiff; |
| char *pixheader; |
| char *linebuff; |
| int imhver, lpixhead = 0; |
| char pixname[SZ_IM2PIXFILE+1]; |
| char errmsg[FLEN_ERRMSG]; |
| size_t newfilesize; |
| |
| fitsheader = *buffptr; |
|
|
| |
| hgets (fitsheader, "PIXFILE", SZ_IM2PIXFILE, pixname); |
| hgeti4 (fitsheader, "PIXOFF", &lpixhead); |
|
|
| |
| if ((bang = strchr (pixname, '!')) != NULL ) |
| fd = fopen (bang + 1, "rb"); |
| else |
| fd = fopen (pixname, "rb"); |
|
|
| |
| if (!fd) { |
| ffpmsg("IRAFRIMAGE: Cannot open IRAF pixel file:"); |
| ffpmsg(pixname); |
| return (*status = FILE_NOT_OPENED); |
| } |
|
|
| |
| pixheader = (char *) calloc (lpixhead, 1); |
| if (pixheader == NULL) { |
| ffpmsg("IRAFRIMAGE: Cannot alloc memory for pixel header"); |
| ffpmsg(pixname); |
| fclose (fd); |
| return (*status = FILE_NOT_OPENED); |
| } |
| nbr = fread (pixheader, 1, lpixhead, fd); |
|
|
| |
| if (nbr < lpixhead) { |
| snprintf(errmsg, FLEN_ERRMSG,"IRAF pixel file: %d / %d bytes read.", |
| nbr,LEN_PIXHDR); |
| ffpmsg(errmsg); |
| free (pixheader); |
| fclose (fd); |
| return (*status = FILE_NOT_OPENED); |
| } |
|
|
| |
| imhver = pix_version (pixheader); |
| if (imhver < 1) { |
| ffpmsg("File not valid IRAF pixel file:"); |
| ffpmsg(pixname); |
| free (pixheader); |
| fclose (fd); |
| return (*status = FILE_NOT_OPENED); |
| } |
| free (pixheader); |
|
|
| |
| hgeti4 (fitsheader,"NAXIS",&nax); |
| hgeti4 (fitsheader,"NAXIS1",&naxis1); |
| hgeti4 (fitsheader,"NPAXIS1",&npaxis1); |
| if (nax > 1) { |
| hgeti4 (fitsheader,"NAXIS2",&naxis2); |
| hgeti4 (fitsheader,"NPAXIS2",&npaxis2); |
| } |
| if (nax > 2) |
| hgeti4 (fitsheader,"NAXIS3",&naxis3); |
| if (nax > 3) |
| hgeti4 (fitsheader,"NAXIS4",&naxis4); |
|
|
| hgeti4 (fitsheader,"BITPIX",&bitpix); |
| if (bitpix < 0) |
| bytepix = -bitpix / 8; |
| else |
| bytepix = bitpix / 8; |
|
|
| nbimage = naxis1 * naxis2 * naxis3 * naxis4 * bytepix; |
| |
| newfilesize = *filesize + nbimage; |
| newfilesize = (((newfilesize - 1) / 2880 ) + 1 ) * 2880; |
|
|
| if (newfilesize > *buffsize) |
| { |
| fitsheader = (char *) realloc (*buffptr, newfilesize); |
| if (fitsheader == NULL) { |
| snprintf(errmsg, FLEN_ERRMSG,"IRAFRIMAGE Cannot allocate %d-byte image buffer", |
| (int) (*filesize)); |
| ffpmsg(errmsg); |
| ffpmsg(pixname); |
| fclose (fd); |
| return (*status = FILE_NOT_OPENED); |
| } |
| } |
|
|
| *buffptr = fitsheader; |
| *buffsize = newfilesize; |
|
|
| image = fitsheader + *filesize; |
| *filesize = newfilesize; |
|
|
| |
| if (npaxis1 == naxis1) |
| nbr = fread (image, 1, nbimage, fd); |
|
|
| |
| else { |
| nbdiff = (npaxis1 - naxis1) * bytepix; |
| nbaxis = naxis1 * bytepix; |
| linebuff = image; |
| nbr = 0; |
| if (naxis2 == 1 && naxis3 > 1) |
| naxis2 = naxis3; |
| for (i = 0; i < naxis2; i++) { |
| nbl = fread (linebuff, 1, nbaxis, fd); |
| nbr = nbr + nbl; |
| fseek (fd, nbdiff, 1); |
| linebuff = linebuff + nbaxis; |
| } |
| } |
| fclose (fd); |
|
|
| |
| if (nbr < nbimage) { |
| snprintf(errmsg, FLEN_ERRMSG,"IRAF pixel file: %d / %d bytes read.", |
| nbr,nbimage); |
| ffpmsg(errmsg); |
| ffpmsg(pixname); |
| return (*status = FILE_NOT_OPENED); |
| } |
|
|
| |
| if (swapdata) |
| irafswap (bitpix, image, nbimage); |
|
|
| return (*status); |
| } |
| |
| |
|
|
| static int head_version ( |
| char *irafheader) |
|
|
| { |
|
|
| |
| if (irafncmp (irafheader, "imhdr", 5) != 0 ) { |
| if (strncmp (irafheader, "imhv2", 5) != 0) |
| return (0); |
| else |
| return (2); |
| } |
| else |
| return (1); |
| } |
|
|
| |
| |
|
|
| static int pix_version ( |
| char *irafheader) |
| { |
|
|
| |
| if (irafncmp (irafheader, "impix", 5) != 0) { |
| if (strncmp (irafheader, "impv2", 5) != 0) |
| return (0); |
| else |
| return (2); |
| } |
| else |
| return (1); |
| } |
|
|
| |
| |
| |
|
|
| static int irafncmp ( |
| |
| char *irafheader, |
| char *teststring, |
| int nc) |
|
|
| { |
| char *line; |
|
|
| if ((line = iraf2str (irafheader, nc)) == NULL) |
| return (1); |
| if (strncmp (line, teststring, nc) == 0) { |
| free (line); |
| return (0); |
| } |
| else { |
| free (line); |
| return (1); |
| } |
| } |
| |
|
|
| |
|
|
| static int iraftofits ( |
| char *hdrname, |
| char *irafheader, |
| int nbiraf, |
| char **buffptr, |
| size_t *nbfits, |
| size_t *fitssize, |
| |
| int *status) |
| { |
| char *objname; |
| int lstr, i, j, k, ib, nax, nbits; |
| char *pixname, *newpixname, *bang, *chead; |
| char *fitsheader; |
| int nblock, nlines; |
| char *fhead, *fhead1, *fp, endline[81]; |
| char irafchar; |
| char fitsline[81]; |
| int pixtype; |
| int imhver, n, imu, pixoff, impixoff; |
| |
| int imndim, imlen, imphyslen, impixtype; |
| char errmsg[FLEN_ERRMSG]; |
|
|
| |
| (void)strncpy (endline,"END", 3); |
| for (i = 3; i < 80; i++) |
| endline[i] = ' '; |
| endline[80] = 0; |
|
|
| |
| imhver = head_version (irafheader); |
| if (imhver < 1) { |
| ffpmsg("File not valid IRAF image header"); |
| ffpmsg(hdrname); |
| return(*status = FILE_NOT_OPENED); |
| } |
| if (imhver == 2) { |
| nlines = 24 + ((nbiraf - LEN_IM2HDR) / 81); |
| imndim = IM2_NDIM; |
| imlen = IM2_LEN; |
| imphyslen = IM2_PHYSLEN; |
| impixtype = IM2_PIXTYPE; |
| impixoff = IM2_PIXOFF; |
| |
| |
| |
| } |
| else { |
| nlines = 24 + ((nbiraf - LEN_IMHDR) / 162); |
| imndim = IM_NDIM; |
| imlen = IM_LEN; |
| imphyslen = IM_PHYSLEN; |
| impixtype = IM_PIXTYPE; |
| impixoff = IM_PIXOFF; |
| |
| |
| |
| } |
|
|
| |
| nblock = (nlines * 80) / 2880; |
| *nbfits = (nblock + 5) * 2880 + 4; |
| fitsheader = (char *) calloc (*nbfits, 1); |
| if (fitsheader == NULL) { |
| snprintf(errmsg, FLEN_ERRMSG,"IRAF2FITS Cannot allocate %d-byte FITS header", |
| (int) (*nbfits)); |
| ffpmsg(hdrname); |
| return (*status = FILE_NOT_OPENED); |
| } |
|
|
| fhead = fitsheader; |
| *buffptr = fitsheader; |
| (void)strncpy (fitsheader, endline, 80); |
| hputl (fitsheader, "SIMPLE", 1); |
| fhead = fhead + 80; |
|
|
| |
| |
| |
| |
| |
| |
|
|
| swaphead = isirafswapped(irafheader, impixtype); |
| if (imhver == 1) |
| swapdata = swaphead; |
| else |
| swapdata = irafgeti4 (irafheader, IM2_SWAPPED); |
|
|
| |
| pixtype = irafgeti4 (irafheader, impixtype); |
| switch (pixtype) { |
| case TY_CHAR: |
| nbits = 8; |
| break; |
| case TY_UBYTE: |
| nbits = 8; |
| break; |
| case TY_SHORT: |
| nbits = 16; |
| break; |
| case TY_USHORT: |
| nbits = -16; |
| break; |
| case TY_INT: |
| case TY_LONG: |
| nbits = 32; |
| break; |
| case TY_REAL: |
| nbits = -32; |
| break; |
| case TY_DOUBLE: |
| nbits = -64; |
| break; |
| default: |
| snprintf(errmsg,FLEN_ERRMSG,"Unsupported IRAF data type: %d", pixtype); |
| ffpmsg(errmsg); |
| ffpmsg(hdrname); |
| return (*status = FILE_NOT_OPENED); |
| } |
| hputi4 (fitsheader,"BITPIX",nbits); |
| hputcom (fitsheader,"BITPIX", "IRAF .imh pixel type"); |
| fhead = fhead + 80; |
|
|
| |
| nax = irafgeti4 (irafheader, imndim); |
| hputi4 (fitsheader,"NAXIS",nax); |
| hputcom (fitsheader,"NAXIS", "IRAF .imh naxis"); |
| fhead = fhead + 80; |
|
|
| n = irafgeti4 (irafheader, imlen); |
| hputi4 (fitsheader, "NAXIS1", n); |
| hputcom (fitsheader,"NAXIS1", "IRAF .imh image naxis[1]"); |
| fhead = fhead + 80; |
|
|
| if (nax > 1) { |
| n = irafgeti4 (irafheader, imlen+4); |
| hputi4 (fitsheader, "NAXIS2", n); |
| hputcom (fitsheader,"NAXIS2", "IRAF .imh image naxis[2]"); |
| fhead = fhead + 80; |
| } |
| if (nax > 2) { |
| n = irafgeti4 (irafheader, imlen+8); |
| hputi4 (fitsheader, "NAXIS3", n); |
| hputcom (fitsheader,"NAXIS3", "IRAF .imh image naxis[3]"); |
| fhead = fhead + 80; |
| } |
| if (nax > 3) { |
| n = irafgeti4 (irafheader, imlen+12); |
| hputi4 (fitsheader, "NAXIS4", n); |
| hputcom (fitsheader,"NAXIS4", "IRAF .imh image naxis[4]"); |
| fhead = fhead + 80; |
| } |
|
|
| |
| if (imhver == 2) |
| objname = irafgetc (irafheader, IM2_TITLE, SZ_IM2TITLE); |
| else |
| objname = irafgetc2 (irafheader, IM_TITLE, SZ_IMTITLE); |
| if ((lstr = strlen (objname)) < 8) { |
| for (i = lstr; i < 8; i++) |
| objname[i] = ' '; |
| objname[8] = 0; |
| } |
| hputs (fitsheader,"OBJECT",objname); |
| hputcom (fitsheader,"OBJECT", "IRAF .imh title"); |
| free (objname); |
| fhead = fhead + 80; |
|
|
| |
| n = irafgeti4 (irafheader, imphyslen); |
| hputi4 (fitsheader, "NPAXIS1", n); |
| hputcom (fitsheader,"NPAXIS1", "IRAF .imh physical naxis[1]"); |
| fhead = fhead + 80; |
| if (nax > 1) { |
| n = irafgeti4 (irafheader, imphyslen+4); |
| hputi4 (fitsheader, "NPAXIS2", n); |
| hputcom (fitsheader,"NPAXIS2", "IRAF .imh physical naxis[2]"); |
| fhead = fhead + 80; |
| } |
| if (nax > 2) { |
| n = irafgeti4 (irafheader, imphyslen+8); |
| hputi4 (fitsheader, "NPAXIS3", n); |
| hputcom (fitsheader,"NPAXIS3", "IRAF .imh physical naxis[3]"); |
| fhead = fhead + 80; |
| } |
| if (nax > 3) { |
| n = irafgeti4 (irafheader, imphyslen+12); |
| hputi4 (fitsheader, "NPAXIS4", n); |
| hputcom (fitsheader,"NPAXIS4", "IRAF .imh physical naxis[4]"); |
| fhead = fhead + 80; |
| } |
|
|
| |
| hputs (fitsheader,"IMHFILE",hdrname); |
| hputcom (fitsheader,"IMHFILE", "IRAF header file name"); |
| fhead = fhead + 80; |
|
|
| |
| if (imhver == 2) |
| pixname = irafgetc (irafheader, IM2_PIXFILE, SZ_IM2PIXFILE); |
| else |
| pixname = irafgetc2 (irafheader, IM_PIXFILE, SZ_IMPIXFILE); |
| if (strncmp(pixname, "HDR", 3) == 0 ) { |
| newpixname = same_path (pixname, hdrname); |
| if (newpixname) { |
| free (pixname); |
| pixname = newpixname; |
| } |
| } |
| if (strchr (pixname, '/') == NULL && strchr (pixname, '$') == NULL) { |
| newpixname = same_path (pixname, hdrname); |
| if (newpixname) { |
| free (pixname); |
| pixname = newpixname; |
| } |
| } |
| |
| if ((bang = strchr (pixname, '!')) != NULL ) |
| hputs (fitsheader,"PIXFILE",bang+1); |
| else |
| hputs (fitsheader,"PIXFILE",pixname); |
| free (pixname); |
| hputcom (fitsheader,"PIXFILE", "IRAF .pix pixel file"); |
| fhead = fhead + 80; |
|
|
| |
| pixoff = irafgeti4 (irafheader, impixoff); |
| pixoff = (pixoff - 1) * 2; |
| hputi4 (fitsheader, "PIXOFF", pixoff); |
| hputcom (fitsheader,"PIXOFF", "IRAF .pix pixel offset (Do not change!)"); |
| fhead = fhead + 80; |
|
|
| |
| hputi4 (fitsheader,"IMHVER",imhver); |
| hputcom (fitsheader,"IMHVER", "IRAF .imh format version (1 or 2)"); |
| fhead = fhead + 80; |
|
|
| |
| if (swapdata) |
| hputl (fitsheader, "PIXSWAP", 1); |
| else |
| hputl (fitsheader, "PIXSWAP", 0); |
| hputcom (fitsheader,"PIXSWAP", "IRAF pixels, FITS byte orders differ if T"); |
| fhead = fhead + 80; |
|
|
| |
| fitsline[80] = 0; |
| if (imhver == 2) { |
| imu = LEN_IM2HDR; |
| chead = irafheader; |
| j = 0; |
| for (k = 0; k < 80; k++) |
| fitsline[k] = ' '; |
| for (i = imu; i < nbiraf; i++) { |
| irafchar = chead[i]; |
| if (irafchar == 0) |
| break; |
| else if (irafchar == 10) { |
| (void)strncpy (fhead, fitsline, 80); |
| |
| if (strncmp (fitsline, "OBJECT ", 7) != 0) { |
| fhead = fhead + 80; |
| } |
| for (k = 0; k < 80; k++) |
| fitsline[k] = ' '; |
| j = 0; |
| } |
| else { |
| if (j > 80) { |
| if (strncmp (fitsline, "OBJECT ", 7) != 0) { |
| (void)strncpy (fhead, fitsline, 80); |
| |
| j = 9; |
| fhead = fhead + 80; |
| } |
| for (k = 0; k < 80; k++) |
| fitsline[k] = ' '; |
| } |
| if (irafchar > 32 && irafchar < 127) |
| fitsline[j] = irafchar; |
| j++; |
| } |
| } |
| } |
| else { |
| imu = LEN_IMHDR; |
| chead = irafheader; |
| if (swaphead == 1) |
| ib = 0; |
| else |
| ib = 1; |
| for (k = 0; k < 80; k++) |
| fitsline[k] = ' '; |
| j = 0; |
| for (i = imu; i < nbiraf; i=i+2) { |
| irafchar = chead[i+ib]; |
| if (irafchar == 0) |
| break; |
| else if (irafchar == 10) { |
| if (strncmp (fitsline, "OBJECT ", 7) != 0) { |
| (void)strncpy (fhead, fitsline, 80); |
| fhead = fhead + 80; |
| } |
| |
| j = 0; |
| for (k = 0; k < 80; k++) |
| fitsline[k] = ' '; |
| } |
| else { |
| if (j > 80) { |
| if (strncmp (fitsline, "OBJECT ", 7) != 0) { |
| (void)strncpy (fhead, fitsline, 80); |
| j = 9; |
| fhead = fhead + 80; |
| } |
| |
| for (k = 0; k < 80; k++) |
| fitsline[k] = ' '; |
| } |
| if (irafchar > 32 && irafchar < 127) |
| fitsline[j] = irafchar; |
| j++; |
| } |
| } |
| } |
|
|
| |
| (void)strncpy (fhead, endline, 80); |
|
|
| |
| fhead = ksearch (fitsheader, "END") + 80; |
| nblock = *nbfits / 2880; |
| fhead1 = fitsheader + (nblock * 2880); |
| *fitssize = fhead - fitsheader; |
|
|
| |
| strncpy (endline," ",3); |
| for (fp = fhead; fp < fhead1; fp = fp + 80) { |
| (void)strncpy (fp, endline,80); |
| } |
|
|
| return (*status); |
| } |
| |
|
|
| |
|
|
| static int getirafpixname ( |
| const char *hdrname, |
| char *irafheader, |
| char *pixfilename, |
| int *status) |
| { |
| int imhver; |
| char *pixname, *newpixname, *bang; |
|
|
| |
| imhver = head_version (irafheader); |
| if (imhver < 1) { |
| ffpmsg("File not valid IRAF image header"); |
| ffpmsg(hdrname); |
| return(*status = FILE_NOT_OPENED); |
| } |
|
|
| |
| if (imhver == 2) |
| pixname = irafgetc (irafheader, IM2_PIXFILE, SZ_IM2PIXFILE); |
| else |
| pixname = irafgetc2 (irafheader, IM_PIXFILE, SZ_IMPIXFILE); |
|
|
| if (strncmp(pixname, "HDR", 3) == 0 ) { |
| newpixname = same_path (pixname, hdrname); |
| if (newpixname) { |
| free (pixname); |
| pixname = newpixname; |
| } |
| } |
|
|
| if (strchr (pixname, '/') == NULL && strchr (pixname, '$') == NULL) { |
| newpixname = same_path (pixname, hdrname); |
| if (newpixname) { |
| free (pixname); |
| pixname = newpixname; |
| } |
| } |
| |
| if ((bang = strchr (pixname, '!')) != NULL ) |
| strcpy(pixfilename,bang+1); |
| else |
| strcpy(pixfilename,pixname); |
|
|
| free (pixname); |
|
|
| return (*status); |
| } |
|
|
| |
| |
|
|
| static char *same_path ( |
| |
| char *pixname, |
| const char *hdrname) |
|
|
| { |
| int len; |
| char *newpixname; |
|
|
| |
| |
|
|
| newpixname = (char *) calloc (2*SZ_IM2PIXFILE+1, sizeof (char)); |
| if (newpixname == NULL) { |
| ffpmsg("iraffits same_path: Cannot alloc memory for newpixname"); |
| return (NULL); |
| } |
|
|
| |
| if (strncmp(pixname, "HDR$", 4) == 0 ) { |
| (void)strncpy (newpixname, hdrname, SZ_IM2PIXFILE); |
|
|
| |
| len = strlen (newpixname); |
| #ifndef VMS |
| while( (len > 0) && (newpixname[len-1] != '/') ) |
| #else |
| while( (len > 0) && (newpixname[len-1] != ']') && (newpixname[len-1] != ':') ) |
| #endif |
| len--; |
|
|
| |
| newpixname[len] = '\0'; |
| (void)strncat (newpixname, &pixname[4], SZ_IM2PIXFILE); |
| } |
|
|
| |
| else if (strchr (pixname, '/') == NULL && strchr (pixname, '$') == NULL) { |
| (void)strncpy (newpixname, hdrname, SZ_IM2PIXFILE); |
|
|
| |
| len = strlen (newpixname); |
| #ifndef VMS |
| while( (len > 0) && (newpixname[len-1] != '/') ) |
| #else |
| while( (len > 0) && (newpixname[len-1] != ']') && (newpixname[len-1] != ':') ) |
| #endif |
| len--; |
|
|
| |
| newpixname[len] = '\0'; |
| (void)strncat (newpixname, pixname, SZ_IM2PIXFILE); |
| } |
|
|
| |
| else if (strncmp (pixname, "HDR", 3) == 0) { |
|
|
| |
| (void)strncpy (newpixname, hdrname, SZ_IM2PIXFILE); |
| len = strlen (newpixname); |
| newpixname[len-3] = 'p'; |
| newpixname[len-2] = 'i'; |
| newpixname[len-1] = 'x'; |
| } |
|
|
| return (newpixname); |
| } |
|
|
| |
| static int isirafswapped ( |
| |
| char *irafheader, |
| int offset) |
|
|
| |
| |
| |
| |
| |
| |
|
|
| { |
| int swapped; |
|
|
| if (irafheader[offset] != 0) |
| swapped = 1; |
| else |
| swapped = 0; |
|
|
| return (swapped); |
| } |
| |
| static int irafgeti4 ( |
| |
| char *irafheader, |
| int offset) |
|
|
| { |
| char *ctemp, *cheader; |
| int temp; |
|
|
| cheader = irafheader; |
| ctemp = (char *) &temp; |
|
|
| if (machswap() != swaphead) { |
| ctemp[3] = cheader[offset]; |
| ctemp[2] = cheader[offset+1]; |
| ctemp[1] = cheader[offset+2]; |
| ctemp[0] = cheader[offset+3]; |
| } |
| else { |
| ctemp[0] = cheader[offset]; |
| ctemp[1] = cheader[offset+1]; |
| ctemp[2] = cheader[offset+2]; |
| ctemp[3] = cheader[offset+3]; |
| } |
| return (temp); |
| } |
|
|
| |
| |
|
|
| static char *irafgetc2 ( |
| |
| char *irafheader, |
| int offset, |
| int nc) |
|
|
| { |
| char *irafstring, *string; |
|
|
| irafstring = irafgetc (irafheader, offset, 2*(nc+1)); |
| string = iraf2str (irafstring, nc); |
| free (irafstring); |
|
|
| return (string); |
| } |
|
|
| |
| |
|
|
| static char *irafgetc ( |
| |
| char *irafheader, |
| int offset, |
| int nc) |
|
|
| { |
| char *ctemp, *cheader; |
| int i; |
|
|
| cheader = irafheader; |
| ctemp = (char *) calloc (nc+1, 1); |
| if (ctemp == NULL) { |
| ffpmsg("IRAFGETC Cannot allocate memory for string variable"); |
| return (NULL); |
| } |
| for (i = 0; i < nc; i++) { |
| ctemp[i] = cheader[offset+i]; |
| if (ctemp[i] > 0 && ctemp[i] < 32) |
| ctemp[i] = ' '; |
| } |
|
|
| return (ctemp); |
| } |
|
|
| |
| |
|
|
| static char *iraf2str ( |
| |
| char *irafstring, |
| int nchar) |
| { |
| char *string; |
| int i, j; |
|
|
| string = (char *) calloc (nchar+1, 1); |
| if (string == NULL) { |
| ffpmsg("IRAF2STR Cannot allocate memory for string variable"); |
| return (NULL); |
| } |
|
|
| |
| |
|
|
| if (irafstring[0] != 0) |
| j = 0; |
| else |
| j = 1; |
|
|
| |
| for (i = 0; i < nchar; i++) { |
| string[i] = irafstring[j]; |
| j = j + 2; |
| } |
|
|
| return (string); |
| } |
|
|
| |
| |
|
|
| static void irafswap ( |
| |
| int bitpix, |
| |
| |
| char *string, |
| int nbytes) |
|
|
| { |
| switch (bitpix) { |
|
|
| case 16: |
| if (nbytes < 2) return; |
| irafswap2 (string,nbytes); |
| break; |
|
|
| case 32: |
| if (nbytes < 4) return; |
| irafswap4 (string,nbytes); |
| break; |
|
|
| case -16: |
| if (nbytes < 2) return; |
| irafswap2 (string,nbytes); |
| break; |
|
|
| case -32: |
| if (nbytes < 4) return; |
| irafswap4 (string,nbytes); |
| break; |
|
|
| case -64: |
| if (nbytes < 8) return; |
| irafswap8 (string,nbytes); |
| break; |
|
|
| } |
| return; |
| } |
|
|
| |
| |
|
|
| static void irafswap2 ( |
| |
| char *string, |
| int nbytes) |
|
|
| { |
| char *sbyte, temp, *slast; |
|
|
| slast = string + nbytes; |
| sbyte = string; |
| while (sbyte < slast) { |
| temp = sbyte[0]; |
| sbyte[0] = sbyte[1]; |
| sbyte[1] = temp; |
| sbyte= sbyte + 2; |
| } |
| return; |
| } |
|
|
| |
| |
|
|
| static void irafswap4 ( |
| |
| char *string, |
| int nbytes) |
|
|
| { |
| char *sbyte, *slast; |
| char temp0, temp1, temp2, temp3; |
|
|
| slast = string + nbytes; |
| sbyte = string; |
| while (sbyte < slast) { |
| temp3 = sbyte[0]; |
| temp2 = sbyte[1]; |
| temp1 = sbyte[2]; |
| temp0 = sbyte[3]; |
| sbyte[0] = temp0; |
| sbyte[1] = temp1; |
| sbyte[2] = temp2; |
| sbyte[3] = temp3; |
| sbyte = sbyte + 4; |
| } |
|
|
| return; |
| } |
|
|
| |
| |
|
|
| static void irafswap8 ( |
| |
| char *string, |
| int nbytes) |
|
|
| { |
| char *sbyte, *slast; |
| char temp[8]; |
|
|
| slast = string + nbytes; |
| sbyte = string; |
| while (sbyte < slast) { |
| temp[7] = sbyte[0]; |
| temp[6] = sbyte[1]; |
| temp[5] = sbyte[2]; |
| temp[4] = sbyte[3]; |
| temp[3] = sbyte[4]; |
| temp[2] = sbyte[5]; |
| temp[1] = sbyte[6]; |
| temp[0] = sbyte[7]; |
| sbyte[0] = temp[0]; |
| sbyte[1] = temp[1]; |
| sbyte[2] = temp[2]; |
| sbyte[3] = temp[3]; |
| sbyte[4] = temp[4]; |
| sbyte[5] = temp[5]; |
| sbyte[6] = temp[6]; |
| sbyte[7] = temp[7]; |
| sbyte = sbyte + 8; |
| } |
| return; |
| } |
|
|
| |
| static int |
| machswap (void) |
|
|
| { |
| char *ctest; |
| int itest; |
|
|
| itest = 1; |
| ctest = (char *)&itest; |
| if (*ctest) |
| return (1); |
| else |
| return (0); |
| } |
|
|
| |
| |
| |
|
|
|
|
| static int lhead0 = 0; |
|
|
| |
|
|
| |
|
|
| static int |
| hgeti4 (hstring,keyword,ival) |
|
|
| char *hstring; |
| |
| char *keyword; |
| |
| |
| |
| |
| int *ival; |
| { |
| char *value; |
| double dval; |
| int minint; |
| char val[30]; |
|
|
| |
| value = hgetc (hstring,keyword); |
|
|
| |
| if (value != NULL) { |
| minint = -MAXINT - 1; |
| if (strlen(value) > 29) |
| return(0); |
| strcpy (val, value); |
| dval = atof (val); |
| if (dval+0.001 > MAXINT) |
| *ival = MAXINT; |
| else if (dval >= 0) |
| *ival = (int) (dval + 0.001); |
| else if (dval-0.001 < minint) |
| *ival = minint; |
| else |
| *ival = (int) (dval - 0.001); |
| return (1); |
| } |
| else { |
| return (0); |
| } |
| } |
|
|
| |
| |
|
|
| static int |
| hgets (hstring, keyword, lstr, str) |
|
|
| char *hstring; |
| |
| char *keyword; |
| |
| |
| |
| |
| int lstr; |
| char *str; |
| { |
| char *value; |
| int lval; |
|
|
| |
| value = hgetc (hstring,keyword); |
|
|
| if (value != NULL) { |
| lval = strlen (value); |
| if (lval < lstr) |
| strcpy (str, value); |
| else if (lstr > 1) { |
| strncpy (str, value, lstr-1); |
| str[lstr-1]=0; |
| } |
| else { |
| str[0] = value[0]; |
| } |
| return (1); |
| } |
| else |
| return (0); |
| } |
|
|
| |
| |
|
|
| static char * |
| hgetc (hstring,keyword0) |
|
|
| char *hstring; |
| |
| char *keyword0; |
| |
| |
| |
| |
| { |
| static char cval[80]; |
| char *value; |
| char cwhite[2]; |
| char squot[2], dquot[2], lbracket[2], rbracket[2], slash[2], comma[2]; |
| char keyword[81]; |
| char line[100]; |
| char *vpos, *cpar = NULL; |
| char *q1, *q2 = NULL, *v1, *v2, *c1, *brack1, *brack2; |
| char *saveptr; |
| int ipar, i; |
|
|
| squot[0] = 39; |
| squot[1] = 0; |
| dquot[0] = 34; |
| dquot[1] = 0; |
| lbracket[0] = 91; |
| lbracket[1] = 0; |
| comma[0] = 44; |
| comma[1] = 0; |
| rbracket[0] = 93; |
| rbracket[1] = 0; |
| slash[0] = 47; |
| slash[1] = 0; |
|
|
| |
| strncpy (keyword,keyword0, sizeof(keyword)-1); |
| keyword[80]=0; |
| brack1 = strsrch (keyword,lbracket); |
| if (brack1 == NULL) |
| brack1 = strsrch (keyword,comma); |
| if (brack1 != NULL) { |
| *brack1 = '\0'; |
| brack1++; |
| } |
|
|
| |
| vpos = ksearch (hstring,keyword); |
|
|
| |
| if (vpos == NULL) { |
| return (NULL); |
| } |
|
|
| |
| for (i = 0; i < 100; i++) |
| line[i] = 0; |
|
|
| |
|
|
| |
| strncpy (line,vpos,80); |
|
|
| |
| q1 = strsrch (line,squot); |
| c1 = strsrch (line,slash); |
| if (q1 != NULL) { |
| if (c1 != NULL && q1 < c1) |
| q2 = strsrch (q1+1,squot); |
| else if (c1 == NULL) |
| q2 = strsrch (q1+1,squot); |
| else |
| q1 = NULL; |
| } |
| else { |
| q1 = strsrch (line,dquot); |
| if (q1 != NULL) { |
| if (c1 != NULL && q1 < c1) |
| q2 = strsrch (q1+1,dquot); |
| else if (c1 == NULL) |
| q2 = strsrch (q1+1,dquot); |
| else |
| q1 = NULL; |
| } |
| else { |
| q1 = NULL; |
| q2 = line + 10; |
| } |
| } |
|
|
| |
| if (q1 != NULL) { |
| v1 = q1 + 1; |
| v2 = q2; |
| c1 = strsrch (q2,"/"); |
| } |
| else { |
| v1 = strsrch (line,"=") + 1; |
| c1 = strsrch (line,"/"); |
| if (c1 != NULL) |
| v2 = c1; |
| else |
| v2 = line + 79; |
| } |
|
|
| |
| while (*v1 == ' ' && v1 < v2) { |
| v1++; |
| } |
|
|
| |
| *v2 = '\0'; |
| v2--; |
| while (*v2 == ' ' && v2 > v1) { |
| *v2 = '\0'; |
| v2--; |
| } |
|
|
| if (!strcmp (v1, "-0")) |
| v1++; |
| strcpy (cval,v1); |
| value = cval; |
|
|
| |
| if (brack1 != NULL) { |
| brack2 = strsrch (brack1,rbracket); |
| if (brack2 != NULL) |
| *brack2 = '\0'; |
| ipar = atoi (brack1); |
| if (ipar > 0) { |
| cwhite[0] = ' '; |
| cwhite[1] = '\0'; |
| for (i = 1; i <= ipar; i++) { |
| cpar = ffstrtok (v1,cwhite,&saveptr); |
| v1 = NULL; |
| } |
| if (cpar != NULL) { |
| strcpy (cval,cpar); |
| } |
| else |
| value = NULL; |
| } |
| } |
|
|
| return (value); |
| } |
|
|
|
|
| |
| |
|
|
| static char * |
| blsearch (hstring,keyword) |
|
|
| |
| |
| |
|
|
| char *hstring; |
| |
| |
| |
| |
| char *keyword; |
| |
| |
| |
| |
| { |
| char *loc, *headnext, *headlast, *pval, *lc, *line; |
| char *bval; |
| int icol, nextchar, lkey, nleft, lhstr; |
|
|
| pval = 0; |
|
|
| |
| if (lhead0) |
| lhstr = lhead0; |
| else { |
| lhstr = 0; |
| while (lhstr < 57600 && hstring[lhstr] != 0) |
| lhstr++; |
| } |
| headlast = hstring + lhstr; |
| headnext = hstring; |
| pval = NULL; |
| while (headnext < headlast) { |
| nleft = headlast - headnext; |
| loc = strnsrch (headnext, keyword, nleft); |
|
|
| |
| if (loc == NULL) { |
| break; |
| } |
|
|
| icol = (loc - hstring) % 80; |
| lkey = strlen (keyword); |
| nextchar = (int) *(loc + lkey); |
|
|
| |
| if (icol > 7) |
| headnext = loc + 1; |
|
|
| |
| else if (nextchar != 61 && nextchar > 32 && nextchar < 127) |
| headnext = loc + 1; |
|
|
| |
| else { |
| line = loc - icol; |
| for (lc = line; lc < loc; lc++) { |
| if (*lc != ' ') |
| headnext = loc + 1; |
| } |
|
|
| |
| if (loc >= headnext) { |
| pval = line; |
| break; |
| } |
| } |
| } |
|
|
| |
| if (pval == NULL) |
| return (pval); |
|
|
| |
| if (pval == hstring) |
| return (NULL); |
|
|
| |
| bval = pval - 80; |
| while (!strncmp (bval," ",8)) |
| bval = bval - 80; |
| bval = bval + 80; |
|
|
| |
| if (bval < pval) |
| return (bval); |
| else |
| return (NULL); |
| } |
|
|
|
|
| |
| |
|
|
| static char *ksearch (hstring,keyword) |
|
|
| |
| |
| |
|
|
| char *hstring; |
| |
| |
| |
| |
| char *keyword; |
| |
| |
| |
| |
| { |
| char *loc, *headnext, *headlast, *pval, *lc, *line; |
| int icol, nextchar, lkey, nleft, lhstr; |
|
|
| pval = 0; |
|
|
| |
| if (lhead0) |
| lhstr = lhead0; |
| else { |
| lhstr = 0; |
| while (lhstr < 57600 && hstring[lhstr] != 0) |
| lhstr++; |
| } |
| headlast = hstring + lhstr; |
| headnext = hstring; |
| pval = NULL; |
| while (headnext < headlast) { |
| nleft = headlast - headnext; |
| loc = strnsrch (headnext, keyword, nleft); |
|
|
| |
| if (loc == NULL) { |
| break; |
| } |
|
|
| icol = (loc - hstring) % 80; |
| lkey = strlen (keyword); |
| nextchar = (int) *(loc + lkey); |
|
|
| |
| if (icol > 7) |
| headnext = loc + 1; |
|
|
| |
| else if (nextchar != 61 && nextchar > 32 && nextchar < 127) |
| headnext = loc + 1; |
|
|
| |
| else { |
| line = loc - icol; |
| for (lc = line; lc < loc; lc++) { |
| if (*lc != ' ') |
| headnext = loc + 1; |
| } |
|
|
| |
| if (loc >= headnext) { |
| pval = line; |
| break; |
| } |
| } |
| } |
|
|
| |
| return (pval); |
|
|
| } |
|
|
| |
| |
|
|
| static char * |
| strsrch (s1, s2) |
|
|
| char *s1; |
| char *s2; |
|
|
| { |
| int ls1; |
| ls1 = strlen (s1); |
| return (strnsrch (s1, s2, ls1)); |
| } |
|
|
| |
| |
|
|
| static char * |
| strnsrch (s1, s2, ls1) |
|
|
| char *s1; |
| char *s2; |
| int ls1; |
|
|
| { |
| char *s,*s1e; |
| char cfirst,clast; |
| int i,ls2; |
|
|
| |
| if (s1 == NULL || s2 == NULL) |
| return (NULL); |
|
|
| |
| ls2 = strlen (s2); |
| if (ls2 ==0) |
| return (s1); |
|
|
| |
| if (ls1 ==0) |
| return (NULL); |
|
|
| cfirst = s2[0]; |
| clast = s2[ls2-1]; |
| s1e = s1 + ls1 - ls2 + 1; |
| s = s1; |
| while (s < s1e) { |
|
|
| |
| if (*s == cfirst) { |
|
|
| |
| if (ls2 == 1) |
| return (s); |
|
|
| |
| if (s[ls2-1] == clast) { |
|
|
| |
| if (ls2 == 2) |
| return (s); |
|
|
| |
| i = 1; |
| while (i < ls2 && s[i] == s2[i]) |
| i++; |
|
|
| |
| if (i >= ls2) |
| return (s); |
| } |
| } |
| s++; |
| } |
| return (NULL); |
| } |
|
|
| |
| |
| |
| |
|
|
| static void |
| hputi4 (hstring,keyword,ival) |
|
|
| char *hstring; |
| |
| |
| |
|
|
| char *keyword; |
| |
| |
| |
| int ival; |
| { |
| char value[30]; |
|
|
| |
| snprintf (value,30,"%d",ival); |
|
|
| |
| hputc (hstring,keyword,value); |
|
|
| |
| return; |
| } |
|
|
| |
|
|
| |
|
|
| static void |
| hputl (hstring, keyword,lval) |
|
|
| char *hstring; |
| char *keyword; |
| int lval; |
| { |
| char value[8]; |
|
|
| |
| if (lval) |
| strcpy (value, "T"); |
| else |
| strcpy (value, "F"); |
|
|
| |
| hputc (hstring,keyword,value); |
|
|
| |
| return; |
| } |
|
|
| |
|
|
| |
|
|
| static void |
| hputs (hstring,keyword,cval) |
|
|
| char *hstring; |
| char *keyword; |
| char *cval; |
| |
| { |
| char squot = 39; |
| char value[70]; |
| int lcval; |
|
|
| |
|
|
| lcval = strlen (cval); |
| if (lcval > 67) |
| lcval = 67; |
|
|
| |
| value[0] = squot; |
| strncpy (&value[1],cval,lcval); |
| value[lcval+1] = squot; |
| value[lcval+2] = 0; |
|
|
| |
| hputc (hstring,keyword,value); |
|
|
| |
| return; |
| } |
|
|
| |
| |
|
|
| static void |
| hputc (hstring,keyword,value) |
|
|
| char *hstring; |
| char *keyword; |
| char *value; |
| |
| { |
| char squot = 39; |
| char line[100]; |
| char newcom[50]; |
| char blank[80]; |
| char *v, *vp, *v1, *v2, *q1, *q2, *c1, *ve; |
| int lkeyword, lcom, lval, lc, i; |
|
|
| for (i = 0; i < 80; i++) |
| blank[i] = ' '; |
|
|
| |
| lkeyword = strlen (keyword); |
| lval = strlen (value); |
|
|
| |
| if (lkeyword == 7 && (strncmp (keyword,"COMMENT",7) == 0 || |
| strncmp (keyword,"HISTORY",7) == 0)) { |
|
|
| |
| v1 = ksearch (hstring,"END"); |
| v2 = v1 + 80; |
|
|
| |
| strncpy (v2, v1, 80); |
|
|
| |
| strncpy (v1,keyword,7); |
|
|
| |
| for (vp = v1+lkeyword; vp < v2; vp++) |
| *vp = ' '; |
|
|
| |
| strncpy (v1+9,value,lval); |
| return; |
| } |
|
|
| |
| else |
| v1 = ksearch (hstring,keyword); |
|
|
| |
| if (v1 == NULL) { |
| |
| |
| v1 = blsearch (hstring, "END"); |
| |
| |
| if (v1 == NULL) { |
| ve = ksearch (hstring,"END"); |
| v1 = ve; |
| v2 = v1 + 80; |
| strncpy (v2, ve, 80); |
| } |
| else |
| v2 = v1 + 80; |
| lcom = 0; |
| newcom[0] = 0; |
| } |
|
|
| |
| else { |
| strncpy (line, v1, 80); |
| line[80] = 0; |
| v2 = v1 + 80; |
|
|
| |
| q1 = strchr (line, squot); |
| if (q1 != NULL) |
| q2 = strchr (q1+1,squot); |
| else |
| q2 = line; |
|
|
| |
|
|
| c1 = strchr (q2,'/'); |
| if (c1 != NULL) { |
| lcom = 80 - (c1 - line); |
| strncpy (newcom, c1+1, lcom); |
| vp = newcom + lcom - 1; |
| while (vp-- > newcom && *vp == ' ') |
| *vp = 0; |
| lcom = strlen (newcom); |
| } |
| else { |
| newcom[0] = 0; |
| lcom = 0; |
| } |
| } |
|
|
| |
| for (vp = v1; vp < v2; vp++) |
| *vp = ' '; |
|
|
| |
| strncpy (v1, keyword, lkeyword); |
|
|
| |
| vp = v1 + 8; |
| *vp = '='; |
| vp = v1 + 9; |
| *vp = ' '; |
| vp = vp + 1; |
| if (*value == squot) { |
| strncpy (vp, value, lval); |
| if (lval+12 > 31) |
| lc = lval + 12; |
| else |
| lc = 30; |
| } |
| else { |
| vp = v1 + 30 - lval; |
| strncpy (vp, value, lval); |
| lc = 30; |
| } |
|
|
| |
| if (lcom > 0) { |
| if (lc+2+lcom > 80) |
| lcom = 78 - lc; |
| vp = v1 + lc + 2; |
| *vp = '/'; |
| vp = vp + 1; |
| strncpy (vp, newcom, lcom); |
| for (v = vp + lcom; v < v2; v++) |
| *v = ' '; |
| } |
|
|
| return; |
| } |
|
|
| |
| |
|
|
| static void |
| hputcom (hstring,keyword,comment) |
|
|
| char *hstring; |
| char *keyword; |
| char *comment; |
| { |
| char squot; |
| char line[100]; |
| int lkeyword, lcom; |
| char *vp, *v1, *v2, *c0 = NULL, *c1, *q1, *q2; |
|
|
| squot = 39; |
|
|
| |
| lkeyword = strlen (keyword); |
|
|
| |
| if (lkeyword == 7 && (strncmp (keyword,"COMMENT",7) == 0 || |
| strncmp (keyword,"HISTORY",7) == 0)) { |
|
|
| |
| v1 = ksearch (hstring,"END"); |
| v2 = v1 + 80; |
| strncpy (v2, v1, 80); |
|
|
| |
| for (vp = v1; vp < v2; vp++) |
| *vp = ' '; |
| strncpy (v1, keyword, lkeyword); |
| } |
|
|
| |
| else { |
| v1 = ksearch (hstring,keyword); |
| v2 = v1 + 80; |
|
|
| |
| if (v1 == NULL) { |
| return; |
| } |
|
|
| |
| strncpy (line, v1, 80); |
|
|
| |
| q1 = strchr (line,squot); |
| if (q1 != NULL) |
| q2 = strchr (q1+1,squot); |
| else |
| q2 = NULL; |
|
|
| if (q2 == NULL || q2-line < 31) |
| c0 = v1 + 31; |
| else |
| c0 = v1 + (q2-line) + 2; |
|
|
| strncpy (c0, "/ ",2); |
| } |
|
|
| |
| lcom = strlen (comment); |
|
|
| if (lcom > 0) { |
| c1 = c0 + 2; |
| if (c1+lcom > v2) |
| lcom = v2 - c1; |
| strncpy (c1, comment, lcom); |
| } |
|
|
| } |
|
|