Exemple #1
0
int save_attr_xml(

  struct attribute_def *padef,   /* pbs_attribute definition array */
  pbs_attribute        *pattr,   /* ptr to pbs_attribute value array */
  int                   numattr, /* number of attributes in array */
  int                   fds)     /* file descriptor where attributes are written */

  {
  int             i;
  int             rc;
  char            buf[MAXLINE<<8];
  char            log_buf[LOCAL_LOG_BUF_SIZE];
  std::string      ds = "";

  /* write the opening tag for attributes */
  snprintf(buf,sizeof(buf),"<attributes>\n");
  if ((rc = write_buffer(buf,strlen(buf),fds)) != 0)
    return(rc);

  for (i = 0; i < numattr; i++)
    {
    if (pattr[i].at_flags & ATR_VFLAG_SET)
      {
      buf[0] = '\0';
      ds.clear();

      if ((rc = attr_to_str(ds, padef+i, pattr[i], TRUE)) != 0)
        {
        if (rc != NO_ATTR_DATA)
          {
          /* ERROR */
          snprintf(log_buf,sizeof(log_buf),
              "Not enough space to print pbs_attribute %s",
              padef[i].at_name);

          return(rc);
          }
        }
      else
        {
        snprintf(buf,sizeof(buf),"<%s>%s</%s>\n",
            padef[i].at_name,
            ds.c_str(),
            padef[i].at_name);

        if ((rc = write_buffer(buf,strlen(buf),fds)) != 0)
          {
          return(rc);
          }
        }
      }
    } /* END for each pbs_attribute */

  /* close the attributes */
  snprintf(buf,sizeof(buf),"</attributes>\n");
  rc = write_buffer(buf,strlen(buf),fds);

  /* we can just return this since its the last write */
  return(rc);
  } /* END save_attr_xml() */
Exemple #2
0
void
ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function,
                     int attr_idx, enum ac_func_attr attr)
{
   const char *attr_name = attr_to_str(attr);
   unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name,
                                                      strlen(attr_name));
   LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(ctx, kind_id, 0);

   if (LLVMIsAFunction(function))
      LLVMAddAttributeAtIndex(function, attr_idx, llvm_attr);
   else
      LLVMAddCallSiteAttribute(function, attr_idx, llvm_attr);
}
Exemple #3
0
/*
 * Create the configuration file
 */
void dialog_create_rc(unsigned char *filename)
{
  int i;
  FILE *rc_file;

  if ((rc_file = fopen(filename, "wt")) == NULL) {
    fprintf(stderr, "\nError opening file for writing in create_rc().\n");
    exit(-1);
  }

  fprintf(rc_file, "#\
\n# Run-time configuration file for dialog\
\n#\
\n# Automatically generated by \"dialog --create-rc <file>\"\
\n#\
\n#\
\n# Types of values:\
\n#\
\n# Number     -  <number>\
\n# String     -  \"string\"\
\n# Boolean    -  <ON|OFF>\
\n# Attribute  -  (foreground,background,highlight?)\
\n#\n\n");

  /* Print an entry for each configuration variable */
  for (i = 0; i < VAR_COUNT; i++) {
    fprintf(rc_file, "\n# %s\n", vars[i].comment);    /* print comment */
    switch (vars[i].type) {
      case VAL_INT:
        fprintf(rc_file, "%s = %d\n", vars[i].name, *((int *) vars[i].var));
        break;
      case VAL_STR:
        fprintf(rc_file, "%s = \"%s\"\n", vars[i].name, (unsigned char *) vars[i].var);
        break;
      case VAL_BOOL:
        fprintf(rc_file, "%s = %s\n", vars[i].name, *((bool *) vars[i].var) ? "ON" : "OFF");
        break;
      case VAL_ATTR:
        fprintf(rc_file, "%s = %s\n", vars[i].name, attr_to_str(((int *) vars[i].var)[0], ((int *) vars[i].var)[1], ((int *) vars[i].var)[2]));
        break;
    }
  }

  fclose(rc_file);
}
void
lp_add_function_attr(LLVMValueRef function_or_call,
                     int attr_idx, enum lp_func_attr attr)
{

#if HAVE_LLVM < 0x0400
   LLVMAttribute llvm_attr = lp_attr_to_llvm_attr(attr);
   if (LLVMIsAFunction(function_or_call)) {
      if (attr_idx == -1) {
         LLVMAddFunctionAttr(function_or_call, llvm_attr);
      } else {
         LLVMAddAttribute(LLVMGetParam(function_or_call, attr_idx - 1), llvm_attr);
      }
   } else {
      LLVMAddInstrAttribute(function_or_call, attr_idx, llvm_attr);
   }
#else

   LLVMModuleRef module;
   if (LLVMIsAFunction(function_or_call)) {
      module = LLVMGetGlobalParent(function_or_call);
   } else {
      LLVMBasicBlockRef bb = LLVMGetInstructionParent(function_or_call);
      LLVMValueRef function = LLVMGetBasicBlockParent(bb);
      module = LLVMGetGlobalParent(function);
   }
   LLVMContextRef ctx = LLVMGetModuleContext(module);

   const char *attr_name = attr_to_str(attr);
   unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name,
                                                      strlen(attr_name));
   LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(ctx, kind_id, 0);

   if (LLVMIsAFunction(function_or_call))
      LLVMAddAttributeAtIndex(function_or_call, attr_idx, llvm_attr);
   else
      LLVMAddCallSiteAttribute(function_or_call, attr_idx, llvm_attr);
