Skip to content

Commit 6074996

Browse files
committed
rim 7 rev 6
1 parent e5bd871 commit 6074996

File tree

1 file changed

+46
-54
lines changed

1 file changed

+46
-54
lines changed

zapps/f/rim.c

+46-54
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <profan/syscall.h>
1515
#include <profan/panda.h>
1616
#include <profan/clip.h>
17+
#include <profan/arp.h>
1718
#include <profan.h>
1819

1920
#include <string.h>
@@ -48,7 +49,7 @@
4849
#define COLOR_U 0x80 // unknown character
4950
#define COLOR_W 0x08 // whitespace
5051

51-
#define RIM_VERSION "7 rev 5"
52+
#define RIM_VERSION "7 rev 6"
5253

5354
// GLOBALS
5455
typedef struct {
@@ -860,7 +861,7 @@ char **copy_array(char **array) {
860861
return copy;
861862
}
862863

863-
void rim_syntax_init(char *lang) {
864+
void rim_syntax_init(const char *lang) {
864865
g_rim.syntax = calloc(1, sizeof(rim_syntax_t));
865866

866867
if (!lang)
@@ -936,60 +937,53 @@ void rim_syntax_init(char *lang) {
936937
}
937938

938939
char *compute_args(int argc, char **argv) {
939-
char *file = NULL;
940-
char *ext = NULL;
940+
arp_init("[options] [file]", 1);
941+
arp_set_ver("rim", RIM_VERSION);
942+
943+
arp_register('c', ARP_NEXT_STR, "specify syntax highlighting");
944+
arp_register('n', ARP_STANDARD, "disable syntax highlighting");
945+
arp_register('s', ARP_STANDARD, "always save file at exit");
946+
arp_register('M', ARP_STANDARD, "show a memo of keyboard shortcuts");
947+
arp_register('t', ARP_STANDARD, "always insert tab character");
948+
949+
arp_conflict("nc");
950+
951+
if (arp_parse(argc, argv))
952+
exit(1);
953+
954+
const char *ext = NULL;
941955

942956
g_rim.always_tab = 0;
943957

944-
for (int i = 1; i < argc; i++) {
945-
if (argv[i][0] == '-') {
946-
if (argv[i][1] == 'h') {
947-
puts("Usage: rim [opt] [file]\n"
948-
"Options:\n"
949-
" -c specify syntax highlighting\n"
950-
" -h display this help message\n"
951-
" -n disable syntax highlighting\n"
952-
" -s always save file at exit\n"
953-
" -t always insert tab character\n"
954-
" -v display version information\n"
955-
"\nSyntax highlighting:\n"
956-
" c, lua, py, olv\n"
957-
"\nRim Shortcuts:\n"
958-
" ctrl + q quit\n"
959-
" ctrl + s save\n"
960-
" ctrl + c copy\n"
961-
" ctrl + x cut\n"
962-
" ctrl + v paste\n"
963-
" ctrl + m page down\n"
964-
" ctrl + p page up\n"
965-
" ctrl + a home\n"
966-
" ctrl + e end"
967-
);
968-
exit(0);
969-
} else if (argv[i][1] == 't') {
970-
g_rim.always_tab = 1;
971-
} else if (argv[i][1] == 'n') {
972-
ext = "txt";
973-
} else if (argv[i][1] == 's') {
974-
g_rim.save_at_exit = 1;
975-
} else if (argv[i][1] == 'c') {
976-
if (i + 1 >= argc) {
977-
fprintf(stderr, "rim: missing argument for option -- 'c'\n");
978-
exit(1);
979-
}
980-
ext = argv[++i];
981-
} else if (argv[i][1] == 'v') {
982-
puts("rim version " RIM_VERSION ", profanOS text editor");
983-
exit(0);
984-
} else {
985-
fprintf(stderr, "rim: unknown option -- '%s'\n", argv[i] + 1);
986-
exit(1);
987-
}
988-
} else {
989-
file = argv[i];
990-
}
958+
if (arp_isset('M')) {
959+
puts("Rim Shortcuts:\n"
960+
" ctrl + q quit\n"
961+
" ctrl + s save\n"
962+
" ctrl + c copy\n"
963+
" ctrl + x cut\n"
964+
" ctrl + v paste\n"
965+
" ctrl + m page down\n"
966+
" ctrl + p page up\n"
967+
" ctrl + a home\n"
968+
" ctrl + e end\n\n"
969+
"Syntax highlighting:\n"
970+
" c, lua, py, olv"
971+
);
972+
973+
exit(0);
991974
}
992975

976+
if (arp_isset('t'))
977+
g_rim.always_tab = 1;
978+
if (arp_isset('n'))
979+
ext = "txt";
980+
if (arp_isset('s'))
981+
g_rim.save_at_exit = 1;
982+
if (arp_isset('c'))
983+
ext = arp_get_str('c');
984+
985+
const char *file = arp_file_next();
986+
993987
if (ext == NULL && file) {
994988
ext = strrchr(file, '.');
995989
if (ext) ext++;
@@ -1000,9 +994,7 @@ char *compute_args(int argc, char **argv) {
1000994
if (!file)
1001995
return NULL;
1002996

1003-
file = profan_path_join(profan_wd_path, file);
1004-
1005-
return file;
997+
return profan_path_join(profan_wd_path, file);
1006998
}
1007999

10081000
int main(int argc, char **argv) {

0 commit comments

Comments
 (0)