All pastes #419471 Raw Edit

Unnamed

public c v1 · immutable
·published 2007-04-01 11:11 UTC
rendered paste body
static void tconfig_r_depth_first_write(int depth, FILE *out, struct tconfig_block *tmp){  int i;  if (tmp == NULL)    return;  if (tmp->child != NULL)  {    for(i=0;i<(depth*2);i++)      fputc(' ',out);    fprintf(out,"%s\t%s\n",tmp->key,tmp->value);    for(i=0;i<(depth*2);i++)      fputc(' ',out);    fprintf(out,"{\n");    tmp = tmp->child;    depth++;  }  else if (tmp->next != NULL)  {    for(i=0;i<(depth*2);i++)      fputc(' ',out);    fprintf(out,"%s\t%s\n",tmp->key,tmp->value);    tmp = tmp->next;  }  else  {    for(i=0;i<(depth*2);i++)      fputc(' ',out);    fprintf(out,"%s\t%s\n",tmp->key,tmp->value);    if (depth > 0)    {      while (tmp)      {        if (tmp->next == NULL)        {          if (depth == 0)            return;          while (tmp->parent == NULL)          {            tmp = tmp->prev;          }          tmp = tmp->parent;          depth--;          for(i=0;i<(depth*2);i++)            fputc(' ',out);          fprintf(out,"}\n\n");        }        else        {          tmp = tmp->next;          break;        }      }    }    else      return;  }  tconfig_r_depth_first_write(depth,out,tmp);}/* write a tconfig block back out */void tconfig_to_file(struct tconfig_block *tcfg, char *filename){  FILE *out;  struct tconfig_block *tmp = tcfg;  struct tconfig_block *search;  int indent;  if (tmp == NULL)  {    troll_debug(LOG_WARN,"tconfig_to_file() passed a NULL tconfig block.");    return;  }  if ((out = fopen(filename,"w")) == NULL)  {    troll_debug(LOG_ERROR,"Could not open %s for writing.",filename);    return;  }  tconfig_r_depth_first_write(0,out,tmp);  fclose(out);}