14
14
#include <profan/syscall.h>
15
15
#include <profan/panda.h>
16
16
#include <profan/clip.h>
17
+ #include <profan/arp.h>
17
18
#include <profan.h>
18
19
19
20
#include <string.h>
48
49
#define COLOR_U 0x80 // unknown character
49
50
#define COLOR_W 0x08 // whitespace
50
51
51
- #define RIM_VERSION "7 rev 5 "
52
+ #define RIM_VERSION "7 rev 6 "
52
53
53
54
// GLOBALS
54
55
typedef struct {
@@ -860,7 +861,7 @@ char **copy_array(char **array) {
860
861
return copy ;
861
862
}
862
863
863
- void rim_syntax_init (char * lang ) {
864
+ void rim_syntax_init (const char * lang ) {
864
865
g_rim .syntax = calloc (1 , sizeof (rim_syntax_t ));
865
866
866
867
if (!lang )
@@ -936,60 +937,53 @@ void rim_syntax_init(char *lang) {
936
937
}
937
938
938
939
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 ;
941
955
942
956
g_rim .always_tab = 0 ;
943
957
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 );
991
974
}
992
975
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
+
993
987
if (ext == NULL && file ) {
994
988
ext = strrchr (file , '.' );
995
989
if (ext ) ext ++ ;
@@ -1000,9 +994,7 @@ char *compute_args(int argc, char **argv) {
1000
994
if (!file )
1001
995
return NULL ;
1002
996
1003
- file = profan_path_join (profan_wd_path , file );
1004
-
1005
- return file ;
997
+ return profan_path_join (profan_wd_path , file );
1006
998
}
1007
999
1008
1000
int main (int argc , char * * argv ) {
0 commit comments