~ubuntu-branches/ubuntu/wily/geany/wily

« back to all changes in this revision

Viewing changes to tagmanager/sort.c

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-12-10 07:43:26 UTC
  • mfrom: (3.3.7 sid)
  • Revision ID: package-import@ubuntu.com-20111210074326-s8yqbew5i20h33tf
Tags: 0.21-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  - debian/patches/20_use_evince_viewer.patch:
     + use evince as viewer for pdf and dvi files
  - debian/patches/20_use_x_terminal_emulator.patch:
     + use x-terminal-emulator as terminal
  - debian/control
     + Add breaks on geany-plugins-common << 0.20
* Also fixes bugs:
  - Filter for MATLAB/Octave files filters everythign (LP: 885505)

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
 *  so have lots of memory if you have large tag files.
106
106
 */
107
107
 
108
 
static void failedSort (FILE *const fp, const char* msg)
 
108
static void failedSort (MIO *const mio, const char* msg)
109
109
{
110
110
    const char* const cannotSort = "cannot sort tag file";
111
 
    if (fp != NULL)
112
 
        fclose (fp);
 
111
    if (mio != NULL)
 
112
        mio_free (mio);
113
113
    if (msg == NULL)
114
114
        error (FATAL | PERROR, "%s", cannotSort);
115
115
    else
127
127
static void writeSortedTags (char **const table, const size_t numTags,
128
128
                             const boolean toStdout)
129
129
{
130
 
    FILE *fp;
 
130
    MIO *mio;
131
131
    size_t i;
132
132
 
133
133
    /*  Write the sorted lines back into the tag file.
134
134
     */
135
135
    if (toStdout)
136
 
        fp = stdout;
 
136
        mio = mio_new_fp (stdout, NULL);
137
137
    else
138
138
    {
139
 
        fp = g_fopen (tagFileName (), "w");
140
 
        if (fp == NULL)
141
 
            failedSort (fp, NULL);
 
139
        mio = mio_new_file_full (tagFileName (), "w", g_fopen, fclose);
 
140
        if (mio == NULL)
 
141
            failedSort (mio, NULL);
142
142
    }
143
143
    for (i = 0 ; i < numTags ; ++i)
144
144
    {
146
146
         *  pattern) if this is not an xref file.
147
147
         */
148
148
        if (i == 0  ||  Option.xref  ||  strcmp (table [i], table [i-1]) != 0)
149
 
            if (fputs (table [i], fp) == EOF)
150
 
                failedSort (fp, NULL);
 
149
            if (mio_puts (mio, table [i]) == EOF)
 
150
                failedSort (mio, NULL);
151
151
    }
152
152
    if (toStdout)
153
 
        fflush (fp);
154
 
    else
155
 
        fclose (fp);
 
153
        fflush (mio_file_get_fp (mio));
 
154
    mio_free (mio);
156
155
}
157
156
 
158
157
extern void internalSortTags (const boolean toStdout)
159
158
{
160
159
    vString *vLine = vStringNew ();
161
 
    FILE *fp = NULL;
 
160
    MIO *mio = NULL;
162
161
    const char *line;
163
162
    size_t i;
164
163
 
170
169
    DebugStatement ( size_t mallocSize = tableSize; )   /* cumulative total */
171
170
 
172
171
    if (table == NULL)
173
 
        failedSort (fp, "out of memory");
 
172
        failedSort (mio, "out of memory");
174
173
 
175
174
    /*  Open the tag file and place its lines into allocated buffers.
176
175
     */
177
 
    fp = g_fopen (tagFileName (), "r");
178
 
    if (fp == NULL)
179
 
        failedSort (fp, NULL);
180
 
    for (i = 0  ;  i < numTags  &&  ! feof (fp)  ;  )
 
176
    mio = mio_new_file_full (tagFileName (), "r", g_fopen, fclose);
 
177
    if (mio == NULL)
 
178
        failedSort (mio, NULL);
 
179
    for (i = 0  ;  i < numTags  &&  ! mio_eof (mio)  ;  )
181
180
    {
182
 
        line = readLine (vLine, fp);
 
181
        line = readLine (vLine, mio);
183
182
        if (line == NULL)
184
183
        {
185
 
            if (! feof (fp))
186
 
                failedSort (fp, NULL);
 
184
            if (! mio_eof (mio))
 
185
                failedSort (mio, NULL);
187
186
            break;
188
187
        }
189
188
        else if (*line == '\0'  ||  strcmp (line, "\n") == 0)
194
193
 
195
194
            table [i] = (char *) g_malloc (stringSize);
196
195
            if (table [i] == NULL)
197
 
                failedSort (fp, "out of memory");
 
196
                failedSort (mio, "out of memory");
198
197
            DebugStatement ( mallocSize += stringSize; )
199
198
            strcpy (table [i], line);
200
199
            ++i;
201
200
        }
202
201
    }
203
202
    numTags = i;
204
 
    fclose (fp);
 
203
    mio_free (mio);
205
204
    vStringDelete (vLine);
206
205
 
207
206
    /*  Sort the lines.