Ejemplo n.º 1
0
webcam::~webcam()
{
    for (uint i = 0; i < n_buffers; ++i)
        if (munmap(buffers[i].start, buffers[i].length) < 0) TERMINATE("can't unmap memory");
    free(buffers);
    if(close(fd) < 0) TERMINATE("close device problem");
}
Ejemplo n.º 2
0
void webcam::readFrame()
{
    struct v4l2_buffer buf;
    CLEAR(buf);
    buf.type    = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    buf.memory  = V4L2_MEMORY_MMAP;
    if (IO_CTL(fd, VIDIOC_DQBUF, &buf) < 0 && errno != EAGAIN) TERMINATE("read frame problem");
    assert(buf.index < n_buffers);
    saveImage(buffers[buf.index].start);
    if (IO_CTL(fd, VIDIOC_QBUF, &buf) < 0) TERMINATE("VIDIOC_QBUF");
}
Ejemplo n.º 3
0
/* fetch_marshbuf: reads off the buffer 'marshbuf' at the offset 'marshoff'.
 * It reads 'sztoread' bytes from this offset and stores the result in the
 * void * 'result' blob. Assumes that sufficient memory has already been 
 * allocated in the 'result' blob and so does no memory mgmt. on its own.
 */
void fetch_marshbuf (const char *function_name,
                     void *marshbuf,
                     int *marshoff,
                     int sztoread,
                     void *result)
{
    void *currptr;
    if (function_name == NULL) {
        PRINT("%s:  function_name is NULL!\n", __FUNCTION__);
        TERMINATE();
    }


    if (result == 0U) {
        PRINT ("%s: You passed me a NULL result\n", __FUNCTION__);
        //*marshoff += sztoread;
        TERMINATE();
        //return;
    }

    if (marshbuf == NULL) {
        PRINT ("%s: You passed me a NULL buffer!  Things will fail now.\n", __FUNCTION__);
        TERMINATE();
    }

    //PRINT ("%s copying data to %p\n", __FUNCTION__, result);
    
    currptr = marshbuf + *marshoff;
#ifdef MARSH_PRINT    
    printk ("fetch: %s copying data %p to %p of size %d from %p, returning %p\n", __FUNCTION__, * (unsigned long *)currptr, result, sztoread, currptr, marshbuf);
#endif    
    memcpy(
        result,
        currptr,
        sztoread);

	

    // This should only be done during on our way to SFI. (why?)
    odft_insert_range_hash(function_name, result, sztoread, 2);

#ifdef MARSH_PRINT    
    printk ("INSERTING %p %d in hashtable.\n", result, sztoread); 
    //full_slab_verify();
#endif
    *marshoff += sztoread;
    return;
}
Ejemplo n.º 4
0
 static inline String cv_names(const SInd i) noexcept {
   if (i == 0) {
     return "T";
   } else {
     TERMINATE("unknown variable index: " + std::to_string(i));
   }
 }
Ejemplo n.º 5
0
    UNIQUE<ZeroCopyStreamResource> resource_from_url(std::string url) {
        boost::trim(url);
        if (url == "-") return UNIQUE<UnixStream>(new UnixStream(STDIN_FILENO));

        bool try_mmap = true;

        // Deal with rfio, dcap and file URLs
        string proto = url.substr(0,7);
        if (proto == "rfio://" or proto == "dcap://" or proto == "hdfs://") {
            return UNIQUE<RemoteFile>(new RemoteFile(url, default_network_block_size));
        } else if (proto == "file://") {
            url = url.substr(7);
        } else if (proto == "nomm://") {
            url = url.substr(7);
            try_mmap = false;
        }

        struct stat buffer;
        if (stat(url.c_str(), &buffer) == -1) TERMINATE("Could not open '", url, "': ", strerror(errno));

        // If it's a FIFO, use a non-seeking buffer
        if (S_ISFIFO(buffer.st_mode) || !try_mmap) return UNIQUE<UnixFile>(new UnixFile(url));
        //else return UNIQUE<UnixFilePartMMap>(new UnixFilePartMMap(url));
        else return UNIQUE<UnixFileMMap>(new UnixFileMMap(url));
    }
Ejemplo n.º 6
0
 void UnixFilePartMMap::remap() {
     if (_mmap) munmap(_mmap, _mmap_blocksize);
     _mmap = ::mmap(NULL, _mmap_blocksize, PROT_READ, MAP_PRIVATE, _file->no, _mmap_offset);
     if (mmap == MAP_FAILED) {
         TERMINATE("Could not open (mmap) '", _name, "': ", strerror(errno));
     }
 }
