~ubuntu-branches/ubuntu/lucid/mc/lucid

« back to all changes in this revision

Viewing changes to edit/wordproc.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-09-16 10:38:59 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080916103859-2uwn8w61xk5mbxxq
Tags: 2:4.6.2~git20080311-4
Corrected fix for odt2txt issue (Closes: #492019) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include <config.h>
 
22
 
 
23
#include <stdio.h>
 
24
#include <stdarg.h>
 
25
#include <sys/types.h>
 
26
#ifdef HAVE_UNISTD_H
 
27
#    include <unistd.h>
 
28
#endif
 
29
#include <string.h>
 
30
#include <ctype.h>
 
31
#include <errno.h>
 
32
#include <sys/stat.h>
 
33
 
 
34
#include <stdlib.h>
 
35
 
 
36
#include "../src/global.h"
 
37
 
22
38
#include "edit.h"
23
39
#include "edit-widget.h"
24
40
 
148
164
    }
149
165
}
150
166
 
151
 
/* 
152
 
   This is a copy of the function 
 
167
/*
 
168
   This is a copy of the function
153
169
   int calc_text_pos (WEdit * edit, long b, long *q, int l)
154
170
   in propfont.c  :(
155
171
   It calculates the number of chars in a line specified to length l in pixels
181
197
    return b;
182
198
}
183
199
 
184
 
/* find the start of a word */
185
 
static int next_word_start (unsigned char *t, int q, int size)
 
200
static int
 
201
next_word_start (unsigned char *t, int q, int size)
186
202
{
187
203
    int i;
188
 
    for (i = q;; i++) {
 
204
    int saw_ws = 0;
 
205
 
 
206
    for (i = q; i < size; i++) {
189
207
        switch (t[i]) {
190
208
        case '\n':
191
209
            return -1;
192
210
        case '\t':
193
211
        case ' ':
194
 
            for (;; i++) {
195
 
                if (t[i] == '\n')
196
 
                    return -1;
197
 
                if (t[i] != ' ' && t[i] != '\t')
198
 
                    return i;
199
 
            }
 
212
            saw_ws = 1;
 
213
            break;
 
214
        default:
 
215
            if (saw_ws != 0)
 
216
                return i;
200
217
            break;
201
218
        }
202
219
    }
 
220
    return -1;
203
221
}
204
222
 
205
223
/* find the start of a word */
206
 
static int word_start (unsigned char *t, int q, int size)
 
224
static int
 
225
word_start (unsigned char *t, int q, int size)
207
226
{
208
227
    int i = q;
209
228
    if (t[q] == ' ' || t[q] == '\t')
238
257
            break;
239
258
        p = word_start (t, q, size);
240
259
        if (p == -1)
241
 
            q = next_word_start (t, q, size);   /* Return the end of the word if the beginning 
242
 
                                                   of the word is at the beginning of a line 
 
260
            q = next_word_start (t, q, size);   /* Return the end of the word if the beginning
 
261
                                                   of the word is at the beginning of a line
243
262
                                                   (i.e. a very long word) */
244
263
        else
245
264
            q = p;
258
277
}
259
278
 
260
279
/* replaces a block of text */
261
 
static void put_paragraph (WEdit * edit, unsigned char *t, long p, long q, int indent, int size)
 
280
static void
 
281
put_paragraph (WEdit * edit, unsigned char *t, long p, int indent, int size)
262
282
{
263
283
    long cursor;
264
284
    int i, c = 0;
342
362
        }
343
363
    }
344
364
    format_this (t, q - p, indent);
345
 
    put_paragraph (edit, t, p, q, indent, size);
 
365
    put_paragraph (edit, t, p, indent, size);
346
366
    g_free (t);
347
367
 
348
368
    /* Scroll left as much as possible to show the formatted paragraph */