예제 #1
0
/* init the wcs struct and create a new info record */
int initwcs(char *s, int n){
  struct WorldCoor *wcs;
  if( n > 0 ){
    wcs = wcsninit(s, n);
  } else {
    wcs = wcsinit(s);
  }
  if( wcs ){
    wcsoutinit(wcs, getradecsys(wcs));
  }
  return newinfo(wcs);
}
예제 #2
0
파일: record.c 프로젝트: machineroom/ttm50m
void SpOpenRec(void)
{
   char              fname[MAX_SLICE_LENGTH+1];
   int               namelen;
   int               fileorg;
   int               filemode;
   int               filetype;
   int               format;
   long              mrs;
   long              fileid;
   FILE              *fd;
   struct FILE_INFO  *info;
#ifdef VMS
   struct RAB        *rab;
   RecInfo           *rinfo;
   unsigned int      rfm,rat;
#endif /* VMS */
   
   dbgmsg("SP.OPENREC");

   InBuf = &Tbuf[3];
   OutBuf = &Tbuf[2];
   OutCount = 0;
   
   namelen  = get_slice((unsigned char *) fname);
   fname[namelen] = '\0';
   fileorg  = (int) get_8();
   filemode = (int) get_8();
   filetype = (int) get_8();
   format   = (int) get_8();
   mrs      = get_32();
   
   dbgmsg("file=\"%s\" %d:%d:%d:%d %ld", fname, fileorg, filemode, 
                                                filetype, format, mrs);                                                    
   
   /* Validate request */
   if ((strlen(fname) == 0) || (fileorg < 3) || (fileorg > 4) ||
                                 (filetype < 0) || (filetype > 2) ||
                                   (filemode < 1) || (filemode > 6) ||
                                    (format < 0) || (format > 1)) {
      SpFail(ER_ERROR);
      return;
   }
      
   if (filetype == TYPE_DONTCARE)
      filetype = TYPE_RECORD;
   
#ifdef VMS
   if (fileorg == ORG_VARIABLE)
      rfm = FAB$C_VAR;
   rfm = (fileorg == ORG_VARIABLE)?FAB$C_VAR:FAB$C_FIX;
   rat = (filetype == TYPE_RECORD)?FAB$M_FTN:0;    /* FTN:FAB$M_CR */
   
   /* We ignore format under VMS */
   
   /* decide whether to open or create file */
   if ((filemode == 1) || (filemode == 4))
      rab = vmsopen(fname, rfm, rat);
   else
      rab = vmscreate(fname, rfm, rat, rfm);

   if (rab == (struct RAB *) NULL) {
      SpFail(ER_NOFILE);
      return;
   }
   
   rinfo = newinfo();
   if (rinfo == (RecInfo *) NULL) {
      vmsclose(rab);
      SpFail(ER_ERROR);
   }
   else {
      rinfo->baserec = 0;
      rinfo->prev = (FilePos *) NULL;
      rinfo->next = (FilePos *) NULL;
   }
   
   fd = stdout;         /* Must be something ! */
#else
   fd = fopen(fname, OpenModes[fileorg-1][filemode-1]);
   if (fd == NULL) {
      SpFail(ER_NOFILE);
      return;
   }
#endif /* VMS */
   
   /* File opened OK */
   fileid = RememberFile(fd, fileorg);
   if (fileid == NO_SLOT) {
      SpFail(ER_NORESOURCE);
      return;
   }
   
   /* Things are looking good Houston....beep */
   info = &FileInfo[fileid];
   info->buff = (unsigned char *) malloc((int) mrs+3); /* Room for CR, NL, EOS */
   if (info->buff == (unsigned char *) NULL) {      
      ForgetFile(fileid);
      SpFail(ER_NORESOURCE);
      return;
   }
   
   info->mrs = mrs;
   info->recordsize = -1;
   info->format = format;
   info->type = filetype;
   info->recno = 0;
   info->lastop = FIOP_NONE;
   info->pasteof = false;
   
#ifdef VMS
   info->rab = rab;
   info->poslist = rinfo;
#else
   if (fileorg == ORG_VARIABLE) {
      info->putfn = (format == FMT_FORMATTED)?form_seq_write_rec:unform_seq_write_rec;
      info->getfn = (format == FMT_FORMATTED)?form_seq_read_rec:unform_seq_read_rec;
      
      /* Need to allocate a read-ahead buffer for formatted files */
      if (format == FMT_FORMATTED) {
         info->llbuff = (unsigned char *) malloc(LL_BUF_SIZE);
         info->llind = LL_BUF_SIZE;
         if (info->llbuff == (unsigned char *) NULL) {
            free(info->buff);
            ForgetFile(fileid);
            SpFail(ER_NORESOURCE);
            return;
         }
      }
      else {
         info->llbuff = NULL;
         info->llind = 0;
      }
   }
   else {
      info->putfn = direct_write_rec;
      info->getfn = direct_read_rec;
      info->llbuff = NULL;
      info->llind = 0;
   }
#endif /* VMS */
   
   put_8(ER_SUCCESS);
   put_32(mrs);
   put_32(fileid);
   put_32(filetype);
   
   put_count(OutCount);
}