Ejemplo n.º 7
0
FileFinder OutputFileHandler::CopyFileTo(const FileFinder& rSourceFile) const
{
    if (!rSourceFile.IsFile())
    {
        EXCEPTION("Can only copy single files:\n" << rSourceFile.GetAbsolutePath() << " is not a file.");
    }
    fs::path from_path(rSourceFile.GetAbsolutePath());
    fs::path to_path(GetOutputDirectoryFullPath());
    to_path /= from_path.leaf();
    if (PetscTools::AmMaster())
    {
        try
        {
            fs::copy_file(from_path, to_path);
        }
        // LCOV_EXCL_START
        catch (const fs::filesystem_error& e)
        {
            TERMINATE("Error copying file '" << rSourceFile.GetAbsolutePath() << "': " << e.what());
        }
        // LCOV_EXCL_STOP
    }
    PetscTools::Barrier("OutputFileHandler::CopyFileTo");
    return FileFinder(to_path.string(), RelativeTo::Absolute);
}
Ejemplo n.º 8
0
void webcam::cameraOn()
{
    enum v4l2_buf_type type;
    for (uint i = 0; i < n_buffers; ++i) 
    {
        v4l2_buffer buf;
        CLEAR(buf);
        buf.type    = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        buf.memory  = V4L2_MEMORY_MMAP;
        buf.index   = i;
        if(IO_CTL(fd, VIDIOC_QBUF, &buf) < 0) TERMINATE("buffer exchange error");
    }
    type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    if(IO_CTL(fd, VIDIOC_STREAMON, &type) < 0) TERMINATE("can't start streaming");
    isEnabled = true;
}
Ejemplo n.º 9
0
Archivo: ld.c Proyecto: unixaaa/LuxCC
Symbol *define_symbol(char *name, int kind, int segment, int offset)
{
    unsigned h;
    Symbol *np;

    h = HASH(name);
    for (np = symbols[h]; np != NULL; np = np->next)
        if (equal(np->name, name))
            break;

    if (np == NULL) {
        np = malloc(sizeof(Symbol));
        /* set attributes */
        np->name = strdup(name);
        np->segment = segment;
        np->offset = offset;
        np->kind = kind;
        /* chain */
        np->next = symbols[h];
        symbols[h] = np;
    } else {
        if (np->kind == EXTERN_SYM) {
            if (kind == GLOBAL_SYM) {
                np->kind = GLOBAL_SYM; /* now defined */
                np->segment = segment;
                np->offset = offset;
            }
        } else if (np->kind == GLOBAL_SYM) {
            if (kind == GLOBAL_SYM)
                TERMINATE("%s: multiple definition of `%s'", prog_name, name);
        }
    }

    return np;
}
Ejemplo n.º 10
0
/*>void WriteJobFile(char *queueDir, int pid, char **progArgs, 
                     int nProgArgs)
   -----------------------------------------------------------
*//**
   \param[in]  *queueDir    queue directory
   \param[in]  pid          job number
   \param[in]  **progArgs   Program and arguments in an array
   \param[in]  nProgArgs    Number of items in progArgs

   Creates a job file

-  16.10.15  Original   By: ACRM
*/
void WriteJobFile(char *queueDir, int pid, char **progArgs, int nProgArgs)
{
   char jobFile[MAXBUFF],
        pwd[MAXBUFF];
   FILE *fp;


   sprintf(jobFile, "%s/%d", queueDir, pid);
   getcwd(pwd, MAXBUFF);
   TERMINATE(pwd);

   if((fp=fopen(jobFile, "w"))!=NULL)
   {
      int i;
      fprintf(fp, "%s\n", pwd);
      for(i=0; i<nProgArgs; i++)
      {
         fprintf(fp, "%s ", progArgs[i]);
      }
      fprintf(fp, "\n");
      fclose(fp);
   }
   else
   {
      char msg[MAXBUFF];
      sprintf(msg,"Unable to create job file %s", jobFile);
      Message(PROGNAME, MSG_FATAL, msg);
   }
}
Ejemplo n.º 11
0
Archivo: stmt.c Proyecto: unixaaa/LuxCC
void increase_switch_nesting_level(ExecNode *e)
{
    ++switch_nesting_level;
    if (switch_nesting_level >= MAX_SWITCH_NEST)
        TERMINATE("error: too many nested switch statements (>= %d)", MAX_SWITCH_NEST);
    switch_case_counter[switch_nesting_level] = 1;
    switch_contr_expr_types[switch_nesting_level] = get_type_category(&e->type);
}
Ejemplo n.º 12
0
Archivo: ld.c Proyecto: unixaaa/LuxCC
void *new_local_symbol(void)
{
    void *p;

    if ((p=arena_alloc(local_arena, sizeof(Symbol))) == NULL)
        TERMINATE("%s: out of memory", prog_name);

    return p;
}
Ejemplo n.º 13
0
 void setup_processor(CopyProcessor& p) {
     if (_start_index) {
         static int processor_count = 0;
         if (processor_count++)
             TERMINATE("--start-index only works with one processor (-t1)");
         p._start_index = _start_index;
     }
     p._metadata_only = _metadata_only;
 }