#endif
}
Exemple #5
0
/*
 * Create the configuration file
 */
void
dlg_create_rc(const char *filename)
{
    unsigned i;
    FILE *rc_file;

    if ((rc_file = fopen(filename, "wt")) == NULL)
        dlg_exiterr("Error opening file for writing in dlg_create_rc().");

    fprintf(rc_file, "#\n\
# Run-time configuration file for dialog\n\
#\n\
# Automatically generated by \"dialog --create-rc <file>\"\n\
#\n\
#\n\
# Types of values:\n\
#\n\
# Number     -  <number>\n\
# String     -  \"string\"\n\
# Boolean    -  <ON|OFF>\n"
#ifdef HAVE_COLOR
            "\
# Attribute  -  (foreground,background,highlight?)\n"
#endif
           );

    /* Print an entry for each configuration variable */
    for (i = 0; i < VAR_COUNT; i++) {
        fprintf(rc_file, "\n# %s\n", vars[i].comment);
        switch (vars[i].type) {
        case VAL_INT:
            fprintf(rc_file, "%s = %d\n", vars[i].name,
                    *((int *) vars[i].var));
            break;
        case VAL_STR:
            fprintf(rc_file, "%s = \"%s\"\n", vars[i].name,
                    (char *) vars[i].var);
            break;
        case VAL_BOOL:
            fprintf(rc_file, "%s = %s\n", vars[i].name,
                    *((bool *) vars[i].var) ? "ON" : "OFF");
            break;
        }
    }
#ifdef HAVE_COLOR
    for (i = 0; i < (unsigned) dlg_color_count(); ++i) {
        char buffer[MAX_LEN + 1];
        unsigned j;
        bool repeat = FALSE;

        fprintf(rc_file, "\n# %s\n", dlg_color_table[i].comment);
        for (j = 0; j != i; ++j) {
            if (dlg_color_table[i].fg == dlg_color_table[j].fg
                    && dlg_color_table[i].bg == dlg_color_table[j].bg
                    && dlg_color_table[i].hilite == dlg_color_table[j].hilite) {
                fprintf(rc_file, "%s = %s\n",
                        dlg_color_table[i].name,
                        dlg_color_table[j].name);
                repeat = TRUE;
                break;
            }
        }

        if (!repeat) {
            fprintf(rc_file, "%s = %s\n", dlg_color_table[i].name,
                    attr_to_str(buffer,
                                dlg_color_table[i].fg,
                                dlg_color_table[i].bg,
                                dlg_color_table[i].hilite));
        }
    }
#endif /* HAVE_COLOR */
    dlg_dump_keys(rc_file);

    (void) fclose(rc_file);
}
int svr_save_xml(

  struct server *ps,
  int            mode)

  {
  char *id   = "svr_save_xml";
  char  buf[MAXLINE<<8];
  dynamic_string *ds;

  int   fds;
  int   rc;
  int   len;
  int   i;

  fds = open(path_svrdb, O_WRONLY | O_CREAT | O_Sync | O_TRUNC, 0600);

  if (fds < 0)
    {
    log_err(errno,id,msg_svdbopen);

    return(-1);
    }

  /* write the sv_qs info */
  snprintf(buf,sizeof(buf),
    "<server_db>\n<numjobs>%d</numjobs>\n<numque>%d</numque>\n<nextjobid>%d</nextjobid>\n<savetime>%ld</savetime>\n",
    ps->sv_qs.sv_numjobs,
    ps->sv_qs.sv_numque,
    ps->sv_qs.sv_jobidnumber,
    time_now);
  len = strlen(buf);

  if ((rc = write_buffer(buf,len,fds)))
    return(rc);

  /* write the attribute info */
  snprintf(buf,sizeof(buf),"<attributes>");
  if ((rc = write_buffer(buf,strlen(buf),fds)))
    return(rc);

  if ((ds = get_dynamic_string(-1, NULL)) == NULL)
    {
    log_err(ENOMEM, id, "");
    return(ENOMEM);
    }

  i = 0;
  while (i != SRV_ATR_LAST)
    {
    if (ps->sv_attr[i].at_flags & ATR_VFLAG_SET)
      {
      buf[0] = '\0';
      clear_dynamic_string(ds);

      if ((rc = attr_to_str(ds, svr_attr_def + i, ps->sv_attr[i], TRUE) != 0))
        {
        if (rc != NO_ATTR_DATA)
          {
          /* ERROR */
          snprintf(log_buffer,sizeof(log_buffer),
            "Not enough space to print attribute %s",
            svr_attr_def[i].at_name);
          log_err(-1,id,log_buffer);

          free_dynamic_string(ds);
          return(rc);
          }
        }
      else
        {
        snprintf(buf,sizeof(buf),"<%s>%s</%s>\n",
          svr_attr_def[i].at_name,
          ds->str,
          svr_attr_def[i].at_name);
        
        if (buf[0] != '\0')
          {
          if ((rc = write_buffer(buf,strlen(buf),fds)))
            {
            free_dynamic_string(ds);
            return(rc);
            }
          }
        }      
      }

    i++;
    }

  free_dynamic_string(ds);
  
  snprintf(buf,sizeof(buf),"</attributes>\n");
  if ((rc = write_buffer(buf,strlen(buf),fds)))
    return(rc);

  /* close the server_db */
  snprintf(buf,sizeof(buf),"</server_db>");
  if ((rc = write_buffer(buf,strlen(buf),fds)))
    return(rc);

  close(fds);

  return(0);

  } /* END svr_save_xml */
