Skip to content

Commit 5c1bbae

Browse files
committed
Finished most of the OPBSD porting work - has trouble with non-EDIT_MODE key input...
1 parent c3b4067 commit 5c1bbae

5 files changed

Lines changed: 30 additions & 12 deletions

File tree

edit.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include <math.h>
3232
#include <limits.h>
3333
#include <sys/stat.h>
34+
#ifdef __OpenBSD__
35+
#include <unistd.h>
36+
#endif
3437

3538
//Define color schemes
3639
#define EDITOR_SCHEME 1
@@ -102,8 +105,8 @@ void key_left(struct Window *, struct Cursor *);
102105
int dialog_input(struct Window *, char *);
103106

104107
//file.c
105-
void open(struct Window *, struct File *);
108+
void open_file(struct Window *, struct File *);
106109
void save(struct Window *, struct File *);
107-
void new(struct Window *, struct File *, struct Cursor *);
110+
void new(struct Window *, struct Cursor *, struct File *);
108111

109112
#endif /* EDIT_H */

file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
#include "edit.h"
2424

25-
void open(struct Window *w, struct File *f)
25+
void open_file(struct Window *w, struct File *f)
2626
/*Opens a file, copies the contents, and
2727
*assesses file permissions
2828
*/
@@ -55,7 +55,7 @@ void save(struct Window *w, struct File *f)
5555
{
5656
f->fp = fopen(f->path, "w");
5757

58-
if (f->fp)
58+
if (!f->ro)
5959
{
6060
fputs(w->contents, f->fp);
6161
fclose(f->fp);
@@ -65,7 +65,7 @@ void save(struct Window *w, struct File *f)
6565
mode=SAVE_AS;
6666
}
6767

68-
void new(struct Window *w, struct File *f, struct Cursor *c)
68+
void new(struct Window *w, struct Cursor *c, struct File *f)
6969
//Creates a blank file
7070
{
7171
f->fp=NULL;

input.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ void get_input(struct Window *w, struct Cursor *c, struct File *f)
141141
case KEY_F(4):
142142
svdmd=NEW_FILE;
143143
if (f->saved)
144+
{
144145
mode=svdmd;
146+
}
145147
else
146148
mode=NOT_SAVED;
147149
break;
@@ -181,7 +183,8 @@ int dialog_input(struct Window *w, char *str)
181183
printw(str);
182184
switch(k = getch())
183185
{
184-
case '\n':
186+
case 10:
187+
str[i]='\0';
185188
return 0;
186189
break;
187190
case KEY_BACKSPACE:
@@ -195,4 +198,5 @@ int dialog_input(struct Window *w, char *str)
195198
i++;
196199
break;
197200
}
201+
return 1;
198202
}

main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ char ln[NAME_MAX]="";
2828

2929
int main(int argc, char *argv[])
3030
{
31+
#ifdef __OpenBSD__
32+
pledge("stdio rpath wpath cpath tty", NULL);
33+
#endif
34+
3135
//Initialize all of our core data structures in memory
3236
struct Window *w = malloc(sizeof(struct Window));
3337
w->contents = calloc(1,array_size(0)*sizeof(char));
@@ -37,12 +41,14 @@ int main(int argc, char *argv[])
3741
c->x=0, c->y=0; c->abs=0; //Make sure our cursor is initialized at position (0, 0)
3842

3943
struct File *f = malloc(sizeof(struct File));
44+
strncpy(f->path, "", PATH_MAX);
45+
f->ro=true;
4046
f->saved=true;
4147

42-
if (argc)
48+
if (argc>1)
4349
{
4450
strcpy(f->path, argv[1]);
45-
open(w, f);
51+
open_file(w, f);
4652
}
4753

4854
//Initialize curses

print.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ void initialize_editor()
3737
init_pair(BOUNDARY_SCHEME, COLOR_BLACK, COLOR_CYAN); //Initialize color pair of black text on a cyan background (for top and bottom boundaries)
3838
keypad(stdscr, true);
3939
cbreak();
40+
//raw();
41+
//nonl();
4042
curs_set(1);
4143
}
4244

@@ -69,7 +71,7 @@ void content_line_print(int r, struct Window *w, struct Cursor *c)
6971
if (r==c->y)
7072
j += (long) c->x-(c->x%w->width)-floor(c->x/w->width);
7173

72-
for (i,j; i < w->width-1 && j+i < get_end_of_line(j, w->contents); i++) //Repeat the following code segment until the rest of the bar is full
74+
for (; i < w->width-1 && j+i < get_end_of_line(j, w->contents); i++) //Repeat the following code segment until the rest of the bar is full
7375
{
7476
if(w->contents[j+i]!='\t')
7577
addch(w->contents[j+i]);
@@ -113,6 +115,7 @@ bool msg_box(struct Window *w, char *msg)
113115
return false;
114116
break;
115117
}
118+
return NULL;
116119
}
117120

118121
void dialog(struct Window *w, char *prompt, char *msg)
@@ -136,6 +139,7 @@ void run_mode(int m, struct Window *w, struct Cursor *c, struct File *f)
136139
*based upon the current given mode of operation
137140
*/
138141
{
142+
int rep;
139143
switch (m)
140144
{
141145
case EDIT_MODE:
@@ -156,16 +160,17 @@ void run_mode(int m, struct Window *w, struct Cursor *c, struct File *f)
156160
dialog(w, "File path:", "Open File");
157161
if(!dialog_input(w,f->path))
158162
{
159-
open(w,f);
163+
open_file(w,f);
160164
m=EDIT_MODE;
161165
}
162166
break;
163167
case NEW_FILE:
164168
dialog(w, "File path:", "New File");
165169
if(!dialog_input(w,f->path))
166170
{
167-
new(w,f,c);
168-
if (f->fp = fopen(f->path, "w"))
171+
new(w,c,f);
172+
f->fp = fopen(f->path, "w");
173+
if (f->fp)
169174
{
170175
f->ro=false;
171176
fclose(f->fp);

0 commit comments

Comments
 (0)