Ejemplo n.º 14
0
/*>static BOOL ExtractField(STRINGLIST *molidStart, 
                            STRINGLIST *molidStop, char *data,
                            char *type, char *field)
   ------------------------------------------------------------
*//**
   \param[in]   *molidStart    Start of a set of header records 
   \param[in]   *molidStop     Start of next set of headers (or NULL)
   \param[out]  *data          Storage for extracted string
   \param[in]   *type          Record type (COMPND or SOURCE)
   \param[in]   *field         Sub-record field of interest
   \return                     Success

   Extracts data for a field from a COMPND or SOURCE record. The field 
   data after the field specfication and is terminated by a ;

   Returns FALSE if field not found.

-  28.04.15  Original   By: ACRM
*/
static BOOL ExtractField(STRINGLIST *molidStart, STRINGLIST *molidStop,
                         char *data, char *type, char *field)
{
   STRINGLIST *s;
   BOOL       GotField = FALSE;
   char       *chp,
              buffer[MAXPDBANNOTATION];

   data[0] = '\0';

   for(s=molidStart; s!=molidStop; NEXT(s))
   {
      if(strncmp(s->string, type, 6))
         break;

      chp = NULL;

      if(GotField && isdigit(s->string[9]))
      {
         /* We have found the field already on previous line and this is
            marked as a continuation line            
         */
         chp = s->string+10;
      }
      else
      {
         /* Look for this field                                         */
         if((chp=strstr(s->string, field))!=NULL)
         {
            GotField = TRUE;
            /* Step over the field name                                 */
            chp += strlen(field);
            if(*chp == ' ')
               chp++;
         }
      }
      
      if(GotField && (chp != NULL))
      {
         /* Copy into the buffer                                        */
         strncpy(buffer, chp, MAXPDBANNOTATION);
         /* Remove spaces                                               */
         TERMINATE(buffer);
         KILLTRAILSPACES(buffer);
         /* Add to output data                                          */
         blStrncat(data, buffer, MAXPDBANNOTATION);

         /* Exit if the string contains a ;                             */
         if((chp=strchr(data, ';'))!=NULL)
         {
            *chp = '\0';
            return(TRUE);
         }
      }
   }
   return(FALSE);
}
Ejemplo n.º 15
0
/**
 * This function is called when the control is unloaded. It happens when
 * the user loads a new control program or exits.
 *
 * @return Return non-zero to indicate an error.
 */
int ZenomMatlab::terminate()
{
     if (fd >= 0){
        
         Q8Close(fd);        
         printf("q8 is closing...\n");
     }

    TERMINATE(rtM);

    return 0;
}
Ejemplo n.º 16
0
void webcam::shot(uint count)
{
    if(!isEnabled) return;
    while (count-- > 0) 
    {
        fd_set  fds;
        timeval tv;
        
        FD_ZERO(&fds);
        FD_SET(fd, &fds);
        tv.tv_sec  = 2;
        tv.tv_usec = 0;
        int r = select(fd + 1, &fds, NULL, NULL, &tv);
        if (r < 0) 
        {
            if (errno == EINTR) continue;
            TERMINATE("select");
        }
        if (r == 0) TERMINATE ("select timeout error"); 
        readFrame();
    }    
}
Ejemplo n.º 17
0
std::string OutputFileHandler::MakeFoldersAndReturnFullPath(const std::string& rDirectory) const
{
    fs::path output_root(GetChasteTestOutputDirectory());
    fs::path rel_path(rDirectory);

    if (!rel_path.empty() && (*(--rel_path.end())) == ".")
    {
        // rDirectory has a trailing slash, which gives an unhelpful last component
        rel_path.remove_leaf();
    }

    // Make master wait (because other processes may be checking whether a directory exists)
    PetscTools::Barrier("OutputFileHandler::MakeFoldersAndReturnFullPathBeforeCreation");
    // Are we the master process? Only the master should make any new directories
    if (PetscTools::AmMaster())
    {
        try
        {
            // If necessary make the ChasteTestOutputDirectory - don't make it deleteable by Chaste
            fs::create_directories(output_root); // Note that this is a no-op if the folder exists already

            // Now make all the sub-folders requested one-by-one and add the .chaste_deletable_folder file to them
            fs::path next_folder(output_root);
            for (fs::path::iterator path_iter = rel_path.begin(); path_iter != rel_path.end(); ++path_iter)
            {
                next_folder /= *path_iter;
                bool created_dir = fs::create_directory(next_folder);
                if (created_dir)
                {
                    // Add the Chaste signature file
                    fs::ofstream sig_file(next_folder / SIG_FILE_NAME);
                    sig_file.close();
                }
            }
        }
        // LCOV_EXCL_START
        catch (const fs::filesystem_error& e)
        {
            TERMINATE("Error making test output folder: " << e.what());
        }
        // LCOV_EXCL_STOP
    }

    // Wait for master to finish before going on to use the directory.
    PetscTools::Barrier("OutputFileHandler::MakeFoldersAndReturnFullPath");

    std::string path_with_slash = (output_root / rel_path).string();
    AddTrailingSlash(path_with_slash);
    return path_with_slash;
}
Ejemplo n.º 18
0
 RemoteCopyingFile::RemoteCopyingFile(std::string filename)
   : _filename(filename),
     _is_closed(false),
     _errno(0),
     _fileno(-1),
     _previous_seek_failed(false),
     _close_on_delete(true),
     _position(0) {
     if (filename.substr(0,7) == "rfio://") {
         fscalls.reset(new rfio_filesystem_calls());
     } else if (filename.substr(0,7) == "dcap://") {
         fscalls.reset(new dcap_filesystem_calls());
     } else if (filename.substr(0,7) == "hdfs://") {
         fscalls.reset(new hdfs_filesystem_calls());
         filename = filename.substr(8);
     } else {
         TERMINATE("Unknown remote file type: ", filename);
     }
     if (!fscalls->loaded) TERMINATE("Failure to load remote access library!");
     _fileno = fscalls->open(const_cast<char*>(filename.c_str()), O_RDONLY, 0);
     _errno = fscalls->last_errno();
     if (_errno != 0 or _fileno == -1) TERMINATE("Could not open '", filename, "': ", strerror(_errno));
 }
