about summary refs log tree commit diff stats
path: root/sys.arc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-10-07 14:01:58 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-10-07 14:02:16 -0700
commitfde987b54f32ecb7c26c42322ab5df48e317c236 (patch)
treecc1dfb5ce46879816427b182e91cf56b709d774e /sys.arc
parentd43f0c54e22161687570ad34efa9df8e5a8a2f53 (diff)
downloadmu-fde987b54f32ecb7c26c42322ab5df48e317c236.tar.gz
120 - forgot to alloc space for array length
Diffstat (limited to 'sys.arc')
0 files changed, 0 insertions, 0 deletions
roject "lynx", label v2-8-1dev_5' href='/ingrix/lynx-snapshots/commit/src/LYEdit.c?id=af9be28bc2701ea448898282942bd5b957439f18'>af9be28b ^
89168f60 ^
e087f6d4
d326f24d ^
8bccca15 ^
d326f24d ^

8bccca15 ^
184855c6 ^

8bccca15 ^
184855c6 ^









8bccca15 ^
184855c6 ^

d326f24d ^
184855c6 ^





8bccca15 ^

e087f6d4
d326f24d ^



f7c3c4ca ^
d326f24d ^
e087f6d4
d326f24d ^


e087f6d4
8bccca15 ^
57bfc74f ^
d326f24d ^
0cb11571 ^
ab1d1ae5 ^


8bccca15 ^
d326f24d ^
1a6a3318 ^
57bfc74f ^
1a6a3318 ^
e087f6d4
d1349dd6 ^
d326f24d ^
d1349dd6 ^
57bfc74f ^
d326f24d ^
57bfc74f ^

d3f9d547 ^
57bfc74f ^

e087f6d4
57bfc74f ^
d326f24d ^
57bfc74f ^
0cb11571 ^
e087f6d4
57bfc74f ^
d326f24d ^

57bfc74f ^


0cb11571 ^
d326f24d ^
a2a1ab1e ^

1a6a3318 ^
a2a1ab1e ^




95586cc2 ^
a2a1ab1e ^

d326f24d ^
a2a1ab1e ^



57bfc74f ^

1a6a3318 ^
57bfc74f ^
d326f24d ^
b6d1143c ^
1a6a3318 ^
57bfc74f ^
8bccca15 ^
e087f6d4
57bfc74f ^
0cb11571 ^
57bfc74f ^
e087f6d4
b6d1143c ^
d326f24d ^
b6d1143c ^
d326f24d ^
d3f9d547 ^
8bccca15 ^
57bfc74f ^

e087f6d4

57bfc74f ^
d326f24d ^
57bfc74f ^





d326f24d ^
57bfc74f ^
8bccca15 ^







d1349dd6 ^
864412f0 ^
d1349dd6 ^
d326f24d ^
d1349dd6 ^
d326f24d ^
d1349dd6 ^
0cb11571 ^
d1349dd6 ^

864412f0 ^
d1349dd6 ^


d326f24d ^
b52ca53f ^

d1349dd6 ^
864412f0 ^
d1349dd6 ^
864412f0 ^
b52ca53f ^
d1349dd6 ^
b52ca53f ^
d1349dd6 ^



d326f24d ^
d1349dd6 ^
8bccca15 ^
e087f6d4
d1349dd6 ^
a2e94617 ^

8bccca15 ^
d1349dd6 ^
8bccca15 ^

d1349dd6 ^
a2e94617 ^
8bccca15 ^
d1349dd6 ^
a2e94617 ^
8bccca15 ^

a2a1ab1e ^

d326f24d ^
383b3f2d ^
a2a1ab1e ^




d326f24d ^
383b3f2d ^
a2a1ab1e ^











a2e94617 ^
a2a1ab1e ^
a2e94617 ^
8bccca15 ^
57bfc74f ^
d1349dd6 ^


8bccca15 ^
95586cc2 ^
d3f9d547 ^
e087f6d4
57bfc74f ^
e087f6d4
d1349dd6 ^





d326f24d ^

d1349dd6 ^


89168f60 ^
d326f24d ^
d1349dd6 ^
89168f60 ^



d1349dd6 ^
89168f60 ^



d1349dd6 ^
89168f60 ^





d1349dd6 ^







57bfc74f ^
d326f24d ^
57bfc74f ^
d326f24d ^


