about summary refs log tree commit diff stats
path: root/update_html
blob: d525ee8d078d584611ac1971c2cd13a5d2bf33fe (plain) (blame)
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
#!/bin/bash
# Regenerate html files.

set -e

( cd linkify; build; )

# generate html/$1.html using /tmp/tags
process() {
  rm -f html/$1.html
  convert_html $1
  linkify/linkify /tmp/tags html/$1.html
  mv html/$1.html.out html/$1.html
}

convert_html() {
  vim -c "set number" -c TOhtml -c write -c qall $1

  sed -i 's,<title>.*/mu/,<title>Mu - ,' $1.html
  sed -i 's,\.html</title>,</title>,' $1.html
  sed -i 's/^\* { \(.*\) }/* { font-size: 12pt; \1 }/g' $1.html
  sed -i 's/^body { \(.*\) }/body { font-size: 12pt; \1 }/g' $1.html
  # turn most code grey
  sed -i 's/#eeeeee/#aaaaaa/g' $1.html
  # ..so that we can use white for cross-links (underlining only on hover)
  sed -i '/^body {/ a  a:hover { text-decoration: underline; }' $1.html
  sed -i '/^body {/ a  a { color:#eeeeee; text-decoration: none; }' $1.html
  # line numbers are darker still
  sed -i 's/^\.LineNr .*/.LineNr { color: #444444; }/' $1.html  # line numbers
  # tweak contrast for remaining colors
  sed -i 's/^\.Constant .*/.Constant { color: #00a0a0; }/' $1.html
  sed -i 's/^\.muControl .*/.muControl { color: #c0a020; }/' $1.html
  # real links in comments continue to be the usual blue
  sed -i 's/^\.Comment .*/.Comment { color: #9090ff; }\n.Comment a { color:#0000ee; text-decoration:underline; }/' $1.html
  sed -i 's/^\.Delimiter .*/.Delimiter { color: #800080; }/' $1.html  # not meant to be read; can be lower-contrast
  sed -i 's/^\.PreProc .*/.PreProc { color: #800080; }/' $1.html  # not meant to be read; can be lower-contrast
  sed -i 's/^\.Identifier .*/.Identifier { color: #c0a020; }/' $1.html  # same as muControl
  sed -i 's/^\.Special .*/.Special { color: #c00000; }/' $1.html  # same as traceAbsent..

  # switch unicode characters around in the rendered html
  #   the ones we have in the source files render double-wide in html
  #   the ones we want in the html cause iTerm2 to slow down in alt-tabbing for some reason
  # the following commands give us the best of both worlds
  sed -i -e 's/┈/╌/g' -e 's/┊/╎/g' $1.html

  mv -i $1.html html/`dirname $1`
}

ctags -x *.cc  |grep -v "^operator \| member \| variable "  > /tmp/tags
for f in *.cc
do
  process $f
done

ctags -x [0-9]*.mu  > /tmp/tags
for f in [0-9]*.mu
do
  process $f
done

for f in [a-zA-Z]*.mu
do
  ctags -x [0-9]*.mu $f  > /tmp/tags
  process $f
done

