Exemple #1
0
Attribute* cast_operator(Attribute* attr1, int type, int rm_attr1, int lno) {
    if(attr1 == NULL)
        die(lno, "NULL Attribute error");
    int	type1 = attr1->type;
    Attribute* result;
    if(type1 == INT_T && type == FLOAT_T) {
        result = new_attr(FLOAT_T, NULL);
        result->value.fv = (float)attr1->value.iv;
    }
    else if(type1 == FLOAT_T && type == INT_T) {
        result = new_attr(INT_T, NULL);
        result->value.iv = (int)attr1->value.fv;
    }
    else if(type1 == INT_T && type ==INT_T) {
        result = new_attr(INT_T, NULL);
        result->value.iv = attr1->value.iv;
    }
    else if(type1 == FLOAT_T && type == FLOAT_T) {
        result = new_attr(FLOAT_T, NULL);
        result->value.fv = attr1->value.fv;
    }
    else
        die(lno, "cast_operator: illegal type conversion ");

    if(rm_attr1==FLAG_DESTROY_ATTR) destroy_attr(attr1);
    return result;
}
Exemple #2
0
static Attribute* math_operator( Attribute* attr1, Attribute* attr2, int op, int lno) {
    if(attr1==NULL || attr2==NULL)
		die(lno, "NULL pointer for attr1 or attr2\n");
    int type1 = attr1->type, type2 = attr2->type, resultype;
    Attribute* result;
    if(type1 == INT_T && type2 == INT_T) {
        result = new_attr(INT_T, NULL);
        resultype = INT_T;
    }
    else if (type1 == INT_T && type2 == FLOAT_T ||
                type1 == FLOAT_T && type2 == FLOAT_T ||
                    type1 == FLOAT_T && type2 == INT_T) {
        result = new_attr(FLOAT_T, NULL);
        resultype = FLOAT_T;
    }
    if(resultype == INT_T || resultype == FLOAT_T){
        switch (op) {
            case OP_ADD :
                if(resultype == INT_T) 
                    result->value.iv = attr1->value.iv + attr2->value.iv;
                else if (resultype == FLOAT_T)
                    result->value.fv = attr1->value.fv + attr2->value.fv;
                else
                    die(lno, "math_operator: coding error\n");
				break;
            case OP_SUB :
                if(resultype == INT_T)
                    result->value.iv = attr1->value.iv - attr2->value.iv;
                else if (resultype == FLOAT_T)
                    result->value.fv = attr1->value.fv - attr2->value.fv;
                else
                    die(lno, "math_operator: coding error\n");
				break;
            case OP_MUL :
                if(resultype == INT_T)
                    result->value.iv = attr1->value.iv * attr2->value.iv;
                else if (resultype == FLOAT_T)
                    result->value.fv = attr1->value.fv * attr2->value.fv;
                else
                    die(lno, "math_operator: coding error\n");
				break;
            case OP_DIV :
                if(resultype == INT_T)
                    result->value.iv = attr1->value.iv / attr2->value.iv;
                else if (resultype == FLOAT_T)
                    result->value.fv = attr1->value.fv / attr2->value.fv;
                else
                    die(lno, "math_operator: coding error\n");
				break;
            default:
                die(lno, "math_operator: unsupported op %d.\n",op);
        }
    }
    else
                die(lno, "math_operator: unsupported op %d.\n",op);
    return result;
}
Exemple #3
0
Fichier : bsr.c Projet : AlD/bareos
static int match_fileregex(BSR *bsr, DEV_RECORD *rec, JCR *jcr)
{
   if (bsr->fileregex_re == NULL)
      return 1;

   if (bsr->attr == NULL) {
      bsr->attr = new_attr(jcr);
   }

   /*
    * The code breaks if the first record associated with a file is
    * not of this type
    */
   if (rec->maskedStream == STREAM_UNIX_ATTRIBUTES ||
       rec->maskedStream == STREAM_UNIX_ATTRIBUTES_EX) {
      bsr->skip_file = false;
      if (unpack_attributes_record(jcr, rec->Stream, rec->data, rec->data_len, bsr->attr)) {
         if (regexec(bsr->fileregex_re, bsr->attr->fname, 0, NULL, 0) == 0) {
            Dmsg2(dbglevel, "Matched pattern, fname=%s FI=%d\n",
                  bsr->attr->fname, rec->FileIndex);
         } else {
            Dmsg2(dbglevel, "Didn't match, skipping fname=%s FI=%d\n",
                  bsr->attr->fname, rec->FileIndex);
            bsr->skip_file = true;
         }
      }
   }
   return 1;
}
Exemple #4
0
int SubGraphs::edit_attributes( void *object)
{
  attr_sItem	items[10];
  int		i;
  grow_sAttrInfo	*grow_info, *grow_info_p;
  int			grow_info_cnt;
  Attr		        *attr;
  subgraphs_tAttr 	attrlist_p;
  int			trace_type;
  int			dyn_type2;
  int			dyn_action_type1;
  int			dyn_action_type2;

  grow_GetObjectAttrInfo( (grow_tObject)object, NULL, &grow_info, &grow_info_cnt);
  grow_GetNodeClassDynType( object, &trace_type, &dyn_type2, &dyn_action_type1, &dyn_action_type2);

  grow_info_p = grow_info;
  for ( i = 0; i < grow_info_cnt; i++)
  {
    items[i].value = grow_info_p->value_p;
    strcpy( items[i].name, grow_info_p->name);
    if ( grow_info_p->type == glow_eType_TraceColor)
    {
      switch ( trace_type)
      {
        case graph_eTrace_DigTone:
        case graph_eTrace_DigToneWithError:
          items[i].type = glow_eType_ToneOrColor;
          break;
        default:
          items[i].type = glow_eType_Color;
      }
    }
    else
      items[i].type = grow_info_p->type;
    items[i].size = grow_info_p->size;
    items[i].minlimit = 0;
    items[i].maxlimit = 0;
    if ( strcmp( grow_info_p->name, "Extern") == 0)
      items[i].noedit = 0;
    else
      items[i].noedit = 1;
    items[i].multiline = grow_info_p->multiline;
    grow_info_p++;
  }

  attr = new_attr( object, items, i);
  attr->client_data = (void *)grow_info;
  attr->close_cb = subgraphs_attr_close_cb;
  attr->redraw_cb = subgraphs_attr_redraw_cb;

  // Insert in attrlist
  attrlist_p = (subgraphs_tAttr) calloc( 1, sizeof( *attrlist_p));
  attrlist_p->attrctx = attr;
  attrlist_p->next = attrlist;
  attrlist = attrlist_p;
  return 1;
}
Exemple #5
0
Attribute* unary_operator(Attribute* attr1, int op,int rm_attr1, int lno) {
    if(attr1 == NULL)
        die(lno, "NULL Attribute error");
    int	type1 = attr1->type;
    Attribute* result;
    switch(op) {
    case OP_PLUS:
        if(type1 == INT_T) {
            result = new_attr(INT_T, NULL);
            result->value.iv = +(attr1->value.iv);
        }
        else if(type1 == FLOAT_T) {
            result = new_attr(FLOAT_T, NULL);
            result->value.fv = +(attr1->value.fv);
        }
        else
            die(lno, "unary_operator: incompatible type.\n");
        break;
    case OP_MINUS:
        if(type1 == INT_T) {
            result = new_attr(INT_T, NULL);
            result->value.iv = -(attr1->value.iv);
        }
        else if(type1 == FLOAT_T) {
            result = new_attr(FLOAT_T, NULL);
            result->value.fv = -(attr1->value.fv);
        }
        else
            die(lno, "unary_operator: incompatible type.\n");
        break;
    case OP_NOT:
        if(type1 == BOOL_T) {
            result = new_attr(BOOL_T, NULL);
            result->value.bv = !(attr1->value.bv);
        }
        else
            die(lno, "unary_operator: incompatible type %d.\n", type1);
        break;
    default:
        die(lno, "unary_operator: unknown operator.\n");
        break;
    }
    if(rm_attr1==FLAG_DESTROY_ATTR) destroy_attr(attr1);
    return result;
}
/**
 * @brief Change the attribute to "@attr"by searching "@label"
 *
 * @param fp_src		File handler of source nvm file
 * @param fp_dest		File handler of Destination nvm file	
 * @param label			Label for attribute to be changed
 * @param attr			The wanted attribute
 *
 * @return 				0		success
 						-1 		failed
 */