d1349dd6 ^
8bccca15 ^
e087f6d4
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
                    


                     
                    

                         

                   

                
                    
                     
 
                                 
 

                                
          

               
     









                
      

               
 





                                            

 
  



                                                                               
  
                                       
   


                                    
 
                       
                          
 
                                              


                      
                      
 
                                                       
             
      
 
                                                                      
                                   
 
      
                                                   

                                  
                                            

                     
 
      
                                            
       
                                             
 
      

                                                                              


                                 
                                             
                                                                    

                                                 
                                   




                                                  
                                                    

                  
                               



                                                       

                                        
                                   
                       
                                                                        
                             
                                                   
                                           
                      
         
     
      
 
                                                       
      
                                                       
       
                                                
                                       
                  

               

                                              
      
                                            





                  
                                               
       







                                           
                                                  
                  
 
       
      
                                                   
       
                                      

                   
                                                            


                    
                                        

                                              
 
           
                          
      
                                 
                         
                                



                                 
                                                                   
     
                                             
          
                               

                                                         
                                                         
                                                           

                                             
                               
                                                       
                                                         
                                                           
                                                         

                                             

              
                                             
                           




                                                                           
                                                 
                                 











                                                                             
                                                       
      
                                                         
                                             
     


                             
 
                                           
                              
 
                  
 





                                                                  

                                                                             


           
                                 
 
                                                                          



                                           
                                                 



                                                                
                                                                        





                                                                           







                                                           
      
                                                
       


                                          
      
                  
 
#include <HTUtils.h>
#include <HTParse.h>
#include <HTAlert.h>
#include <LYCurses.h>
#include <LYUtils.h>
#include <LYGlobalDefs.h>
#include <LYEdit.h>
#ifdef VMS
#include <unixio.h>
#endif /* VMS */

#include <LYLeaks.h>
#include <www_wait.h>

BOOLEAN editor_can_position(void)
{
    static const char *table[] =
    {
#ifdef VMS
	"sedt",
	"SEDT"
#else
	"emacs",
	"jed",
	"jmacs",
	"joe",
	"jove",
	"jpico",
	"jstar",
	"pico",
	"rjoe",
	"vi"
#endif
    };
    unsigned n;

    for (n = 0; n < TABLESIZE(table); n++) {
	if (strstr(editor, table[n]) != 0) {
	    return TRUE;
	}
    }
    return FALSE;
}

/*
 * In edit mode invoke the given (or default) editor to display and edit the
 * current file.  For editors listed in 'editor_can_position()', Lynx will open
 * the file to the same line that the screen cursor is on (or close...) when
 * editing is invoked.
 *
 * Returns FALSE if file is uneditable.
 */
int edit_current_file(char *newfile,
		      int cur,
		      int lineno)
{
    int result = FALSE;
    char *filename = NULL;

#if !(defined(VMS) || defined(USE_DOS_DRIVES))
    char *colon;
#endif
    char *number_sign;
    char position[80];

#if defined(VMS) || defined(CANT_EDIT_UNWRITABLE_FILES)
    FILE *fp;
#endif

    CTRACE((tfp, "edit_current_file(newfile=%s, cur=%d, lineno=%d)\n",
	    newfile, cur, lineno));

    /*
     * If it's a remote file then we can't edit it.
     */
    if (!LYisLocalFile(newfile)) {
	HTUserMsg(CANNOT_EDIT_REMOTE_FILES);
	return FALSE;
    }

    /*
     * If there's a fragment, trim it.  - FM
     */
    number_sign = trimPoundSelector(newfile);

    /*
     * On Unix, first try to open it as a completely referenced file, then via
     * the path alone.
     *
     * On VMS, only try the path.
     */
#if defined (VMS) || defined (USE_DOS_DRIVES)
    filename = HTParse(newfile, "", PARSE_PATH + PARSE_PUNCTUATION);
    HTUnEscape(filename);
    StrAllocCopy(filename, HTSYS_name(filename));
    if (!LYCanReadFile(filename)) {
#ifdef SH_EX
	HTUserMsg2(COULD_NOT_EDIT_FILE, filename);
#else
	HTAlert(COULD_NOT_ACCESS_FILE);
#endif
	CTRACE((tfp, "filename: '%s'\n", filename));
	goto done;
    }
#else /* something like UNIX */
    if (strncmp(newfile, "file://localhost/", 16) == 0)
	colon = newfile + 16;
    else
	colon = strchr(newfile, ':');
    StrAllocCopy(filename, (colon + 1));
    HTUnEscape(filename);
    if (!LYCanReadFile(filename)) {
	FREE(filename);
	filename = HTParse(newfile, "", PARSE_PATH + PARSE_PUNCTUATION);
	HTUnEscape(filename);
	if (!LYCanReadFile(HTSYS_name(filename))) {
	    HTAlert(COULD_NOT_ACCESS_FILE);
	    goto done;
	}
    }
#endif

#if defined(VMS) || defined(CANT_EDIT_UNWRITABLE_FILES)
    /*
     * Don't allow editing if user lacks append access.
     */
    if ((fp = fopen(filename, TXT_A)) == NULL) {
	HTUserMsg(NOAUTH_TO_EDIT_FILE);
	goto done;
    }
    fclose(fp);
#endif /* VMS || CANT_EDIT_UNWRITABLE_FILES */

    /*
     * Make sure cur is at least zero.  - FM
     */
    if (cur < 0) {
	cur = 0;
    }

    /*
     * Set up the command for the editor.  - FM
     */
    *position = 0;
#ifdef VMS
    lineno--;
#endif
    lineno += (nlinks ? links[cur].ly : 0);
    if (lineno > 0)
	sprintf(position, "%d", lineno);

    edit_temporary_file(filename, position, NULL);
    result = TRUE;

  done:
    /*
     * Restore the fragment if there was one.  - FM
     */
    restorePoundSelector(number_sign);

    FREE(filename);
    CTRACE((tfp, "edit_current_file returns %d\n", result));
    return (result);
}