Ejemplo n.º 19
0
 inline void CommandContext<T, N, L>::destroy() {
     CHECK_CALL(m_commandQueue->Signal(m_fence.Get(), UINT64_MAX),
                "Failed to insert a fence into the command queue.");
     syncThread(UINT64_MAX);
     if (!CloseHandle(m_syncEvent)) {
         printError("Failed to close the synchronization event handle."); 
         TERMINATE();
     }
     for (size_t i = 0; i < L; ++i) {
         // Command lists have to be released before the associated
         // root signatures and pipeline state objects.
         m_commandLists[i].Reset();
     }
 }
Ejemplo n.º 20
0
Archivo: ld.c Proyecto: unixaaa/LuxCC
void append_data_reloc(int segment, int offset, char *symbol)
{
    if (ndreloc >= dreloc_max) {
        Reloc *p;

        dreloc_max *= 2;
        if ((p=realloc(data_relocation_table, dreloc_max*sizeof(Reloc))) == NULL)
            TERMINATE("out of memory");
        data_relocation_table = p;
    }
    data_relocation_table[ndreloc].segment = segment;
    data_relocation_table[ndreloc].offset = offset;
    data_relocation_table[ndreloc].symbol = symbol;
    ++ndreloc;
}
Ejemplo n.º 21
0
Archivo: ld.c Proyecto: unixaaa/LuxCC
void append_text_reloc(int segment, int offset, char *symbol)
{
    if (ntreloc >= treloc_max) {
        Reloc *p;

        treloc_max *= 2;
        if ((p=realloc(text_relocation_table, treloc_max*sizeof(Reloc))) == NULL)
            TERMINATE("out of memory");
        text_relocation_table = p;
    }
    text_relocation_table[ntreloc].segment = segment;
    text_relocation_table[ntreloc].offset = offset;
    text_relocation_table[ntreloc].symbol = symbol;
    ++ntreloc;
}
Ejemplo n.º 22
0
/* fill_marshbuf: fills the buffer 'marshbuf' at offset 'marshoff' with the 
 * contents of 'tocopy'. The number of bytes of data contained in tocopy is
 * stored in sztocopy
 */
void fill_marshbuf (const char *function_name,
                    void **marshbuf,
                    int *marshoff,
                    const void *tocopy, int sztocopy) 
{
    //full_slab_verify();
    if (function_name == NULL) {
        PRINT("%s:  function_name is NULL!\n", __FUNCTION__);
        TERMINATE();
    }

    if (*marshbuf == NULL) {
        *marshbuf = ALLOC(0);
        //printk ("Verifying slab again..\n");
        //full_slab_verify();
    }

    if (MAX_MARSH_BUFF_SIZE < *marshoff)    {
        printk ("Incorrect marshalling  - let's panic.\n");
        panic ("Marsh buffer too small.\n");
    }

#ifdef MARSH_PRINT
    printk ("In fill_marshbuf for %s, *marshbuf %p *marshoff %d, tocopy %p, size %d", function_name,
                *marshbuf, *marshoff, tocopy, sztocopy);
#endif		
    //full_slab_verify();

    // Trivial case
    if (tocopy == 0U) {
        *marshoff += sztocopy;
    }

#ifdef MARSH_PRINT
    printk ("%s copying data of size %d to %p, returning %p\n", __FUNCTION__, sztocopy, *marshbuf + *marshoff, *marshbuf);
#endif
    memcpy (
        *marshbuf + *marshoff,
        tocopy,
        sztocopy);

    *marshoff += sztocopy;
#ifdef MARSH_PRINT    	
    printk ("marsh off %d sztocopy %d.\n", *marshoff, sztocopy); 
    //full_slab_verify();
    printk ("\nDone with fill_marshbuf : new offset is %p %d.\n", *marshbuf + *marshoff, sztocopy);
#endif    
}
Ejemplo n.º 23
0
/**
 * This function is called when the START button is pushed from zenom.
 *
 * @return If you return 0, the control starts and the doloop() function is
 * called periodically. If you return nonzero, the control will not start.
 */
int ZenomMatlab::start()
{
    
    fprintf(stderr, "\n** starting the model **\n");

    START(rtM);

    if (rtmGetErrorStatus(rtM) != NULL) {
        fprintf(stderr, "Failed in target initialization.\n");
        TERMINATE(rtM); 
        return 0;
    }

    fprintf(stderr, "starting done!\n");
    
    return 0;
}
Ejemplo n.º 24
0
int main() {
	ASM_INIT();

	// 0 1 2
	COPY_IM('0', code+4);
	// 3 4
	PRINT_I('X');
	// 5 6
//	PRINT_I('\n');
	// 7 8 9
	ADD_IMM(1, code+4, code+4);
	// 10 11
	AND_IMM(0x7F, code+4, code+4);
	// 12 13
	JUMP_I(code+3);
	// 14
	TERMINATE();

	ASM_RUN()
}
Ejemplo n.º 25
0
void Atom_type::set_radial_grid(int num_points, double const* points)
{
    if (num_mt_points_ == 0) TERMINATE("number of muffin-tin points is zero");
    if (num_points < 0 && points == nullptr)
    {
        /* create default exponential grid */
        radial_grid_ = Radial_grid(exponential_grid, num_mt_points_, radial_grid_origin_, mt_radius_); 
    }
    else
    {
        assert(num_points == num_mt_points_);
        radial_grid_ = Radial_grid(num_points, points);
    }
    if (parameters_.processing_unit() == GPU)
    {
        #ifdef __GPU
        radial_grid_.copy_to_device();
        #endif
    }
}
Ejemplo n.º 26
0
/* fill_marshbuf_ptr: fills the buffer 'marshbuf' at offset 'marshoff' with
 * the contents of 'tocopy'. In this case, 'tocopy' contains a pointer 
 * Here, the contents of the void * location are suposed to be the pointer.
 * That is, the void * is not the pointer itself.
 */