static int change_attr(FILE *fp_src, FILE *fp_dest, const char *label, const char *attr)
{
	int ret = -1;
	char buf[MAX_CONFIG_LEN];
	size_t buf_len = sizeof(buf);
	char *rest_buf;
	size_t rest_len;
	int label_len;
	size_t attr_len;
	size_t write_len;

	while (!feof(fp_src))
	{
		buf[0] = '\0';
		label_len = get_label(fp_src, buf, sizeof(buf));
		if (label_len <= 0)
		{ 
			DEBUG("Get label failed\n");
			break;
		}

		rest_len = buf_len - label_len;	
		rest_buf = buf + label_len;

		if (!memcmp(label, buf, strlen(label)))
		{
			attr_len = new_attr(fp_src, rest_buf, rest_len, attr);
			ret = 0;
		}
		else
		{
			attr_len = get_attr_separator(fp_src, rest_buf, rest_len);
		}

		if (attr_len <= 0)
		{
			DEBUG("%s, get attribute failed\n", __FUNCTION__);
			break;
		}

		write_len = label_len + attr_len;

		/*Write one config to nvm files*/
		if (write_len != fwrite(buf, sizeof(char), write_len, fp_dest))
		{
			DEBUG("write error\n");
			return -1;
		}

		if (0 == ret)
		{
			break;
		}
	}

	return ret;
}
Exemple #7
0
Attribute* vertex_get_attribute(VertexType* v, char* attribute, int autoNew, int lno){
	if(v==NULL)
		die(lno, "NULL vertex in function: vertex_get_attribute()\n");
    Attribute* attr = g_hash_table_lookup(v->attributes, attribute);
    if (attr == NULL && autoNew) {
        attr = new_attr(UNKNOWN_T, NULL);
        g_hash_table_insert( v->attributes, attribute, attr );
    }
    return attr;
}
Exemple #8
0
Attribute* edge_get_attribute(EdgeType* e, char* attribute, int autoNew, int lno){	
    if(e==NULL)
		die(lno, "NULL edge in function: edge_get_attribute()\n");
	Attribute* attr = g_hash_table_lookup(e->attributes, attribute);
    if (attr == NULL && autoNew) {
        attr = new_attr(UNKNOWN_T, NULL);
        g_hash_table_insert( e->attributes, attribute, attr );
    }
    return attr;
}
Exemple #9
0
static void do_extract(char *devname)
{
   struct stat statp;

   enable_backup_privileges(NULL, 1);

   jcr = setup_jcr("bextract", devname, bsr, director, VolumeName, 1); /* acquire for read */
   if (!jcr) {
      exit(1);
   }
   dev = jcr->read_dcr->dev;
   if (!dev) {
      exit(1);
   }
   dcr = jcr->read_dcr;

   /* Make sure where directory exists and that it is a directory */
   if (stat(where, &statp) < 0) {
      berrno be;
      Emsg2(M_ERROR_TERM, 0, _("Cannot stat %s. It must exist. ERR=%s\n"),
         where, be.bstrerror());
   }
   if (!S_ISDIR(statp.st_mode)) {
      Emsg1(M_ERROR_TERM, 0, _("%s must be a directory.\n"), where);
   }

   free(jcr->where);
   jcr->where = bstrdup(where);
   attr = new_attr(jcr);

   compress_buf = get_memory(compress_buf_size);

   acl_data.last_fname = get_pool_memory(PM_FNAME);
   xattr_data.last_fname = get_pool_memory(PM_FNAME);

   read_records(dcr, record_cb, mount_next_read_volume);
   /* If output file is still open, it was the last one in the
    * archive since we just hit an end of file, so close the file.
    */
   if (is_bopen(&bfd)) {
      set_attributes(jcr, attr, &bfd);
   }
   free_attr(attr);

   free_pool_memory(acl_data.last_fname);
   free_pool_memory(xattr_data.last_fname);

   clean_device(jcr->dcr);
   dev->term();
   free_dcr(dcr);
   free_jcr(jcr);

   printf(_("%u files restored.\n"), num_files);
   return;
}
Exemple #10
0
int edge_assign_attribute ( EdgeType* e, char * attr_name, void * val, int type ) {
    if(e==NULL)
		die(-1, "NULL edge in function: edge_assign_attribute()\n");
	if(attr_name==NULL)
		die(-1, "NULL attr_name in function: edge_assign_attribute()\n");
	Attribute* attr = (Attribute*)g_hash_table_lookup(e->attributes, attr_name);
    if (attr != NULL) {
        if ( attr->type != type ) {
    		die(-1, "edge_assign_attribute: attribute type mismatch error \n");
        }
    }
    else {
        attr = new_attr( type, NULL );
        g_hash_table_insert( e->attributes, attr_name, attr );
    }
    assign_attr( attr, type, val );
    return 0;
}
Exemple #11
0
int vertex_assign_attribute(VertexType* v, char* attr_name, void * val, int type ) {
	if(v==NULL)
		die(-1, "NULL vertex in function: vertex_assign_attribute()\n");
	if(attr_name==NULL)
		die(-1, "NULL attr_name in function: vertex_assign_attribute()\n");
    Attribute* attr = (Attribute*)g_hash_table_lookup(v->attributes, attr_name);
    if (attr != NULL) {
        if ( attr->type != type ) {
    		die(-1, "vertex_assign_attribute: attribute type mismatch error \n");
        }
    }
    else {
        attr = new_attr( type, NULL );
        g_hash_table_insert( v->attributes, attr_name, attr );
    }
    assign_attr( attr, type, val );
    return 0;
}
Exemple #12
0
int vertex_assign_attribute(VertexType* v, char* attr_name, void * val, int type ) {
    if(v==NULL)
        die(-1, "NULL vertex in function: vertex_assign_attribute()\n");
    if(attr_name==NULL)
        die(-1, "NULL attr_name in function: vertex_assign_attribute()\n");
    Attribute* attr = (Attribute*)g_hash_table_lookup(v->attributes, attr_name);
    if (attr != NULL) {
        if ( attr->type != type ) {
            die(-1, "vertex_assign_attribute: attribute type mismatch error \n");
        }
    }
    else {
        attr = new_attr( type, NULL );
        g_hash_table_insert( v->attributes, attr_name, attr );
        // GC: in  FileReadWrite.c, when we read a graph from xml, need to append info
        //   to GC
        gcRef( (void *) attr, DYN_ATTR_T );
    }
    assign_attr( attr, type, val );
    return 0;
}
Exemple #13
0
static int ti_refresh( int must )
/*******************************/
{
    int         i;
    int         incr;               // chars per line
    LP_PIXEL    bufp, sbufp;        // buffer and shadow buffer
    LP_PIXEL    pos;                // the address of the current char
    LP_PIXEL    blankStart;         // start of spaces to eos and then complete
                                    // draw
    int         lastattr = -1;
    int         bufSize;
    LP_PIXEL    bufEnd;
    bool        cls = dirty_area.row1;   // line on which we should clr_eos
                                    // and then continue to draw
    bool        done = false;

    // Need these for startup and the refresh key
    if( UserForcedTermRefresh ) {
        // in the case where a user has forced a refresh we must assume
        // the screen is trashed, and so our cursor position is unknown
        OldCol = -1;
        OldRow = -1;
    }
    must |= UserForcedTermRefresh;
    UserForcedTermRefresh = false;

    // Move the cursor & return if dirty box contains no chars
    if( dirty_area.row0 == dirty_area.row1 && dirty_area.col0 == dirty_area.col1 ) {
        ti_hwcursor();
        __flush();
        return( 0 );
    }

    QNXDebugPrintf4( "ti_refresh( %d, %d )->( %d, %d )", dirty_area.row0,
                                    dirty_area.col0, dirty_area.row1, dirty_area.col1 );

    // Disable cursor during draw if we can
    if( UIData->cursor_type != C_OFF ) {
        TI_CURSOR_OFF();
    }

    // Get our new and old buffers
    bufp = UIData->screen.origin;
    sbufp = shadow;

    // Get some screen statistics
    bufSize = UIData->height * UIData->width;
    bufEnd = &UIData->screen.origin[bufSize - 1];
    incr = UIData->screen.increment;

    // Find a place where we could use clear to end of screen
    if( OptimizeTerminfo ) {
        blankStart = NonBlankEnd( bufEnd, bufSize, *bufEnd ) + 1;
    } else {
        blankStart = bufEnd;
    }

    if( blankStart <= UIData->screen.origin && TCAP_CLS ) {
        // if we could do it at the top then we might as well
        // not bother doing anything else
        lastattr = new_attr( UIData->screen.origin->attr, -1 );
        done = true;
    } else {
        lastattr = -1;

        if( !must ) {
            int         r,c;
            int         pos;
            bool        diff = false;

            while( dirty_area.col0 < dirty_area.col1 ) {
                for( r = dirty_area.row0; r < dirty_area.row1; r++ ) {
                    pos = r * incr + dirty_area.col0;
                    if( !PIXELEQUAL( bufp[pos], sbufp[pos] ) ) {
                        diff = true;
                        break;
                    }
                }
                if( diff )
                    break;
                dirty_area.col0++;
            }

            diff = false;
            while( dirty_area.col0 < dirty_area.col1 ) {
                for( r = dirty_area.row0; r < dirty_area.row1; r++ ) {
                    pos = r * incr + dirty_area.col1 - 1;
                    if( !PIXELEQUAL( bufp[pos], sbufp[pos] ) ) {
                        diff = true;
                        break;
                    }
                }
                if( diff )
                    break;
                dirty_area.col1--;
            }

            diff = false;
            while( dirty_area.row0 < dirty_area.row1 ) {
                for( c = dirty_area.col0; c < dirty_area.col1; c++ ) {
                    pos = dirty_area.row0 * incr + c;
                    if( !PIXELEQUAL( bufp[pos], sbufp[pos] ) ) {
                        diff = true;
                        break;
                    }
                }
                if( diff )
                    break;
                dirty_area.row0++;
            }

            diff = false;
            while( dirty_area.row0 < dirty_area.row1 ) {
                for( c = dirty_area.col0; c < dirty_area.col1; c++ ) {
                    pos = ( dirty_area.row1 - 1 ) * incr + c;
                    if( !PIXELEQUAL( bufp[pos], sbufp[pos] ) ) {
                        diff = true;
                        break;
                    }
                }
                if( diff )
                    break;
                dirty_area.row1--; 
            }
        }

        if( OptimizeTerminfo ) {
            // Set cls if drawing box is bottom part (or whole) of screen
            if( dirty_area.col0 == 0 &&
                dirty_area.row1 == UIData->height &&
                dirty_area.col1 == UIData->width &&
                TCAP_CLS ) {

                if( clr_eos[0] != '\0' ) {
                    cls = dirty_area.row0;
                } else if( dirty_area.row0 == 0 ) {
                    cls = 0;
                }
            }

            if( !must ) {
                // Adjust cls so refresh looks pretty
                for( ; cls < dirty_area.row1; cls++ ) {
                    int         pos;
                    int         pos2;

                    pos = cls * incr;
                    pos2 = pos + UIData->width - 1;
                    if( !PIXELEQUAL( bufp[pos], sbufp[pos] )
                      && ( bufp[pos].ch != sbufp[pos2].ch
                      || bufp[pos].attr == sbufp[pos2].attr) ) {
                        break;
                    }
                }
            }

            /*
            if( cls < dirty_area.row1 ) {
                // If cls is set to by this point we've decided to clear the area
                blankStart = bufEnd;
            }
            */
        }
    }

    if( cls == 0 || ( TI_FillColourSet && blankStart < bufp && TCAP_CLS ) ) {
        // Clear the screen if cls is set to 0 or if the screen
        // is supposed to be blank
        if( cls == 0 ) {
            TI_RESTORE_COLOUR();
        }
        TI_CLS();
    } else {
        // we still have work to do if it turned out we couldn't use the
        // blank start after all
        done = false;
    }

    if( !done ) {
        // If the screen isn't completely blank we have to do some work
        int             j;
        bool            ca_valid;       // is cursor address valid?

        int             rcount;         // repeat count
        char            rchar;          // repeated character
        bool            ralt;           // if repeated character is in acs
        int             rcol;           // starting column of repeated chars

        bufp += dirty_area.row0 * incr;
        sbufp += dirty_area.row0 * incr;

        for( i = dirty_area.row0; i < dirty_area.row1; i++ ) {
            ca_valid = false;
            rcount = 0;

            if( i == cls ) {
                TI_RESTORE_COLOUR();
                TI_CURSOR_MOVE( 0, i );
                putp( clr_eos );
                ca_valid = true;
                //assert( dirty_area.col0==0 && dirty_area.col1==UIData->width );
            }

            for( j = dirty_area.col0; j < dirty_area.col1; j++ ) {
                pos = &bufp[j];
                if( !must && (
                    ( cls <= i )
                    ? ( bufp[j].ch == ' ' && ( (bufp[j].attr & 0x70) == 0 ) )
                    : ( PIXELEQUAL( bufp[j], sbufp[j] ) && pos <= blankStart ) ) ) {
                    ca_valid = false;
                    continue;
                }

                if( !ca_valid ) {
                    QNXDebugPrintf2( "cursor address %d, %d\n", j, i );

                    // gotta dump chars before we move
                    TI_DUMPCHARS();
                    TI_CURSOR_MOVE( j, i );
                    ca_valid = true;
                }

                if( bufp[j].attr != lastattr ) {
                    // dump before changing attrs too...
                    TI_DUMPCHARS();
                    lastattr = new_attr( bufp[j].attr, lastattr );
                }

                // Clear to end of screen if we can
                if( pos > blankStart ) {
                    if( TI_FillColourSet ) {
                        // Dump before blank to end of screen...
                        TI_DUMPCHARS();
                        putp( clr_eos );
                        update_shadow();
                        return( 0 );
                    } else {
                        pos = bufEnd;
                    }
                }

                if( !TI_ignore_bottom_right || (j != UIData->width - 1) || (i != UIData->height - 1) ) {
                    // slurp up the char
                    TI_SLURPCHAR( bufp[j].ch );
                    OldCol++;

                    // if we walk off the edge our position is undefined
                    if( OldCol >= UIData->width ) {
                        OldCol = -1;
                        OldRow = -1;
                    }
                }
            }
            // Make sure we dump any stragglers
            TI_DUMPCHARS();

            bufp += incr;
            sbufp += incr;
        }
    }

    update_shadow();
    return( 0 );
}
Exemple #14
0
static int td_refresh( int must )
/*******************************/
{
    int             i;
    int             incr;
    LP_PIXEL        bufp, sbufp;

    must |= UserForcedTermRefresh;
    UserForcedTermRefresh = false;

    if( dirty_area.row0 == dirty_area.row1 && dirty_area.col0 == dirty_area.col1 ) {
        td_hwcursor();
        __flush();
        return( 0 );
    }

QNXDebugPrintf4("td_refresh (%d,%d)->(%d,%d)", dirty_area.row0, dirty_area.col0, dirty_area.row1, dirty_area.col1);

    if( UIData->cursor_type != C_OFF )
        QNX_CURSOR_OFF();

    bufp = UIData->screen.origin;
    incr = UIData->screen.increment;
    sbufp = shadow;
    bufp += dirty_area.row0 * incr;
    sbufp += dirty_area.row0 * incr;

/*-
* minimize updates
*/
    for( i = dirty_area.row0; i < dirty_area.row1; i++ ) {
        int     j;
        int     lastattr = -1;      // invalid to start
        bool    ca_valid = false;   // is cursor address valid?

        for( j = dirty_area.col0; j < dirty_area.col1; j++ ) {
            if( !must && PIXELEQUAL( bufp[j], sbufp[j] ) ) {
                ca_valid = false;
                lastattr = -1;
                continue;
            }

            if( !ca_valid ) {
QNXDebugPrintf2("cursor address %d,%d\n",j,i);
                QNX_CURSOR_MOVE( j, i );
                ca_valid = true;
            }
            if( bufp[j].attr != lastattr ) {
                lastattr = new_attr( bufp[j].attr, lastattr );
            }
            if( bufp[j].ch < 0x20 )
                __putchar( 033 );
            __putchar( bufp[j].ch );
            sbufp[j] = bufp[j];
        }
        bufp += incr;
        sbufp += incr;
    }
    dirty_area.row0 = dirty_area.row1 = 0;
    dirty_area.col0 = dirty_area.col1 = 0;

    td_hwcursor();
    __flush();

    return( 0 );
}
Exemple #15
0
int
be_visitor_interface_ss::gen_abstract_ops_helper (
  be_interface *node,
  be_interface *base,
  TAO_OutStream *os)
{
  if (!base->is_abstract ())
    {
      return 0;
    }

  AST_Decl *d = 0;
  be_visitor_context ctx;
  ctx.stream (os);
  ctx.state (TAO_CodeGen::TAO_ROOT_SS);

  for (UTL_ScopeActiveIterator si (base, UTL_Scope::IK_decls);
       !si.is_done ();
       si.next ())
    {
      d = si.item ();

      if (d == 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("be_visitor_interface_ss::")
                             ACE_TEXT ("gen_abstract_ops_helper - ")
                             ACE_TEXT ("bad node in this scope\n")),
                            -1);
        }

      AST_Decl::NodeType nt = d->node_type ();

      UTL_ScopedName *item_new_name = 0;
      UTL_ScopedName *new_name = 0;

      if (AST_Decl::NT_op == nt || AST_Decl::NT_attr == nt)
        {
          ACE_NEW_RETURN (item_new_name,
                          UTL_ScopedName (d->local_name ()->copy (),
                                          0),
                          -1);

          new_name = (UTL_ScopedName *) node->name ()->copy ();
          new_name->nconc (item_new_name);
        }
      else
        {
          continue;
        }

      // We pass the node's is_abstract flag to the operation
      // constructor so we will get the right generated operation
      // body if we are regenerating an operation from an
      // abstract interface in a concrete interface or component.
      if (AST_Decl::NT_op == nt)
        {
          be_operation *op = be_operation::narrow_from_decl (d);
          UTL_ScopedName *old_name =
            (UTL_ScopedName *) op->name ()->copy ();
          op->set_name (new_name);
          op->set_defined_in (node);
          op->is_abstract (node->is_abstract ());

          be_visitor_operation_ss op_visitor (&ctx);
          op_visitor.visit_operation (op);

          op->set_name (old_name);
          op->set_defined_in (base);
          op->is_abstract (base->is_abstract ());
        }
      else if (AST_Decl::NT_attr == nt)
        {
          AST_Attribute *attr =
            AST_Attribute::narrow_from_decl (d);
          be_attribute new_attr (attr->readonly (),
                                 attr->field_type (),
                                 0,
                                 attr->is_local (),
                                 attr->is_abstract ());
          new_attr.set_defined_in (node);
          new_attr.set_name (new_name);

          UTL_ExceptList *get_exceptions =
            attr->get_get_exceptions ();

          if (0 != get_exceptions)
            {
              new_attr.be_add_get_exceptions (get_exceptions->copy ());
            }

          UTL_ExceptList *set_exceptions =
            attr->get_set_exceptions ();

          if (0 != set_exceptions)
            {
              new_attr.be_add_set_exceptions (set_exceptions->copy ());
            }

          be_visitor_attribute attr_visitor (&ctx);
          attr_visitor.visit_attribute (&new_attr);
          ctx.attribute (0);
          new_attr.destroy ();
        }
    }

  return 0;
}
Exemple #16
0
/* convert XMLRPC_REQUEST to soap xml dom. */
xml_element* SOAP_REQUEST_to_xml_element(XMLRPC_REQUEST request) {
	xml_element* root = xml_elem_new();

	/* safety first. */
	if (root) {
		xml_element* body = xml_elem_new();
		root->name = strdup("SOAP-ENV:Envelope");

		/* silly namespace stuff */
		Q_PushTail(&root->attrs, new_attr("xmlns:SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/"));
		Q_PushTail(&root->attrs, new_attr("xmlns:xsi", "http://www.w3.org/1999/XMLSchema-instance"));
		Q_PushTail(&root->attrs, new_attr("xmlns:xsd", "http://www.w3.org/1999/XMLSchema"));
		Q_PushTail(&root->attrs, new_attr("xmlns:SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/"));
		Q_PushTail(&root->attrs, new_attr("xmlns:si", "http://soapinterop.org/xsd"));
		Q_PushTail(&root->attrs, new_attr("xmlns:ns6", "http://testuri.org"));
		Q_PushTail(&root->attrs, new_attr("SOAP-ENV:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/"));

		/* Q_PushHead(&root->attrs, new_attr("xmlns:ks", "http://kitchen.sink.org/soap/everything/under/sun"));
		       JUST KIDDING!! :-)  ---->                ------------------------------------------------- */

		if (body) {
			/* go ahead and serialize first... */
			xml_element* el_serialized =  
			SOAP_to_xml_element_worker(request, 
												XMLRPC_RequestGetData(request));

			/* check for fault, in which case, there is no intermediate element */
			if (el_serialized && !strcmp(el_serialized->name, TOKEN_FAULT)) {
				Q_PushTail(&body->children, el_serialized);
			}
			/* usual case: not a fault. Add Response element in between. */
			else {
				xml_element* rpc = xml_elem_new();

				if (rpc) {
					const char* methodname = XMLRPC_RequestGetMethodName(request);
					XMLRPC_REQUEST_TYPE rtype = XMLRPC_RequestGetRequestType(request);

					/* if we are making a request, we want to use the methodname as is. */
					if (rtype == xmlrpc_request_call) {
						if (methodname) {
							rpc->name = strdup(methodname);
						}
					}
					/* if it's a response, we append "Response". Also, given xmlrpc-epi
					   API/architecture, it's likely that we don't have a methodname for
					   the response, so we have to check that. */
					else {
						char buf[128];
						snprintf(buf, sizeof(buf), "%s%s", 
									methodname ? methodname : "",
									"Response");

						rpc->name = strdup(buf);
					}

					/* add serialized data to method call/response.
					   add method call/response to body element */
					if (rpc->name) {
						if(el_serialized) {
							if(Q_Size(&el_serialized->children) && rtype == xmlrpc_request_call) {
								xml_element* iter = (xml_element*)Q_Head(&el_serialized->children);
								while(iter) {
									Q_PushTail(&rpc->children, iter);
									iter = (xml_element*)Q_Next(&el_serialized->children);
								}
								xml_elem_free_non_recurse(el_serialized);
							}
							else {
								Q_PushTail(&rpc->children, el_serialized);
							}
						}

						Q_PushTail(&body->children, rpc);
					}
					else {
						/* no method name?!
						   TODO: fault here...? */
					}
				}
			}
			body->name = strdup("SOAP-ENV:Body");
			Q_PushTail(&root->children, body);
		}
	}

	return root;
}
Exemple #17
0
Attribute* new_attr_STRING_T(GString* s) {
    return new_attr(STRING_T, s);
}
Exemple #18
0
Attribute* new_attr_BOOL_T(bool b) {
    return new_attr(BOOL_T, &b);
}
Exemple #19
0
Attribute* new_attr_FLOAT_T(float f) {
    return new_attr(FLOAT_T, &f);
}
Exemple #20
0
/* translates data structures to soap/xml. recursive */
xml_element* SOAP_to_xml_element_worker(XMLRPC_REQUEST request, XMLRPC_VALUE node) {
#define BUF_SIZE 128
	xml_element* elem_val = NULL;
	if (node) {
		int bFreeNode = 0;  /* sometimes we may need to free 'node' variable */
		char buf[BUF_SIZE];
		XMLRPC_VALUE_TYPE_EASY type = XMLRPC_GetValueTypeEasy(node);
		char* pName = NULL, *pAttrType = NULL;

		/* create our return value element */
		elem_val = xml_elem_new();

		switch (type) {
		case xmlrpc_type_struct:
		case xmlrpc_type_mixed:
		case xmlrpc_type_array:
			if (type == xmlrpc_type_array) {
				/* array's are _very_ special in soap.
				   TODO: Should handle sparse/partial arrays here. */

				/* determine soap array type. */
				const char* type = get_array_soap_type(node);
				xml_element_attr* attr_array_type = NULL;

				/* specify array kids type and array size. */
				snprintf(buf, sizeof(buf), "%s[%i]", type, XMLRPC_VectorSize(node));
				attr_array_type = new_attr(TOKEN_ARRAY_TYPE, buf);

				Q_PushTail(&elem_val->attrs, attr_array_type);

				pAttrType = TOKEN_ARRAY;
			}
			/* check for fault, which is a rather special case. 
			   (can't these people design anything consistent/simple/elegant?) */
			else if (type == xmlrpc_type_struct) {
				int fault_type = get_fault_type(node);
				if (fault_type) {
					if (fault_type == 1) {
						/* gen fault from xmlrpc style fault codes              
						    notice that we get a new node, which must be freed herein. */
						node = gen_fault_xmlrpc(node, elem_val);
						bFreeNode = 1;
					}
					pName = TOKEN_FAULT;
				}
			}

			{
				/* recurse through sub-elements */
				XMLRPC_VALUE xIter = XMLRPC_VectorRewind(node);
				while ( xIter ) {
					xml_element* next_el = SOAP_to_xml_element_worker(request, xIter);
					if (next_el) {
						Q_PushTail(&elem_val->children, next_el);
					}
					xIter = XMLRPC_VectorNext(node);
				}
			}

			break;

			/* handle scalar types */
		case xmlrpc_type_empty:
			pAttrType = TOKEN_NULL;
			break;
		case xmlrpc_type_string:
			pAttrType = TOKEN_STRING;
			simplestring_addn(&elem_val->text, XMLRPC_GetValueString(node), XMLRPC_GetValueStringLen(node));
			break;
		case xmlrpc_type_int:
			pAttrType = TOKEN_INT;
			snprintf(buf, BUF_SIZE, "%i", XMLRPC_GetValueInt(node));
			simplestring_add(&elem_val->text, buf);
			break;
		case xmlrpc_type_boolean:
			pAttrType = TOKEN_BOOLEAN;
			snprintf(buf, BUF_SIZE, "%i", XMLRPC_GetValueBoolean(node));
			simplestring_add(&elem_val->text, buf);
			break;
		case xmlrpc_type_double:
			pAttrType = TOKEN_DOUBLE;
			snprintf(buf, BUF_SIZE, "%f", XMLRPC_GetValueDouble(node));
			simplestring_add(&elem_val->text, buf);
			break;
		case xmlrpc_type_datetime:
			{
				time_t tt = XMLRPC_GetValueDateTime(node);
				struct tm *tm = localtime (&tt);
				pAttrType = TOKEN_DATETIME;
				if(strftime (buf, BUF_SIZE, "%Y-%m-%dT%H:%M:%SZ", tm)) {
					simplestring_add(&elem_val->text, buf);
				}
			}
			break;
		case xmlrpc_type_base64:
			{
				struct buffer_st buf;
				pAttrType = TOKEN_BASE64;
				base64_encode_xmlrpc(&buf, XMLRPC_GetValueBase64(node), XMLRPC_GetValueStringLen(node));
				simplestring_addn(&elem_val->text, buf.data, buf.offset );
				buffer_delete(&buf);
			}
			break;
			break;
		default:
			break;
		}

		/* determining element's name is a bit tricky, due to soap semantics. */
		if (!pName) {
			/* if the value's type is known... */
			if (pAttrType) {
				/* see if it has an id (key). If so, use that as name, and type as an attribute. */
				pName = (char*)XMLRPC_GetValueID(node);
				if (pName) {
					Q_PushTail(&elem_val->attrs, new_attr(TOKEN_TYPE, pAttrType));
				}

				/* otherwise, use the type as the name. */
				else {
					pName = pAttrType;
				}
			}
			/* if the value's type is not known... (a rare case?) */
			else {
				/* see if it has an id (key). otherwise, default to generic "item" */
				pName = (char*)XMLRPC_GetValueID(node);
				if (!pName) {
					pName = "item";
				}
			}
		}
		elem_val->name = strdup(pName);

		/* cleanup */
		if (bFreeNode) {
			XMLRPC_CleanupValue(node);
		}
	}
	return elem_val;
}
Exemple #21
0
int
be_visitor_interface_sh::gen_abstract_ops_helper (
  be_interface *node,
  be_interface *base,
  TAO_OutStream *os)
{
  if (!base->is_abstract ())
    {
      return 0;
    }

  AST_Decl *d = 0;
  be_visitor_context ctx;
  ctx.stream (os);
  ctx.state (TAO_CodeGen::TAO_ROOT_SH);

  for (UTL_ScopeActiveIterator si (base, UTL_Scope::IK_decls);
       !si.is_done ();
       si.next ())
    {
      d = si.item ();

      if (d == 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("be_visitor_interface_sh::")
                             ACE_TEXT ("gen_abstract_ops_helper - ")
                             ACE_TEXT ("bad node in this scope\n")),
                            -1);
        }

      UTL_ScopedName item_new_name (d->local_name (),
                                    0);

      if (d->node_type () == AST_Decl::NT_op)
        {
          be_operation *op = be_operation::narrow_from_decl (d);
          be_visitor_operation_sh op_visitor (&ctx);
          op_visitor.visit_operation (op);
        }
      else if (d->node_type () == AST_Decl::NT_attr)
        {
          AST_Attribute *attr = AST_Attribute::narrow_from_decl (d);
          be_attribute new_attr (attr->readonly (),
                                 attr->field_type (),
                                 &item_new_name,
                                 attr->is_local (),
                                 attr->is_abstract ());
          new_attr.set_defined_in (node);

          UTL_ExceptList *get_exceptions = attr->get_get_exceptions ();

          if (0 != get_exceptions)
            {
              new_attr.be_add_get_exceptions (get_exceptions->copy ());
            }

          UTL_ExceptList *set_exceptions = attr->get_set_exceptions ();

          if (0 != set_exceptions)
            {
              new_attr.be_add_set_exceptions (set_exceptions->copy ());
            }

          be_visitor_attribute attr_visitor (&ctx);
          attr_visitor.visit_attribute (&new_attr);
          ctx.attribute (0);
          new_attr.destroy ();
        }
    }

  return 0;
}
Exemple #22
0
static Attribute* math_operator( Attribute* attr1, Attribute* attr2, int op, int lno) {
    if(attr1==NULL || attr2==NULL)
        die(lno, "NULL pointer for attr1 or attr2\n");
    int type1 = attr1->type, type2 = attr2->type, resultype = UNKNOWN_T;
    int ia1 = 0, ia2 = 0;
    float fa1 = 0., fa2 = 0.;
    Attribute* result;
    if(type1 == INT_T && type2 == INT_T) {
        result = new_attr(INT_T, NULL);
        resultype = INT_T;
        ia1 = attr1->value.iv;
        ia2 = attr2->value.iv;
    }
    else if (type1 == INT_T && type2 == FLOAT_T ||
             type1 == FLOAT_T && type2 == FLOAT_T ||
             type1 == FLOAT_T && type2 == INT_T) {
        result = new_attr(FLOAT_T, NULL);
        resultype = FLOAT_T;
        if(type1 == INT_T) fa1 = (float) attr1->value.iv;
        else fa1 = attr1->value.fv;
        if(type2 == INT_T) fa2 = (float) attr2->value.iv;
        else fa2 = attr2->value.fv;
    }
    if(resultype == INT_T || resultype == FLOAT_T) {
        switch (op) {
        case OP_ADD :
            if(resultype == INT_T)
                result->value.iv = ia1 + ia2;
            else if (resultype == FLOAT_T)
                result->value.fv = fa1 + fa2;
            else
                die(lno, "math_operator: coding error\n");
            break;
        case OP_SUB :
            if(resultype == INT_T)
                result->value.iv = ia1 - ia2;
            else if (resultype == FLOAT_T)
                result->value.fv = fa1 - fa2;
            else
                die(lno, "math_operator: coding error\n");
            break;
        case OP_MUL :
            if(resultype == INT_T)
                result->value.iv = ia1 * ia2;
            else if (resultype == FLOAT_T)
                result->value.fv = fa1 * fa2;
            else
                die(lno, "math_operator: coding error\n");
            break;
        case OP_DIV :
            if(resultype == INT_T)
                result->value.iv = ia1 / ia2;
            else if (resultype == FLOAT_T)
                result->value.fv = fa1 / fa2;
            else
                die(lno, "math_operator: coding error\n");
            break;
        default:
            die(lno, "math_operator: unsupported op %d.\n",op);
        }
    }
    else
        die(lno, "math_operator: unsupported op %d.\n",op);
    return result;
}
Exemple #23
0
Fichier : bls.c Projet : AlD/bareos
int main (int argc, char *argv[])
{
   int i, ch;
   FILE *fd;
   char line[1000];
   char *VolumeName = NULL;
   char *bsrName = NULL;
   char *DirectorName = NULL;
   bool ignore_label_errors = false;
   DIRRES *director = NULL;

   setlocale(LC_ALL, "");
   bindtextdomain("bareos", LOCALEDIR);
   textdomain("bareos");
   init_stack_dump();
   lmgr_init_thread();

   working_directory = "/tmp";
   my_name_is(argc, argv, "bls");
   init_msg(NULL, NULL);              /* initialize message handler */

   OSDependentInit();

   ff = init_find_files();

   while ((ch = getopt(argc, argv, "b:c:D:d:e:i:jkLpvV:?")) != -1) {
      switch (ch) {
      case 'b':
         bsrName = optarg;
         break;

      case 'c':                    /* specify config file */
         if (configfile != NULL) {
            free(configfile);
         }
         configfile = bstrdup(optarg);
         break;

      case 'D':                    /* specify director name */
         if (DirectorName != NULL) {
            free(DirectorName);
         }
         DirectorName = bstrdup(optarg);
         break;

      case 'd':                    /* debug level */
         if (*optarg == 't') {
            dbg_timestamp = true;
         } else {
            debug_level = atoi(optarg);
            if (debug_level <= 0) {
               debug_level = 1;
            }
         }
         break;

      case 'e':                    /* exclude list */
         if ((fd = fopen(optarg, "rb")) == NULL) {
            berrno be;
            Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"),
               optarg, be.bstrerror());
            exit(1);
         }
         while (fgets(line, sizeof(line), fd) != NULL) {
            strip_trailing_junk(line);
            Dmsg1(100, "add_exclude %s\n", line);
            add_fname_to_exclude_list(ff, line);
         }
         fclose(fd);
         break;

      case 'i':                    /* include list */
         if ((fd = fopen(optarg, "rb")) == NULL) {
            berrno be;
            Pmsg2(0, _("Could not open include file: %s, ERR=%s\n"),
               optarg, be.bstrerror());
            exit(1);
         }
         while (fgets(line, sizeof(line), fd) != NULL) {
            strip_trailing_junk(line);
            Dmsg1(100, "add_include %s\n", line);
            add_fname_to_include_list(ff, 0, line);
         }
         fclose(fd);
         break;

      case 'j':
         list_jobs = true;
         break;

      case 'k':
         list_blocks = true;
         break;

      case 'L':
         dump_label = true;
         break;

      case 'p':
         ignore_label_errors = true;
         forge_on = true;
         break;

      case 'v':
         verbose++;
         break;

      case 'V':                    /* Volume name */
         VolumeName = optarg;
         break;

      case '?':
      default:
         usage();

      } /* end switch */
   } /* end while */
   argc -= optind;
   argv += optind;

   if (!argc) {
      Pmsg0(0, _("No archive name specified\n"));
      usage();
   }

   if (configfile == NULL) {
      configfile = bstrdup(CONFIG_FILE);
   }

   my_config = new_config_parser();
   parse_sd_config(my_config, configfile, M_ERROR_TERM);

   LockRes();
   me = (STORES *)GetNextRes(R_STORAGE, NULL);
   if (!me) {
      UnlockRes();
      Emsg1(M_ERROR_TERM, 0, _("No Storage resource defined in %s. Cannot continue.\n"),
            configfile);
   }
   UnlockRes();

  if (DirectorName) {
      foreach_res(director, R_DIRECTOR) {
         if (bstrcmp(director->hdr.name, DirectorName)) {
            break;
         }
      }
      if (!director) {
         Emsg2(M_ERROR_TERM, 0, _("No Director resource named %s defined in %s. Cannot continue.\n"),
               DirectorName, configfile);
      }
   }

   load_sd_plugins(me->plugin_directory, me->plugin_names);

   read_crypto_cache(me->working_directory, "bareos-sd",
                     get_first_port_host_order(me->SDaddrs));

   if (ff->included_files_list == NULL) {
      add_fname_to_include_list(ff, 0, "/");
   }

   for (i=0; i < argc; i++) {
      if (bsrName) {
         bsr = parse_bsr(NULL, bsrName);
      }
      jcr = setup_jcr("bls", argv[i], bsr, director, VolumeName, 1); /* acquire for read */
      if (!jcr) {
         exit(1);
      }
      jcr->ignore_label_errors = ignore_label_errors;
      dev = jcr->dcr->dev;
      if (!dev) {
         exit(1);
      }
      dcr = jcr->dcr;
      rec = new_record();
      attr = new_attr(jcr);
      /*
       * Assume that we have already read the volume label.
       * If on second or subsequent volume, adjust buffer pointer
       */
      if (dev->VolHdr.PrevVolumeName[0] != 0) { /* second volume */
         Pmsg1(0, _("\n"
                    "Warning, this Volume is a continuation of Volume %s\n"),
                dev->VolHdr.PrevVolumeName);
      }

      if (list_blocks) {
         do_blocks(argv[i]);
      } else if (list_jobs) {
         do_jobs(argv[i]);
      } else {
         do_ls(argv[i]);
      }
      do_close(jcr);
   }
   if (bsr) {
      free_bsr(bsr);
   }
   term_include_exclude_files(ff);
   term_find_files(ff);
   return 0;
}
Exemple #24
0
Attribute* new_attr_INT_T(int i) {
    return new_attr(INT_T, &i);
}