Exemple #7
0
int add_encoded_attributes(

  xmlNodePtr     *attr_node, /* M attribute node */ 
  pbs_attribute  *pattr)     /* M ptr to pbs_attribute value array */

  {
  tlist_head  lhead;
  int         i;
  int         resc_access_perm = ATR_DFLAG_ACCESS;
  svrattrl   *pal;
  int         rc = PBSE_NONE;
  xmlNodePtr  attributeNode = *attr_node;
  char        buf[BUFSIZE];
  xmlNodePtr  pal_xmlNode;

  CLEAR_HEAD(lhead);
  xmlNodePtr  resource_list_head_node = NULL;
  xmlNodePtr  resource_used_head_node = NULL;
  xmlNodePtr  complete_req_head_node = NULL;

  for (i = 0; ((i < JOB_ATR_LAST) && (rc >= 0)); i++)
    {
    if ((job_attr_def[i].at_type != ATR_TYPE_ACL) &&
        ((pattr + i)->at_flags & ATR_VFLAG_SET))
      {
      if ((i != JOB_ATR_resource) &&
          (i != JOB_ATR_resc_used) &&
          (i != JOB_ATR_req_information))
        {
        std::string value;

#ifndef PBS_MOM
        if (i == JOB_ATR_depend)
          translate_dependency_to_string(pattr + i, value);
        else
#endif
          attr_to_str(value, job_attr_def + i, pattr[i], true);

        if (value.size() == 0)
          continue;

        pal_xmlNode = xmlNewChild(attributeNode,
                                  NULL,
                                  (xmlChar *)job_attr_def[i].at_name,
                                  (const xmlChar *)value.c_str());

        if (pal_xmlNode)
          {
          snprintf(buf, sizeof(buf), "%u", (unsigned int)pattr[i].at_flags);
          xmlSetProp(pal_xmlNode, (const xmlChar *)AL_FLAGS_ATTR, (const xmlChar *)buf);
          (pattr + i)->at_flags &= ~ATR_VFLAG_MODIFY;
          }
        }
      else
        {
        rc = job_attr_def[i].at_encode(pattr + i,
            &lhead,
            job_attr_def[i].at_name,
            NULL,
            ATR_ENCODE_SAVE,
            resc_access_perm);
        
        if (rc < 0)
          return -1;

        (pattr + i)->at_flags &= ~ATR_VFLAG_MODIFY;

        while ((pal = (svrattrl *)GET_NEXT(lhead)) != NULL)
          {
          if (i == JOB_ATR_resource)
            {
            pal_xmlNode = add_resource_list_attribute(ATTR_l,
                                                      attr_node,
                                                      &resource_list_head_node,
                                                      pal);
            }
          else if (i == JOB_ATR_req_information)
            {
            pal_xmlNode = add_resource_list_attribute(ATTR_req_information,
                                                      attr_node,
                                                      &complete_req_head_node,
                                                      pal);
            }
          else
            {
            pal_xmlNode = add_resource_list_attribute(ATTR_used,
                                                      attr_node,
                                                      &resource_used_head_node,
                                                      pal);
            }

            if (pal_xmlNode)
              {
              snprintf(buf, sizeof(buf), "%u", (unsigned int)pal->al_flags);
              xmlSetProp(pal_xmlNode, (const xmlChar *)AL_FLAGS_ATTR, (const xmlChar *)buf);
              }

            delete_link(&pal->al_link);
            free(pal);
            if (!pal_xmlNode)
              rc = -1;
          }
        }
      }
    }

  return (0);
  } /* END add_encoded_attributes */