void fill_marshbuf_ptr (const char *function_name,
                        void **marshbuf,
                        int *marshoff,
                        const void *tocopy)
{
    int ptrsz = sizeof (void *);
#ifdef MARSH_PRINT    
    printk ("In fill_marshbuf_ptr for marshbuff %p, marshoff %p, functions name %s and tocopy %p.\n", marshbuf, marshoff, function_name, tocopy);
#endif
    if (tocopy == 0)
    {
        PRINT ("fill_marshbuf_ptr: Don't pass a NULL value.  Things are going fail.\n");
        TERMINATE();
    }
    
    //validate_pointer (tocopy);
    //full_slab_verify();
    // The mouse device copies a size_t as a void * (sigh!)
    //validate_pointer (*(const void **) tocopy);
    fill_marshbuf (function_name, marshbuf, marshoff, tocopy, ptrsz);
}
Ejemplo n.º 27
0
/*>char *blGetTitleWholePDB(WHOLEPDB *wpdb)
   ----------------------------------------
*//**
   \param[in]    *wpdb    WHOLEPDB structure
   \return                Tit;le from PDB file (malloc()'d)

   Extracts the title from a PDB file malloc()ing a string in which to
   store the data. This must be freed by user code

-  28.04.15 Original   By: ACRM
-  11.05.15 Return NULL if TITLE line absent. By: CTP
-  09.06.15 Add columns 11 to 80 to title string for both start and 
            continuation lines. By: CTP
*/
char *blGetTitleWholePDB(WHOLEPDB *wpdb)
{
   char       *title = NULL,
              *cleanTitle = NULL;
   STRINGLIST *s;
   BOOL       inTitle = FALSE;

   for(s=wpdb->header; s!=NULL; NEXT(s))
   {
      if(!strncmp(s->string, "TITLE ", 6))
      {
         char buffer[MAXPDBANNOTATION];
         strcpy(buffer, s->string);
         TERMINATE(buffer);

         /* append cols 11-80 to title string                           */
         title = blStrcatalloc(title, buffer+10);

         if(title == NULL)
            return(NULL);
      }
      else if(inTitle)
      {
         break;
      }
   }

   /* title line not found                                              */
   if(title == NULL)
      return(NULL);

   cleanTitle = blCollapseSpaces(title);
   free(title);
   KILLTRAILSPACES(cleanTitle);
   
   return(cleanTitle);
}
Ejemplo n.º 28
0
void webcam::cameraOff()
{
    v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    if(IO_CTL(fd, VIDIOC_STREAMOFF, &type) < 0) TERMINATE("can't stop streaming");
    isEnabled = false;
}
Ejemplo n.º 29
0
/*----------------------------------------------------------------------*
 *  •   prototypes                                                      *
 *—————————————————————————————————————————————————————————————————————-*/