( cd edit
  ctags -x ../[0-9]*.mu *.mu  > /tmp/tags
)
for f in edit/*.mu
do
  process $f
done

( cd subx
  ctags -x *.cc  |grep -v '^. '  > /tmp/tags  # don't hyperlink every 'i' to the integer register variant
)
for f in subx/*.cc
do
  process $f
done

rm /tmp/tags
( cd linkify; clean; )
ommit/prof_history.c?id=f21cb52ab025cfe1bc90226d7bb433fc775d390e'>f21cb52a ^
8afe2dd1 ^
4531aebd ^
773255b4 ^
8afe2dd1 ^

773255b4 ^
6bad38c2 ^
f21cb52a ^

f21cb52a ^
8afe2dd1 ^
6bad38c2 ^
8afe2dd1 ^

6bad38c2 ^
8afe2dd1 ^
f21cb52a ^




279737ba ^

b6c5fef4 ^
4531aebd ^
b6c5fef4 ^
1730372e ^
b6c5fef4 ^

4531aebd ^



6bad38c2 ^
8afe2dd1 ^

6bad38c2 ^
8afe2dd1 ^
6b1b035d ^
8afe2dd1 ^
4531aebd ^
8afe2dd1 ^
4531aebd ^
b6c5fef4 ^
8afe2dd1 ^

b6c5fef4 ^

8afe2dd1 ^
b6c5fef4 ^


279737ba ^

b6c5fef4 ^
773255b4 ^
8afe2dd1 ^
1730372e ^
4531aebd ^




b6c5fef4 ^

8afe2dd1 ^

6bad38c2 ^
8afe2dd1 ^



279737ba ^

8afe2dd1 ^


6bad38c2 ^
8afe2dd1 ^
6bad38c2 ^
b6c5fef4 ^

8afe2dd1 ^


279737ba ^

8afe2dd1 ^
6bad38c2 ^
8afe2dd1 ^


279737ba ^

8afe2dd1 ^






279737ba ^

8afe2dd1 ^



279737ba ^

8afe2dd1 ^





279737ba ^

8afe2dd1 ^



279737ba ^

8afe2dd1 ^



279737ba ^

8afe2dd1 ^


6bad38c2 ^
8afe2dd1 ^



279737ba ^

8afe2dd1 ^



279737ba ^

8afe2dd1 ^





279737ba ^

8afe2dd1 ^
6bad38c2 ^
8afe2dd1 ^


6bad38c2 ^

8afe2dd1 ^







279737ba ^

8afe2dd1 ^







b6c5fef4 ^
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
  


                                                     
  
















                                                                       






                         






                            
                    
                 
                   
                                       

  
                                                            
                                              









                                                                       
 

                                


                                                              
                                 
 
                                



                       

                                              
 



                              
 
                                 
                                         

               
 
                                 
                                                                 
                                   
         
 
                                         
 
            
                                                      
 
                                   

                                                                    
             
 

                                                   
                
                                               
 

                                                                                
 
                                                    




                                                   

                                                
 
                 
                                 
                    

     



                              
 

                                 
 
                           
                                                                               
                                                                        
 
                                                                
                      
            

                                                      

     
                                                            


                  

                                            
 
                                             
                                                                       
                    




                              

     

                                                  
 



                                                            

                                               


                                                         
 
                                                            
                               

     


                            

                             
 
                                         


                                             

                                






                                      

                              



                                            

                               





                                                               

                                                          



                                            

                                             



                                                         

                                           


                                                                    
                            



                                                                    

                                                



                                                                                

                                 





                                                                     

                                   
 
                                


                                                                 

                                    







                                                                          

                               







                                                                         
 
/*
 * prof_history.c
 *
 * Copyright (C) 2012 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdlib.h>
#include <string.h>

#include <glib.h>

#include "prof_history.h"

struct p_history_session_t {
    GList *items;
    GList *sess_curr;
    GList *sess_new;
    GList *orig_curr;
};

struct p_history_t {
    GList *items;
    guint max_size;
    struct p_history_session_t session;
};

static void _replace_history_with_session(PHistory history);
static gboolean _adding_new(PHistory history);
static void _reset_session(PHistory history);
static gboolean _has_session(PHistory history);
static void _remove_first(PHistory history);
static void _update_current_session_item(PHistory history, char *item);
static void _add_to_history(PHistory history, char *item);
static void _remove_last_session_item(PHistory history);
static void _replace_current_with_original(PHistory history);
static void _create_session(PHistory history);
static void _session_previous(PHistory history);
static void _session_next(PHistory history);

PHistory
p_history_new(unsigned int size)
{
    PHistory new_history = malloc(sizeof(struct p_history_t));
    new_history->items = NULL;
    new_history->max_size = size;

    _reset_session(new_history);

    return new_history;
}

void
p_history_append(PHistory history, char *item)
{
    char *copied = "";
    if (item != NULL) {
        copied = strdup(item);
    }

    if (history->items == NULL) {
        _add_to_history(history, copied);
        return;
    }

    if (!_has_session(history)) {
        if (g_list_length(history->items) == history->max_size) {
            _remove_first(history);
        }

        _add_to_history(history, copied);

    } else {
        _update_current_session_item(history, copied);

        if (_adding_new(history)) {
            if (strcmp(history->session.sess_curr->data, "") == 0) {
                _remove_last_session_item(history);
            }

            _replace_history_with_session(history);

        } else {
            _remove_last_session_item(history);

            char *new = strdup(history->session.sess_curr->data);
            history->session.items = g_list_append(history->session.items, new);

            _replace_current_with_original(history);
            _replace_history_with_session(history);
        }
    }
}

char *
p_history_previous(PHistory history, char *item)
{
    // no history
    if (history->items == NULL) {
        return NULL;
    }

    char *copied = "";
    if (item != NULL) {
        copied = strdup(item);
    }

    if (!_has_session(history)) {
        _create_session(history);

        // add the new item
        history->session.items = g_list_append(history->session.items, copied);
        history->session.sess_new = g_list_last(history->session.items);

        char *result = strdup(history->session.sess_curr->data);
        return result;
    } else {
        _update_current_session_item(history, copied);
        _session_previous(history);
    }

    char *result = strdup(history->session.sess_curr->data);
    return result;
}

char *
p_history_next(PHistory history, char *item)
{
    // no history, or no session, return NULL
    if ((history->items == NULL) || (history->session.items == NULL)) {
        return NULL;
    }

    char *copied = "";
    if (item != NULL) {
        copied = strdup(item);
    }

    _update_current_session_item(history, copied);
    _session_next(history);

    char *result = strdup(history->session.sess_curr->data);
    return result;
}

static void
_replace_history_with_session(PHistory history)
{
    g_list_free(history->items);
    history->items = g_list_copy(history->session.items);

    if (g_list_length(history->items) > history->max_size) {
        _remove_first(history);
    }

    _reset_session(history);
}

static gboolean
_adding_new(PHistory history)
{
    return (history->session.sess_curr ==
        g_list_last(history->session.items));
}

static void
_reset_session(PHistory history)
{
    history->session.items = NULL;
    history->session.sess_curr = NULL;
    history->session.sess_new = NULL;
    history->session.orig_curr = NULL;
}

static gboolean
_has_session(PHistory history)
{
    return (history->session.items != NULL);
}

static void
_remove_first(PHistory history)
{
    GList *first = g_list_first(history->items);
    char *first_item = first->data;
    history->items = g_list_remove(history->items, first_item);
}

static void
_update_current_session_item(PHistory history, char *item)
{
    history->session.sess_curr->data = item;
}

static void
_add_to_history(PHistory history, char *item)
{
    history->items = g_list_append(history->items, item);
}

static void
_remove_last_session_item(PHistory history)
{
    history->session.items = g_list_reverse(history->session.items);
    GList *first = g_list_first(history->session.items);
    history->session.items =
        g_list_remove(history->session.items, first->data);
    history->session.items = g_list_reverse(history->session.items);
}

static void
_replace_current_with_original(PHistory history)
{
    history->session.sess_curr->data = strdup(history->session.orig_curr->data);
}

static void
_create_session(PHistory history)
{
    history->session.items = g_list_copy(history->items);
    history->session.sess_curr = g_list_last(history->session.items);
    history->session.orig_curr = g_list_last(history->items);
}

static void
_session_previous(PHistory history)
{
    history->session.sess_curr =
        g_list_previous(history->session.sess_curr);
    if (history->session.orig_curr == NULL)
        history->session.orig_curr = g_list_last(history->items);
    else
        history->session.orig_curr =
            g_list_previous(history->session.orig_curr);

    if (history->session.sess_curr == NULL) {
        history->session.sess_curr = g_list_first(history->session.items);
        history->session.orig_curr = g_list_first(history->items);
    }
}

static void
_session_next(PHistory history)
{
    history->session.sess_curr = g_list_next(history->session.sess_curr);
    history->session.orig_curr = g_list_next(history->session.orig_curr);

    if (history->session.sess_curr == NULL) {
        history->session.sess_curr = g_list_last(history->session.items);
        history->session.orig_curr = NULL;
    }
}