-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathos_amiga.c
1699 lines (1552 loc) · 35.7 KB
/
os_amiga.c
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* os_amiga.c
*
* Amiga system-dependent routines.
*/
#include "vim.h"
#ifdef Window
# undef Window /* Amiga has its own Window definition */
#endif
#undef TRUE /* will be redefined by exec/types.h */
#undef FALSE
/* cproto fails on missing include files, skip them */
#ifndef PROTO
#ifndef LATTICE
# include <exec/types.h>
# include <exec/exec.h>
# include <libraries/dos.h>
# include <intuition/intuition.h>
#endif
/* XXX These are included from os_amiga.h
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
*/
#include <exec/memory.h>
#include <libraries/dosextens.h>
#include <dos/dostags.h> /* for 2.0 functions */
#include <dos/dosasl.h>
/* From version 4 of AmigaOS, several system structures must be allocated
* and freed using system functions. "struct AnchorPath" is one.
*/
#ifdef __amigaos4__
# include <dos/anchorpath.h>
# define free_fib(x) FreeDosObject(DOS_FIB, x)
#else
# define free_fib(x) vim_free(fib)
#endif
#if defined(LATTICE) && !defined(SASC) && defined(FEAT_ARP)
# include <libraries/arp_pragmas.h>
#endif
#endif /* PROTO */
/*
* At this point TRUE and FALSE are defined as 1L and 0L, but we want 1 and 0.
*/
#undef TRUE
#define TRUE (1)
#undef FALSE
#define FALSE (0)
#ifdef __amigaos4__
# define dos_packet(a, b, c) DoPkt(a, b, c, 0, 0, 0, 0)
#elif !defined(AZTEC_C) && !defined(__AROS__)
static long dos_packet __ARGS((struct MsgPort *, long, long));
#endif
static int lock2name __ARGS((BPTR lock, char_u *buf, long len));
static void out_num __ARGS((long n));
static struct FileInfoBlock *get_fib __ARGS((char_u *));
static int sortcmp __ARGS((const void *a, const void *b));
static BPTR raw_in = (BPTR)NULL;
static BPTR raw_out = (BPTR)NULL;
static int close_win = FALSE; /* set if Vim opened the window */
#ifndef __amigaos4__ /* Use autoopen for AmigaOS4 */
struct IntuitionBase *IntuitionBase = NULL;
#endif
#ifdef FEAT_ARP
struct ArpBase *ArpBase = NULL;
#endif
static struct Window *wb_window;
static char_u *oldwindowtitle = NULL;
#ifdef FEAT_ARP
int dos2 = FALSE; /* Amiga DOS 2.0x or higher */
#endif
int size_set = FALSE; /* set to TRUE if window size was set */
void
win_resize_on()
{
OUT_STR_NF("\033[12{");
}
void
win_resize_off()
{
OUT_STR_NF("\033[12}");
}
void
mch_write(p, len)
char_u *p;
int len;
{
Write(raw_out, (char *)p, (long)len);
}
/*
* mch_inchar(): low level input function.
* Get a characters from the keyboard.
* If time == 0 do not wait for characters.
* If time == n wait a short time for characters.
* If time == -1 wait forever for characters.
*
* Return number of characters read.
*/
int
mch_inchar(buf, maxlen, time, tb_change_cnt)
char_u *buf;
int maxlen;
long time; /* milli seconds */
int tb_change_cnt;
{
int len;
long utime;
if (time >= 0)
{
if (time == 0)
utime = 100L; /* time = 0 causes problems in DOS 1.2 */
else
utime = time * 1000L; /* convert from milli to micro secs */
if (WaitForChar(raw_in, utime) == 0) /* no character available */
return 0;
}
else /* time == -1 */
{
/*
* If there is no character available within 2 seconds (default)
* write the autoscript file to disk. Or cause the CursorHold event
* to be triggered.
*/
if (WaitForChar(raw_in, p_ut * 1000L) == 0)
{
#ifdef FEAT_AUTOCMD
if (trigger_cursorhold() && maxlen >= 3)
{
buf[0] = K_SPECIAL;
buf[1] = KS_EXTRA;
buf[2] = (int)KE_CURSORHOLD;
return 3;
}
#endif
before_blocking();
}
}
for (;;) /* repeat until we got a character */
{
# ifdef FEAT_MBYTE
len = Read(raw_in, (char *)buf, (long)maxlen / input_conv.vc_factor);
# else
len = Read(raw_in, (char *)buf, (long)maxlen);
# endif
if (len > 0)
{
#ifdef FEAT_MBYTE
/* Convert from 'termencoding' to 'encoding'. */
if (input_conv.vc_type != CONV_NONE)
len = convert_input(buf, len, maxlen);
#endif
return len;
}
}
}
/*
* return non-zero if a character is available
*/
int
mch_char_avail()
{
return (WaitForChar(raw_in, 100L) != 0);
}
/*
* Return amount of memory still available in Kbyte.
*/
long_u
mch_avail_mem(special)
int special;
{
#ifdef __amigaos4__
return (long_u)AvailMem(MEMF_ANY) >> 10;
#else
return (long_u)(AvailMem(special ? (long)MEMF_CHIP : (long)MEMF_ANY)) >> 10;
#endif
}
/*
* Waits a specified amount of time, or until input arrives if
* ignoreinput is FALSE.
*/
void
mch_delay(msec, ignoreinput)
long msec;
int ignoreinput;
{
#ifndef LATTICE /* SAS declares void Delay(ULONG) */
void Delay __ARGS((long));
#endif
if (msec > 0)
{
if (ignoreinput)
Delay(msec / 20L); /* Delay works with 20 msec intervals */
else
WaitForChar(raw_in, msec * 1000L);
}
}
/*
* We have no job control, fake it by starting a new shell.
*/
void
mch_suspend()
{
suspend_shell();
}
#ifndef DOS_LIBRARY
# define DOS_LIBRARY ((UBYTE *)"dos.library")
#endif
void
mch_init()
{
static char intlibname[] = "intuition.library";
#ifdef AZTEC_C
Enable_Abort = 0; /* disallow vim to be aborted */
#endif
Columns = 80;
Rows = 24;
/*
* Set input and output channels, unless we have opened our own window
*/
if (raw_in == (BPTR)NULL)
{
raw_in = Input();
raw_out = Output();
/*
* If Input() is not interactive, then Output() will be (because of
* check in mch_check_win()). Used for "Vim -".
* Also check the other way around, for "Vim -h | more".
*/
if (!IsInteractive(raw_in))
raw_in = raw_out;
else if (!IsInteractive(raw_out))
raw_out = raw_in;
}
out_flush();
wb_window = NULL;
#ifndef __amigaos4__
if ((IntuitionBase = (struct IntuitionBase *)
OpenLibrary((UBYTE *)intlibname, 0L)) == NULL)
{
mch_errmsg(_("cannot open "));
mch_errmsg(intlibname);
mch_errmsg("!?\n");
mch_exit(3);
}
#endif
}
#ifndef PROTO
# include <workbench/startup.h>
#endif
/*
* Check_win checks whether we have an interactive window.
* If not, a new window is opened with the newcli command.
* If we would open a window ourselves, the :sh and :! commands would not
* work properly (Why? probably because we are then running in a background
* CLI). This also is the best way to assure proper working in a next
* Workbench release.
*
* For the -f option (foreground mode) we open our own window and disable :sh.
* Otherwise the calling program would never know when editing is finished.
*/
#define BUF2SIZE 320 /* length of buffer for argument with complete path */
int
mch_check_win(argc, argv)
int argc;
char **argv;
{
int i;
BPTR nilfh, fh;
char_u buf1[24];
char_u buf2[BUF2SIZE];
static char_u *(constrings[3]) = {(char_u *)"con:0/0/662/210/",
(char_u *)"con:0/0/640/200/",
(char_u *)"con:0/0/320/200/"};
static char_u *winerr = (char_u *)N_("VIM: Can't open window!\n");
struct WBArg *argp;
int ac;
char *av;
char_u *device = NULL;
int exitval = 4;
#ifndef __amigaos4__
struct Library *DosBase;
#endif
int usewin = FALSE;
/*
* check if we are running under DOS 2.0x or higher
*/
#ifndef __amigaos4__
DosBase = OpenLibrary(DOS_LIBRARY, 37L);
if (DosBase != NULL)
/* if (((struct Library *)DOSBase)->lib_Version >= 37) */
{
CloseLibrary(DosBase);
# ifdef FEAT_ARP
dos2 = TRUE;
# endif
}
else /* without arp functions we NEED 2.0 */
{
# ifndef FEAT_ARP
mch_errmsg(_("Need Amigados version 2.04 or later\n"));
exit(3);
# else
/* need arp functions for dos 1.x */
if (!(ArpBase = (struct ArpBase *) OpenLibrary((UBYTE *)ArpName, ArpVersion)))
{
fprintf(stderr, _("Need %s version %ld\n"), ArpName, ArpVersion);
exit(3);
}
# endif
}
#endif /* __amigaos4__ */
/*
* scan argv[] for the "-f" and "-d" arguments
*/
for (i = 1; i < argc; ++i)
if (argv[i][0] == '-')
{
switch (argv[i][1])
{
case 'f':
usewin = TRUE;
break;
case 'd':
if (i < argc - 1
#ifdef FEAT_DIFF
/* require using "-dev", "-d" means diff mode */
&& argv[i][2] == 'e' && argv[i][3] == 'v'
#endif
)
device = (char_u *)argv[i + 1];
break;
}
}
/*
* If we were not started from workbench, do not have a "-d" or "-dev"
* argument and we have been started with an interactive window, use that
* window.
*/
if (argc != 0
&& device == NULL
&& (IsInteractive(Input()) || IsInteractive(Output())))
return OK;
/*
* When given the "-f" argument, we open our own window. We can't use the
* newcli trick below, because the calling program (mail, rn, etc.) would not
* know when we are finished.
*/
if (usewin)
{
/*
* Try to open a window. First try the specified device.
* Then try a 24 line 80 column window.
* If that fails, try two smaller ones.
*/
for (i = -1; i < 3; ++i)
{
if (i >= 0)
device = constrings[i];
if (device != NULL && (raw_in = Open((UBYTE *)device,
(long)MODE_NEWFILE)) != (BPTR)NULL)
break;
}
if (raw_in == (BPTR)NULL) /* all three failed */
{
mch_errmsg(_(winerr));
goto exit;
}
raw_out = raw_in;
close_win = TRUE;
return OK;
}
if ((nilfh = Open((UBYTE *)"NIL:", (long)MODE_NEWFILE)) == (BPTR)NULL)
{
mch_errmsg(_("Cannot open NIL:\n"));
goto exit;
}
/*
* Make a unique name for the temp file (which we will not delete!).
* Use a pointer on the stack (nobody else will be using it).
* Under AmigaOS4, this assumption might change in the future, so
* we use a pointer to the current task instead. This should be a
* shared structure and thus globally unique.
*/
#ifdef __amigaos4__
sprintf((char *)buf1, "t:nc%p", FindTask(0));
#else
sprintf((char *)buf1, "t:nc%ld", (long)buf1);
#endif
if ((fh = Open((UBYTE *)buf1, (long)MODE_NEWFILE)) == (BPTR)NULL)
{
mch_errmsg(_("Cannot create "));
mch_errmsg((char *)buf1);
mch_errmsg("\n");
goto exit;
}
/*
* Write the command into the file, put quotes around the arguments that
* have a space in them.
*/
if (argc == 0) /* run from workbench */
ac = ((struct WBStartup *)argv)->sm_NumArgs;
else
ac = argc;
for (i = 0; i < ac; ++i)
{
if (argc == 0)
{
*buf2 = NUL;
argp = &(((struct WBStartup *)argv)->sm_ArgList[i]);
if (argp->wa_Lock)
(void)lock2name(argp->wa_Lock, buf2, (long)(BUF2SIZE - 1));
#ifdef FEAT_ARP
if (dos2) /* use 2.0 function */
#endif
AddPart((UBYTE *)buf2, (UBYTE *)argp->wa_Name, (long)(BUF2SIZE - 1));
#ifdef FEAT_ARP
else /* use arp function */
TackOn((char *)buf2, argp->wa_Name);
#endif
av = (char *)buf2;
}
else
av = argv[i];
/* skip '-d' or "-dev" option */
if (av[0] == '-' && av[1] == 'd'
#ifdef FEAT_DIFF
&& av[2] == 'e' && av[3] == 'v'
#endif
)
{
++i;
continue;
}
if (vim_strchr((char_u *)av, ' '))
Write(fh, "\"", 1L);
Write(fh, av, (long)strlen(av));
if (vim_strchr((char_u *)av, ' '))
Write(fh, "\"", 1L);
Write(fh, " ", 1L);
}
Write(fh, "\nendcli\n", 8L);
Close(fh);
/*
* Try to open a new cli in a window. If "-d" or "-dev" argument was given try
* to open the specified device. Then try a 24 line 80 column window. If that
* fails, try two smaller ones.
*/
for (i = -1; i < 3; ++i)
{
if (i >= 0)
device = constrings[i];
else if (device == NULL)
continue;
sprintf((char *)buf2, "newcli <nil: >nil: %s from %s", (char *)device, (char *)buf1);
#ifdef FEAT_ARP
if (dos2)
{
#endif
if (!SystemTags((UBYTE *)buf2, SYS_UserShell, TRUE, TAG_DONE))
break;
#ifdef FEAT_ARP
}
else
{
if (Execute((UBYTE *)buf2, nilfh, nilfh))
break;
}
#endif
}
if (i == 3) /* all three failed */
{
DeleteFile((UBYTE *)buf1);
mch_errmsg(_(winerr));
goto exit;
}
exitval = 0; /* The Execute succeeded: exit this program */
exit:
#ifdef FEAT_ARP
if (ArpBase)
CloseLibrary((struct Library *) ArpBase);
#endif
exit(exitval);
/* NOTREACHED */
return FAIL;
}
/*
* Return TRUE if the input comes from a terminal, FALSE otherwise.
* We fake there is a window, because we can always open one!
*/
int
mch_input_isatty()
{
return TRUE;
}
/*
* fname_case(): Set the case of the file name, if it already exists.
* This will cause the file name to remain exactly the same
* if the file system ignores, but preserves case.
*/
/*ARGSUSED*/
void
fname_case(name, len)
char_u *name;
int len; /* buffer size, ignored here */
{
struct FileInfoBlock *fib;
size_t flen;
fib = get_fib(name);
if (fib != NULL)
{
flen = STRLEN(name);
/* TODO: Check if this fix applies to AmigaOS < 4 too.*/
#ifdef __amigaos4__
if (fib->fib_DirEntryType == ST_ROOT)
strcat(fib->fib_FileName, ":");
#endif
if (flen == strlen(fib->fib_FileName)) /* safety check */
mch_memmove(name, fib->fib_FileName, flen);
free_fib(fib);
}
}
/*
* Get the FileInfoBlock for file "fname"
* The returned structure has to be free()d.
* Returns NULL on error.
*/
static struct FileInfoBlock *
get_fib(fname)
char_u *fname;
{
BPTR flock;
struct FileInfoBlock *fib;
if (fname == NULL) /* safety check */
return NULL;
#ifdef __amigaos4__
fib = AllocDosObject(DOS_FIB,0);
#else
fib = (struct FileInfoBlock *)alloc(sizeof(struct FileInfoBlock));
#endif
if (fib != NULL)
{
flock = Lock((UBYTE *)fname, (long)ACCESS_READ);
if (flock == (BPTR)NULL || !Examine(flock, fib))
{
free_fib(fib); /* in case of an error the memory is freed here */
fib = NULL;
}
if (flock)
UnLock(flock);
}
return fib;
}
#ifdef FEAT_TITLE
/*
* set the title of our window
* icon name is not set
*/
void
mch_settitle(title, icon)
char_u *title;
char_u *icon;
{
if (wb_window != NULL && title != NULL)
SetWindowTitles(wb_window, (UBYTE *)title, (UBYTE *)-1L);
}
/*
* Restore the window/icon title.
* which is one of:
* 1 Just restore title
* 2 Just restore icon (which we don't have)
* 3 Restore title and icon (which we don't have)
*/
void
mch_restore_title(which)
int which;
{
if (which & 1)
mch_settitle(oldwindowtitle, NULL);
}
int
mch_can_restore_title()
{
return (wb_window != NULL);
}
int
mch_can_restore_icon()
{
return FALSE;
}
#endif
/*
* Insert user name in s[len].
*/
int
mch_get_user_name(s, len)
char_u *s;
int len;
{
/* TODO: Implement this. */
*s = NUL;
return FAIL;
}
/*
* Insert host name is s[len].
*/
void
mch_get_host_name(s, len)
char_u *s;
int len;
{
#if defined(__amigaos4__) && defined(__CLIB2__)
gethostname(s, len);
#else
vim_strncpy(s, "Amiga", len - 1);
#endif
}
/*
* return process ID
*/
long
mch_get_pid()
{
#ifdef __amigaos4__
/* This is as close to a pid as we can come. We could use CLI numbers also,
* but then we would have two different types of process identifiers.
*/
return((long)FindTask(0));
#else
return (long)0;
#endif
}
/*
* Get name of current directory into buffer 'buf' of length 'len' bytes.
* Return OK for success, FAIL for failure.
*/
int
mch_dirname(buf, len)
char_u *buf;
int len;
{
return mch_FullName((char_u *)"", buf, len, FALSE);
}
/*
* get absolute file name into buffer 'buf' of length 'len' bytes
*
* return FAIL for failure, OK otherwise
*/
int
mch_FullName(fname, buf, len, force)
char_u *fname, *buf;
int len;
int force;
{
BPTR l;
int retval = FAIL;
int i;
/* Lock the file. If it exists, we can get the exact name. */
if ((l = Lock((UBYTE *)fname, (long)ACCESS_READ)) != (BPTR)0)
{
retval = lock2name(l, buf, (long)len - 1);
UnLock(l);
}
else if (force || !mch_isFullName(fname)) /* not a full path yet */
{
/*
* If the file cannot be locked (doesn't exist), try to lock the
* current directory and concatenate the file name.
*/
if ((l = Lock((UBYTE *)"", (long)ACCESS_READ)) != (BPTR)NULL)
{
retval = lock2name(l, buf, (long)len);
UnLock(l);
if (retval == OK)
{
i = STRLEN(buf);
/* Concatenate the fname to the directory. Don't add a slash
* if fname is empty, but do change "" to "/". */
if (i == 0 || *fname != NUL)
{
if (i < len - 1 && (i == 0 || buf[i - 1] != ':'))
buf[i++] = '/';
vim_strncpy(buf + i, fname, len - i - 1);
}
}
}
}
if (*buf == 0 || *buf == ':')
retval = FAIL; /* something failed; use the file name */
return retval;
}
/*
* Return TRUE if "fname" does not depend on the current directory.
*/
int
mch_isFullName(fname)
char_u *fname;
{
return (vim_strchr(fname, ':') != NULL && *fname != ':');
}
/*
* Get the full file name from a lock. Use 2.0 function if possible, because
* the arp function has more restrictions on the path length.
*
* return FAIL for failure, OK otherwise
*/
static int
lock2name(lock, buf, len)
BPTR lock;
char_u *buf;
long len;
{
#ifdef FEAT_ARP
if (dos2) /* use 2.0 function */
#endif
return ((int)NameFromLock(lock, (UBYTE *)buf, len) ? OK : FAIL);
#ifdef FEAT_ARP
else /* use arp function */
return ((int)PathName(lock, (char *)buf, (long)(len/32)) ? OK : FAIL);
#endif
}
/*
* get file permissions for 'name'
* Returns -1 when it doesn't exist.
*/
long
mch_getperm(name)
char_u *name;
{
struct FileInfoBlock *fib;
long retval = -1;
fib = get_fib(name);
if (fib != NULL)
{
retval = fib->fib_Protection;
free_fib(fib);
}
return retval;
}
/*
* set file permission for 'name' to 'perm'
*
* return FAIL for failure, OK otherwise
*/
int
mch_setperm(name, perm)
char_u *name;
long perm;
{
perm &= ~FIBF_ARCHIVE; /* reset archived bit */
return (SetProtection((UBYTE *)name, (long)perm) ? OK : FAIL);
}
/*
* Set hidden flag for "name".
*/
void
mch_hide(name)
char_u *name;
{
/* can't hide a file */
}
/*
* return FALSE if "name" is not a directory
* return TRUE if "name" is a directory.
* return FALSE for error.
*/
int
mch_isdir(name)
char_u *name;
{
struct FileInfoBlock *fib;
int retval = FALSE;
fib = get_fib(name);
if (fib != NULL)
{
#ifdef __amigaos4__
retval = (FIB_IS_DRAWER(fib)) ? TRUE : FALSE;
#else
retval = ((fib->fib_DirEntryType >= 0) ? TRUE : FALSE);
#endif
free_fib(fib);
}
return retval;
}
/*
* Create directory "name".
*/
int
mch_mkdir(name)
char_u *name;
{
BPTR lock;
lock = CreateDir(name);
if (lock != NULL)
{
UnLock(lock);
return 0;
}
return -1;
}
/*
* Return 1 if "name" can be executed, 0 if not.
* Return -1 if unknown.
*/
int
mch_can_exe(name, path)
char_u *name;
char_u **path;
{
/* TODO */
return -1;
}
/*
* Check what "name" is:
* NODE_NORMAL: file or directory (or doesn't exist)
* NODE_WRITABLE: writable device, socket, fifo, etc.
* NODE_OTHER: non-writable things
*/
int
mch_nodetype(name)
char_u *name;
{
/* TODO */
return NODE_NORMAL;
}
void
mch_early_init()
{
}
/*
* Careful: mch_exit() may be called before mch_init()!
*/
void
mch_exit(r)
int r;
{
if (raw_in) /* put terminal in 'normal' mode */
{
settmode(TMODE_COOK);
stoptermcap();
}
out_char('\n');
if (raw_out)
{
if (term_console)
{
win_resize_off(); /* window resize events de-activated */
if (size_set)
OUT_STR("\233t\233u"); /* reset window size (CSI t CSI u) */
}
out_flush();
}
#ifdef FEAT_TITLE
mch_restore_title(3); /* restore window title */
#endif
ml_close_all(TRUE); /* remove all memfiles */
#ifdef FEAT_ARP
if (ArpBase)
CloseLibrary((struct Library *) ArpBase);
#endif
if (close_win)
Close(raw_in);
if (r)
printf(_("Vim exiting with %d\n"), r); /* somehow this makes :cq work!? */
exit(r);
}
/*
* This is a routine for setting a given stream to raw or cooked mode on the
* Amiga . This is useful when you are using Lattice C to produce programs
* that want to read single characters with the "getch()" or "fgetc" call.
*
* Written : 18-Jun-87 By Chuck McManis.
*/
#define MP(xx) ((struct MsgPort *)((struct FileHandle *) (BADDR(xx)))->fh_Type)
/*
* Function mch_settmode() - Convert the specified file pointer to 'raw' or
* 'cooked' mode. This only works on TTY's.
*
* Raw: keeps DOS from translating keys for you, also (BIG WIN) it means
* getch() will return immediately rather than wait for a return. You
* lose editing features though.
*
* Cooked: This function returns the designate file pointer to it's normal,
* wait for a <CR> mode. This is exactly like raw() except that
* it sends a 0 to the console to make it back into a CON: from a RAW:
*/
void
mch_settmode(tmode)
int tmode;
{
#if defined(__AROS__) || defined(__amigaos4__)
if (!SetMode(raw_in, tmode == TMODE_RAW ? 1 : 0))
#else
if (dos_packet(MP(raw_in), (long)ACTION_SCREEN_MODE,
tmode == TMODE_RAW ? -1L : 0L) == 0)
#endif
mch_errmsg(_("cannot change console mode ?!\n"));
}
/*
* set screen mode, always fails.
*/
int
mch_screenmode(arg)
char_u *arg;
{
EMSG(_(e_screenmode));
return FAIL;
}