static Boolean
Print_Standard_Labels (void )
{
    SInt32                  i = 0;
    Boolean                 rc = FALSE;
    char                    lLblType[4];
    char                    lLblNum[2];
    SInt32                  iLblType = 0;

    sscanf ( gStdLblBuffer, "%3c%1c%*76c", lLblType, lLblNum );
    TERMINATE(lLblType);
    TERMINATE(lLblNum);

    if ( isdigit( lLblNum[0] ) )
    { if ( lLblNum[0] < '1' || lLblNum[0] > '9' ) return ( FALSE ); } /* this should be transportable to EBCDIC machines */
    else
        return ( FALSE );

    if ( strcmp ( lLblType, "VOL" ) == 0 )      iLblType = 1;       /* VOL  */

    if ( ( strcmp ( lLblType, "HDR" ) == 0 ) ||
        ( strcmp ( lLblType, "EOF" ) == 0 ) ||
        ( strcmp ( lLblType, "EOV" ) == 0 ) )   iLblType = 2;       /* HDR | EOF | EOV  */

    if ( ( strcmp ( lLblType, "UHL" ) == 0 ) ||
        ( strcmp ( lLblType, "UTL" ) == 0 ) )   iLblType = 3;       /* UHL | UTL    User Labels */

    switch ( iLblType )
    {
        case    1:
        {
            char    volser[7];                              /* ( 5-10) Volume ID                */
            char    vsec[2]                                 /* (   11) Volume Accessability     */
            /* 5 bytes  */                                  /* (12-16) VTOC Pointer (not used)  */
            ;/* 21 bytes */                                 /* (17-37) Reserved                 */
            char    owner[15]                               /* (38-51) Owner ID                 */
            ;/* 29 bytes */                                 /* (52-80) Reserved                 */

            /*       1...5...10...15...20...25...30...35...40...45...50...55...60...65...70...75...80
             *       VOL1volsr|sRESERVED-----------------|owner--------|RESERVED--------------------|
             */
            sscanf ( gStdLblBuffer, "%*3c%*1c%6c%1c%*5c%*21c%14c%*29c", volser, vsec, owner );

            TERMINATE(volser);      /* Null terminate the arrays */
            TERMINATE(vsec);
            TERMINATE(owner);

            printf ( "\n%-2s", "" );

            if ( atoi( lLblNum ) == 1 )
                printf ( "Standard Label Tape\n\n%-4s"
                        "VolSer: %-10s"
                        "Owner: %s\n", "", volser, owner );
            else
                printf ( "%-4s %1s %-s\n", lLblType, lLblNum, &gStdLblBuffer[4] );
        }
            rc = TRUE;
            break;

        case    2:
        {
            switch ( atoi( lLblNum ) )
            {
                case 1:
                {
                    char    fid[18];                /* ( 5-21) rightmost 17 char of file Identifier (dataset name DSN)  */
                    char    afset[7];               /* (22-27) Aggregate volume ID (volser 1st vol)                     */
                    char    afseq[5];               /* (28-31) Aggregate volume seq (multi-volume)                      */
                    char    fseq[5];                /* (32-35) file seq number 0001-9999 < x'6F'xxxxxx 1-64000(bin)     */
                    char    gen[5];                 /* (36-39) generation number    (not used)                          */
                    char    gver[3];                /* (40-41) generation version   (not used)                          */
                    char    cdate[7]                /* (42-47) creation date                                            */
                    ;                               /*         cyyddd;c = blank 19, 0 = 20, 1 = 21; jdate               */
                    char    edate[7];               /* (48-53) expiration date                                          */
                    char    fsec[2]                 /* (   54) File Security        (not used)                          */
                    ;                               /*              0=none,1=pwd-R-W-Del,3=pwd-W-Del                    */
                    char    bcnt[7];                /* (55-60) block count (blockcnt % 1000000) (HDR=0) (EOF/EOV)       */
                    char    impid[14]               /* (61-73) System Code (IBMOS400|IBM OS/VS 370)                     */
                    ;                               /* (74-76) Reserved                                                 */
                    char    ebcnt[5];               /* (77-80) extended block count (blockcnt / 1000000)(EOF/EOV)       */

                    /*       1...5...10...15...20...25...30...35...40...45...50...55...60...65...70...75...80
                     *       HDR1DSNAME----------|afvst|afs|fsq|---|-|cdate|edate||bcnt-|syscode-----|RR|ebct
                     *       {EOF}                                 n/a         fsec^
                     *       {EOV}
                     */
                    sscanf( gStdLblBuffer, "%*3c%*1c%17c%6c%4c%4c%4c%2c%6c%6c%1c%6c%13c%*3c%4c",
                           fid, afset, afseq, fseq, gen, gver, cdate, edate, fsec, bcnt, impid, ebcnt);

                    TERMINATE(fid);             /* NULL Terminate the arrays */
                    TERMINATE(afset);
                    TERMINATE(afseq);
                    TERMINATE(fseq);
                    TERMINATE(gen);
                    TERMINATE(gver);
                    TERMINATE(cdate);
                    TERMINATE(edate);
                    TERMINATE(fsec);
                    TERMINATE(bcnt);
                    TERMINATE(impid);
                    TERMINATE(ebcnt);

                    if ( lLblType[0] == 'E' )
                    {
                        for ( i = 0; i < 4; i++ ) { if ( !isdigit( ebcnt[i] ) ) ebcnt[i] = '0'; }
                        ebcnt[4] = '\0';
                    }
                    else
                        if ( atoi( lLblNum ) == 1 )
                            printf ("\f");

                    if ( fseq[0] == '?' )       /* this is the indicator that IBM uses for seq no > 9999 ebcdic x'6f' */
                    {
                        fseq[0] = '\x00';
                        gLastFileSeqSL = ( ( fseq[0]    << 24 ) & 0xff000000 )
                        |( ( fseq[1]    << 16 ) & 0x00ff0000 )
                        |( ( fseq[2]    << 8  ) & 0x0000ff00 )
                        |( ( fseq[3]          ) & 0x000000ff );
                    }
                    else
                        gLastFileSeqSL = (UInt32)atol( fseq );

                    printf ( "\n%-4s"
                            "SL File Seq: %-4d%-3s"
                            "DSNAME: %-20s"
                            , "", atoi( fseq ), "", fid );

                    printf ( "Created: " );
                    if ( cdate[0] == ' ' )
                        if ( (int)( atol( &cdate[1] ) / 1000l ) < 1967 )
                            printf ( "20" );
                        else
                            printf ( "19" );
                    else
                        printf ( "2%1c", cdate[0] );
                    printf ( "%02d.%03d%-3s", (int)( atol( &cdate[1] ) / 1000l ), atoi( &cdate[3] ), "" );

                    if ( strcmp ( &edate[1], "00000" ) !=0 )
                    {
                        printf ( "Expires: " );
                        if ( atoi ( &edate[3] ) == 0 )
                            printf ( "TMS-%-5s", &edate[1] );
                        else
                        {
                            if ( edate[0] == ' ' )
                                if ( (int)( atol( &edate[1] ) / 1000l ) < 1967 )
                                    printf ( "20" );
                                else
                                    printf ( "19" );
                            else
                                printf ( "2%1c", edate[0] );
                            printf ( "%02d.%03d%-1s", (int)( atol( &edate[1] ) / 1000l ), atoi( &edate[3] ), "" );
                        }
                    }
                    else
                        printf ( "%-9s", "NO EXPDT" );

                    printf ( "%-3sSystem: %s\n", "", impid );

                    if ( gStdLblBuffer[0] == 'E' )
                    {
                        UInt64   lBlockCnt  = (UInt64)(atol( bcnt ) % 1000000l) + (UInt64)(atol( ebcnt ) * 1000000l);
                        printf ( "%-4sBlock Count: "
                                "Expected %llu; "
                                "Actual %d",
                                "", lBlockCnt, (int)gPrevBlkCnt );
                        if ( lBlockCnt == (UInt64)gPrevBlkCnt )
                            printf ( "\n" );
                        else
                            printf ( "%-4s---> BLOCK COUNT MISMATCH <---\n", "" );
                    }
                    else
                    {
                        gMltVolSet[0] = '\0';
                        gMltVolSeq[0] = '\0';
                        strcpy ( gMltVolSet, afset );
                        strcpy ( gMltVolSeq, afseq );
                    }
                }
                    break;

                case 2:
                {
                    char    fmt[2];                             /* (    5) Format F=fixed;V=variable;U=unblock              */
                    char    bsize[6];                           /* ( 6-10) Block Size 1-32767 (>32767 see large block size) */
                    char    rsize[6];                           /* (11-15) Record Size                                      */
                    char    tden[2];                            /* (   16) Density of tape 3=1600,4=6250,5=3200,blank=others */
                    char    mltv[2];                            /* (   17) Multi-volume switch 1/0 2nd + tape seq num       */
                    char    jname[9]                            /* (18-25) Job Name creating tape                           */
                    ;/* 1 byte */                               /* (   26) '/' Separator                                    */
                    char    sname[9];                           /* (27-34) Step Name creating tape                          */
                    char    rtech[3];                           /* (35-36) Adv. Recording tech. blank=none;'P '=IDRC        */
                    char    pcchr[2];                           /* (   37) Printer Control Char A=ANSI;M=machine            */
                    char    battr[2]                            /* (   38) Block Attr B=blkd;S=Spanned(V)|Std(F);R=B&S      */
                    ;/* 3 bytes */                              /* (39-47) Reserved                                         */
                    char    ckpt[2]                             /* (   48) Chkpt Data Set ID; C=secure CKPT dsn;blank - not */
                    ;/* 22 chars */                             /* (49-70) Reserved                                         */
                    char    lbsiz[11];                          /* (71-80) Large Block Size > 32767                         */

                    char    tmp[10];
                    char    dcb[80];

                    /*       1...5...10...15...20...25...30...35...40...45...50...55...60...65...70...75...80
                     *       HDR2|bsiz|rsiz|||jname--|/sname--|r||R|RR000000|RESERVED-------------|lbsize---|
                     *      {EOF}^-- FORMAT |^- MULTI-VOL        | ^- BLK'D ^- CKPT
                     *      {EOV}           ^-- DENSITY          ^-CC {A|M| }
                     */
                    sscanf( gStdLblBuffer,
                           "%*3c"               /*  3 HDR | EOF | EOV                           */
                           "%*1c"               /*  1 1-9                                       */
                           "%1c"                /*  1 fmt                                       */
                           "%5c"                /*  5 bsize                                     */
                           "%5c"                /*  5 rsize                                     */
                           "%1c"                /*  1 tden                                      */
                           "%1c"                /*  1 mltv      Multi-volume switch indicator   */
                           "%8c"                /*  8 jname                                     */
                           "%*1c"               /*  1 '/'                                       */
                           "%8c"                /*  8 sname                                     */
                           "%2c"                /*  2 rtech                                     */
                           "%1c"                /*  1 cc        A | M                           */
                           "%*1c"               /*  1 reserved                                  */
                           "%1c"                /*  1 battr     B | S | BS | ' '                */
                           "%*2c"               /*  2 reserved                                  */
                           "%*6c"               /*  6 Device Serial number or 6 blanks          */
                           "%1c"                /*  1 ckpt      Checkpoint Data Set Id          */
                           "%*22c"              /* 22 reserved                                  */
                           "%10c"               /* 10 lbsize    large block size (> 32767)      */
                           , fmt, bsize, rsize, tden, mltv, jname, sname, rtech, pcchr, battr, ckpt, lbsiz);

                    TERMINATE(fmt);         /* NULL terminate the arrays */
                    TERMINATE(bsize);
                    TERMINATE(rsize);
                    TERMINATE(tden);
                    TERMINATE(mltv);
                    TERMINATE(jname);
                    TERMINATE(sname);
                    TERMINATE(rtech);
                    TERMINATE(pcchr);
                    TERMINATE(battr);
                    TERMINATE(ckpt);
                    TERMINATE(lbsiz);

                    if ( gStdLblBuffer[0] == 'H' )
                    {
                        tmp[0] = dcb[0] = '\0';

                        printf ( "%-4sCreated by: Job %-8s; Step %-11s%-6s"
                                , "", jname, sname, "" );

                        strlcat ( dcb, "DCB=(RECFM=", sizeof(dcb) );

                        strlcat ( dcb, fmt, sizeof(dcb) );      /* first character of the RECFM F|V|U                   */
                                                                /* next 'S' means SPANNED for 'V' and STANDARD for 'F'  */
                        if ( battr[0] == 'R' )                  /* next 1 or 2 (if = 'R') characters B|S|R|' '          */
                            strlcat ( dcb, "BS", sizeof(dcb) ); /* 'R' = both B & S together                            */
                        else
                            if ( battr[0] != ' ' )
                                strlcat ( dcb, battr, sizeof(dcb) ); /* just the B|S if not 'R' - blank is not included      */

                        if ( pcchr[0] != ' ' )
                            strlcat ( dcb, pcchr, sizeof(dcb) );/* last is the printer carriage control type A|M        */
                                                                /* A = ANSI and M = Machine                             */
                        strlcat ( dcb, ",LRECL=", sizeof(dcb) );
                        sprintf ( tmp, "%d", atoi( rsize ) );
                        strlcat ( dcb, tmp, sizeof(dcb) );

                        strlcat ( dcb, ",BLKSIZE=", sizeof(dcb) );
                        if ( lbsiz[0] == '0' )
                            sprintf ( tmp, "%ld", atol( lbsiz ) );
                        else
                            sprintf ( tmp, "%d", atoi( bsize ) );
                        strlcat ( dcb, tmp, sizeof(dcb) );

                        strlcat ( dcb, ")", sizeof(dcb) );

                        printf ( "%-51s", dcb );

                        if ( mltv[0] == '1' || atoi( gMltVolSeq ) > 1 )
                            printf ( "\n%-4sTape is part %d of multi-volume set %s\n", "", atoi( gMltVolSeq ), gMltVolSet );

                        if ( rtech[0] == 'P' )
                            printf ( "%-3sCompression: IDRC", "" );

                        printf ( "\n" );
                    }
                    else
                        printf( "======================================"
                                "======================================"
                                "======================================"
                                "======================================\n" );
                }
                    break;

                default:
                    printf ( "%-4s %1d %-s\n", lLblType, *lLblNum, &gStdLblBuffer[4] );
                    break;
            }
        }
            rc = TRUE;
            break;

        case        3:
            printf ( "%-4s %1d %-s\n", lLblType, *lLblNum, &gStdLblBuffer[4] );
            rc = TRUE;
            break;

        default:
            rc = FALSE;
            break;
    }

    ZERO_OUT ( gStdLblBuffer, sizeof( gStdLblBuffer ) );
    return ( rc );

} /* end function Print_Standard_Labels */
Ejemplo n.º 30
0
webcam::webcam(uint w, uint h, const std::string & device) : 
    width(w),
    height(h),
    device(device)
   
