~ubuntu-branches/ubuntu/wily/steam/wily

« back to all changes in this revision

Viewing changes to sources/wiki/output.c

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-10-29 19:51:18 UTC
  • mfrom: (1.1.4) (0.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029195118-b9bxciz5hwx5z459
Tags: 1:1.0.0.39-2ubuntu1
Add an epoch to the version number as there was an unrelated steam package
in the archive with a higher version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * output.c
3
 
 *
4
 
 * print to output file.
5
 
 */
6
 
 
7
 
/*
8
 
 * Included headers:
9
 
 *
10
 
 * output: interface to the rest of the world
11
 
 * globals: Program_Name
12
 
 * stdio: fprintf(), fputc(), stderr
13
 
 * stdarg: va_list, va_start(), va_end(), vfprintf()
14
 
 */
15
 
#include "output.h"
16
 
#include "globals.h"
17
 
#include <stdio.h>
18
 
#include <stdarg.h>
19
 
 
20
 
extern char* yyoutbuffer;
21
 
 
22
 
struct OutBlock* new_output()
23
 
{
24
 
  struct OutBlock *out;
25
 
  out = (struct OutBlock*)malloc(sizeof(struct OutBlock));
26
 
  out->nextBlock = NULL;
27
 
  out->addr = NULL;
28
 
  out->size = 0;
29
 
  return out;
30
 
}
31
 
 
32
 
char* get_output(struct OutBlock* o)
33
 
{
34
 
  char*  __out;
35
 
  struct OutBlock* ob;
36
 
  
37
 
  int sz = 0;
38
 
  ob = o;
39
 
  while ( ob != NULL ) {
40
 
    sz += ob->size;
41
 
    ob = ob->nextBlock;
42
 
  }
43
 
  __out = malloc(sz*sizeof(char)+1);
44
 
  __out[0] = '\0';
45
 
  
46
 
  while ( o != NULL ) {
47
 
    if ( o->addr != NULL ) {
48
 
      strcat(__out, o->addr);
49
 
      free(o->addr);
50
 
    }
51
 
    ob = o->nextBlock;
52
 
    free(o);
53
 
    o = ob;
54
 
  }
55
 
  strcat(__out, "\0");
56
 
  return __out;
57
 
}
58
 
 
59
 
#define THIS ((wiki_store*)Pike_fp->current_storage)
60
 
 
61
 
/*
62
 
 * output()
63
 
 *
64
 
 * print the given stuff to the output file
65
 
 */
66
 
void output(char *fmt, ...)
67
 
{
68
 
  va_list args;
69
 
  char* str;
70
 
  int size = strlen(fmt);
71
 
  char* argstr = fmt;
72
 
 
73
 
  va_start(args, fmt);
74
 
  while (*argstr) {
75
 
    switch(*argstr++) {
76
 
    case '%':
77
 
        str = va_arg(args, char*);
78
 
        size += strlen(str);
79
 
        break;
80
 
    default:
81
 
        size++;
82
 
        break;
83
 
    }
84
 
  }
85
 
  va_end(args);
86
 
 
87
 
  char* out = (char*)malloc(sizeof(char)*size);
88
 
  out[0] = '\0';
89
 
 
90
 
  va_start(args, fmt);
91
 
  
92
 
  vsprintf(out, fmt, args);
93
 
  
94
 
  va_end(args);
95
 
 
96
 
  THIS->outCurrent->addr = out;
97
 
  THIS->outCurrent->size = strlen(out);
98
 
  THIS->outCurrent->nextBlock = new_output();
99
 
  THIS->outCurrent = THIS->outCurrent->nextBlock;
100
 
}
101
 
 
102
 
 
103
 
 
104
 
/*
105
 
 * output()
106
 
 *
107
 
 * print the given stuff to the output file
108
 
 */
109
 
void output_cb(char *fmt, int len)
110
 
{
111
 
  char* out = (char*)malloc(sizeof(char)*len+1);
112
 
  strncpy(out, fmt, len);
113
 
  out[len] = '\0';
114
 
 
115
 
  THIS->outCurrent->addr = out;
116
 
  THIS->outCurrent->size = strlen(out);
117
 
  THIS->outCurrent->nextBlock = new_output();
118
 
  THIS->outCurrent = THIS->outCurrent->nextBlock;
119
 
}
120