void edit_temporary_file(char *filename,
			 const char *position,
			 const char *message)
{
#ifdef UNIX
    struct stat stat_info;
#endif
    const char *format = "%s %s";
    char *command = NULL;
    const char *editor_arg = "";
    int params = 1;
    int rv;

    if (strstr(editor, "pico")) {
	editor_arg = " -t";	/* No prompt for filename to use */
    }
    if (editor_can_position() && *position) {
#ifdef VMS
	format = "%s %s -%s%s";
	HTAddXpand(&command, format, params++, editor);
	HTAddParam(&command, format, params++, filename);
	HTAddParam(&command, format, params++, position);
	HTAddParam(&command, format, params++, editor_arg);
	HTEndParam(&command, format, params);
#else
	format = "%s +%s%s %s";
	HTAddXpand(&command, format, params++, editor);
	HTAddParam(&command, format, params++, position);
	HTAddParam(&command, format, params++, editor_arg);
	HTAddParam(&command, format, params++, filename);
	HTEndParam(&command, format, params);
#endif
    }
#ifdef DOSPATH
    else if (strncmp(editor, "VZ", 2) == 0) {
	/* for Vz editor */
	format = "%s %s -%s";
	HTAddXpand(&command, format, params++, editor);
	HTAddParam(&command, format, params++, HTDOS_short_name(filename));
	HTAddParam(&command, format, params++, position);
	HTEndParam(&command, format, params);
    } else if (strncmp(editor, "edit", 4) == 0) {
	/* for standard editor */
	HTAddXpand(&command, format, params++, editor);
	HTAddParam(&command, format, params++, HTDOS_short_name(filename));
	HTEndParam(&command, format, params);
    }
#endif
    else {
#ifdef _WINDOWS
	if (strchr(editor, ' '))
	    HTAddXpand(&command, format, params++, HTDOS_short_name(editor));
	else
	    HTAddXpand(&command, format, params++, editor);
#else
	HTAddXpand(&command, format, params++, editor);
#endif
	HTAddParam(&command, format, params++, filename);
	HTEndParam(&command, format, params);
    }
    if (message != NULL) {
	_statusline(message);
    }

    CTRACE((tfp, "LYEdit: %s\n", command));
    CTRACE_SLEEP(MessageSecs);

    stop_curses();

#ifdef UNIX
    set_errno(0);
#endif
    if ((rv = LYSystem(command)) != 0) {	/* Spawn Editor */
	start_curses();
	/*
	 * If something went wrong, we should probably return soon; currently
	 * we don't, but at least put out a message.  - kw
	 */
	{
#ifdef UNIX
	    int save_err = errno;

	    CTRACE((tfp, "ExtEditForm: system() returned %d (0x%x), %s\n",
		    rv, rv,
		    (save_err
		     ? LYStrerror(save_err)
		     : "reason unknown")));
	    LYFixCursesOn("show error warning:");
	    if (rv == -1) {
		HTUserMsg2(gettext("Error starting editor, %s"),
			   LYStrerror(save_err));
	    } else if (WIFSIGNALED(rv)) {
		HTAlwaysAlert(NULL, gettext("Editor killed by signal"));
	    } else if (WIFEXITED(rv) && WEXITSTATUS(rv) != 127) {
		char exitcode[80];

		sprintf(exitcode, "%d", WEXITSTATUS(rv));
		HTUserMsg2(gettext("Editor returned with error status %s"),
			   exitcode);
	    } else
#endif
		HTAlwaysAlert(NULL, ERROR_SPAWNING_EDITOR);
	}
    } else {
	start_curses();
    }
#ifdef UNIX
    /*
     * Delete backup file, if that's your style.
     */
    HTSprintf0(&command, "%s~", filename);
    if (stat(command, &stat_info) == 0)
	remove(command);
#endif
    FREE(command);
}