File: wnwtok.c

package info (click to toggle)
libwn6 6.0-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 5,996 kB
  • ctags: 3,938
  • sloc: ansic: 45,083; makefile: 926; csh: 274; sh: 12
file content (165 lines) | stat: -rw-r--r-- 2,901 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/******************************************************************************

wn_write_blanks(stream,num)
wn_write_blanks_until_column(stream,col)
wn_write_linefeed(stream)

wn_write_literal(stream,literal)
wn_write_id(stream,id)

wn_write_int(stream,i)
wn_write_double(stream,f)

wn_write_quoted_string(stream,start_char,string,fin_char)
wn_write_quoted_string_with_backslash(stream,start_char,string,fin_char)

wn_write_literal_n_times(stream,literal,n)

******************************************************************************/
/****************************************************************************

COPYRIGHT NOTICE:

  The source code in this file is provided free of charge
  to the author's consulting clients.  It is in the
  public domain and therefore may be used by anybody for
  any purpose.

AUTHOR:

  Will Naylor

****************************************************************************/

#include <stdio.h>
#include <string.h>

#include "wnlib.h"
#include "wnasrt.h"
#include "wnmax.h"
#include "wnio.h"

#include "wncstr.h"



char wn_prefered_linefeed_char = '\n',
     wn_prefered_blank_char = ' ';


void wn_write_blanks(wn_cstream stream,int num)
{
  int i;

  for(i=0;i<num;i++)
  {
    wn_write_char(stream,wn_prefered_blank_char);
  }
}


void wn_write_linefeed(wn_cstream stream)
{
  wn_assert(stream->pretty_block_level == 0);

  wn_raw_write_literal_char(stream,wn_prefered_linefeed_char);

  wn_linefeed_at_mark(stream,wn_current_mark(stream));
}


void wn_write_blanks_until_column(wn_cstream stream,int col)
{
  int tab_blanks;

  tab_blanks = col - wn_column_of_current_mark(stream);

  wn_write_blanks(stream,wn_max(0,tab_blanks));
}


void wn_write_literal(wn_cstream stream,char *literal)
{
  wn_write_block(stream,literal,strlen(literal));
}


void wn_write_id(wn_cstream stream,char *id)
{
  wn_write_block(stream,id,strlen(id));
}


void wn_write_int(wn_cstream stream,int i)
{
  char buf[50];

  sprintf(buf,"%d",i);

  wn_write_block(stream,buf,strlen(buf));
}


void wn_write_double(wn_cstream stream,double f)
{
  char buf[50];

  sprintf(buf,"%g",(float)f);

  wn_write_block(stream,buf,strlen(buf));
}


void wn_write_quoted_string
(
  wn_cstream stream,
  char start_char,
  char* string,
  char fin_char
)
{
  wn_write_char(stream,start_char);
  wn_write_block(stream,string,strlen(string));
  wn_write_char(stream,fin_char);
}


void wn_write_quoted_string_with_backslash
(
  wn_cstream stream,
  char start_char,
  char *string,
  char fin_char
)
{
  char *pc;

  wn_write_char(stream,start_char);

  for(pc=string;*pc != '\0';++pc)
  {
    if(*pc == fin_char)
    {
      wn_write_char(stream,'\\');
    }

    wn_write_char(stream,*pc);
  }

  wn_write_char(stream,fin_char);
}


void wn_write_literal_n_times(wn_cstream stream,char *literal,int n)
{
  int i;

  for(i=0;i<n;++i)
  {
    wn_write_literal(stream,literal);
  }
}