{
    struct stat st;
    if(stat(device.c_str(), &st) < 0) TERMINATE("can't find " + device);
    if(!S_ISCHR(st.st_mode)) TERMINATE(device + " is no device"); 
    fd = open(device.c_str(), O_RDWR | O_NONBLOCK, 0);
    if (fd < 0) TERMINATE ("can't open " + device);
    
    v4l2_capability cap;
    v4l2_cropcap    cropcap;
    v4l2_crop       crop;
    v4l2_format     fmt;

    if (IO_CTL(fd, VIDIOC_QUERYCAP, &cap) < 0)        TERMINATE("QUERYCAR request error");
    if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) TERMINATE(device + " is not capture device");
    if (!(cap.capabilities & V4L2_CAP_STREAMING))     TERMINATE(device + " does not support streaming i/o");

    CLEAR(cropcap);
    cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    if (IO_CTL(fd, VIDIOC_CROPCAP, &cropcap) == 0) 
    {
        crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        crop.c = cropcap.defrect;
        IO_CTL(fd, VIDIOC_S_CROP, &crop);
    }    
    CLEAR(fmt);
    fmt.type                = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width       = width;
    fmt.fmt.pix.height      = height;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
    fmt.fmt.pix.field       = V4L2_FIELD_ANY;
    if (IO_CTL(fd, VIDIOC_S_FMT, &fmt) < 0) TERMINATE("can't set capture format");

    v4l2_requestbuffers req;
    CLEAR(req);

    req.count   = 4;
    req.type    = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    req.memory  = V4L2_MEMORY_MMAP;

    if(IO_CTL(fd, VIDIOC_REQBUFS, &req) < 0) TERMINATE("memory mapping not supported"); 
    if(req.count < 2) TERMINATE("insufficient buffer memory ");

    buffers = static_cast<buffer *>(calloc(req.count, sizeof(*buffers)));
    if(!buffers) TERMINATE("out of memory!");
    for(n_buffers = 0; n_buffers < req.count; ++n_buffers) 
    {
        v4l2_buffer buf;
        CLEAR(buf);

        buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        buf.memory      = V4L2_MEMORY_MMAP;
        buf.index       = n_buffers;

        if(IO_CTL(fd, VIDIOC_QUERYBUF, &buf) < 0) TERMINATE("can't create buffers");
        buffers[n_buffers].length = buf.length;
        buffers[n_buffers].start = mmap(NULL,buf.length,PROT_READ|PROT_WRITE,MAP_SHARED,fd, buf.m.offset);
        if (MAP_FAILED == buffers[n_buffers].start) TERMINATE("mmap");
    }
}