diff options
author | Paulo Cesar Pereira de Andrade <pcpa@mandriva.com.br> | 2008-03-11 21:49:14 -0300 |
---|---|---|
committer | Paulo Cesar Pereira de Andrade <pcpa@mandriva.com.br> | 2008-07-02 19:05:51 -0300 |
commit | 371c42ab955357d586cf4501762f6e9cf1be53b8 (patch) | |
tree | 43a73ca455e527408a88447c007998317cbbfe40 | |
parent | cb30367f10f2e38065d336d331afdc50900de76d (diff) |
Add support to enter line number in command line.
This works the same way as for vi, i.e. "xedit file +num" will load
file and move cursor to line "num".
-rw-r--r-- | xedit.c | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -128,9 +128,9 @@ main(int argc, char *argv[]) FileAccess file_access; Widget source; XtAppContext appcon; - unsigned int i, num_loaded; + unsigned int i, num_loaded, lineno; - num_loaded = 0; + num_loaded = lineno = 0; #ifdef INCLUDE_XPRINT_SUPPORT XtSetLanguageProc(NULL, NULL, NULL); @@ -196,6 +196,16 @@ main(int argc, char *argv[]) for (i = 1; i < argc; i++) { struct stat st; + if (argv[i][0] == '+') { + char *endptr; + + lineno = strtol(argv[i], &endptr, 10); + /* Don't warn or anything about incorrect input? */ + if (*endptr) + lineno = 0; + continue; + } + filename = ResolveName(argv[i]); if (filename == NULL || FindTextSource(NULL, filename) != NULL) continue; @@ -289,8 +299,18 @@ main(int argc, char *argv[]) XtSetKeyboardFocus(topwindow, filenamewindow); XtVaSetValues(textwindow, XtNwrap, XawtextWrapLine, NULL); } - else + else { XtSetKeyboardFocus(topwindow, textwindow); + if (lineno) { + XawTextPosition position; + + source = XawTextGetSource(textwindow); + position = RSCAN(XawTextGetInsertionPoint(textwindow), + lineno, False); + position = LSCAN(position, 1, False); + XawTextSetInsertionPoint(textwindow, position); + } + } XtAppMainLoop(appcon); return EXIT_SUCCESS; |