aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/oldfiler.cpp
blob: c54a4696be0afcfbfce4c446c18aaa7f0a033ce3 (plain)
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
#include "ptoc.h"


/*#include "Crt.h"*/
#include "graph.h"
/*#include "Dos.h"*/
/*#include "Rodent.h"*/

/*$V-*/

const char more[] = " (more) ";
const string up = string('-')+'\30'+more+'\30';
const string down = string('+')+'\31'+more+'\31';

const graphcursmasktype fletch = /* Mask 4 in Avalot */
    {(
     (255,511,1023,2047,1023,4607,14591,31871,65031,65283,65281,65280,65280,65409,65473,65511),
     (0,10240,20480,24576,26624,17408,512,256,128,88,32,86,72,20,16,0)),
               0,
               0};

string cdir;
matrix<0,2,1,18,varying_string<15> > info;
matrix<0,2,1,100,varying_string<15> > possible;
byte fv;
array<0,2,byte> light,page_;
array<0,2,boolean> blank;
byte chtcode,where;
string answer;

void split(string x)
{
    byte fv;
;
 x=copy(x,4,255); if (x=="")  {; blank[0]=true; return; }
 x=x+'\\'; possible[0][1]="b\\"; fv=2;
 while (pos("\\",x)!=0) 
 {;
  possible[0][fv]=string('b')+copy(x,1,pos("\\",x)-1); fv += 1;
  x=copy(x,pos("\\",x)+1,255);
 }
 possible[0][fv-1]="";
}

void block(integer x1,integer y1,integer x2,integer y2, string x)
{;
 bar(x1,y1,x2,y2);
 setcolor( 9); outtextxy(x1+(x2-x1) / 2-1,y1+5,x);
 setcolor(15); outtextxy(x1+(x2-x1) / 2+1,y1+6,x);
}

void message(string x)
{;
 block(5,189,640,200,x);
}

void bigbar(byte x)
{;
 bar(15+210*x,36,210+210*x,187);
}

void getem();


static void sub_getem(char prefix, string spec, byte attrib,byte infonum)
{
    searchrec s; byte fv;
;
 fv=0;
 findfirst(spec,attrib,s);
 while ((doserror==0) && (fv<100)) 
 {;
  if (((s.attr & attrib)>0) && (s.name[1]!='.')) 
  {;     /* circumvent inclusive searching! */
   fv += 1;
   possible[infonum][fv]=string(prefix)+s.name;
  }
  findnext(s);
 }
 if (fv==0)  blank[infonum]=true;
}

void getem()

{;
 message("Please wait... scanning directory...");
 sub_getem('a',"*.asg",archive+hidden,1); /* Scan for .ASG files */
 sub_getem('f',"*.*",directory,2); /* Scan for sub-directories */
}

void minisc(string& x)          /* Converts to lower-case */
{
    byte fv;
;
 for( fv=1; fv <= length(x); fv ++)
  if ((x[fv]>='A') && (x[fv]<='Z'))  x[fv] += 32;
}

void showall()
{
    byte fv,ff;
;
 for( fv=0; fv <= 2; fv ++)
 {;
  bigbar(fv); /* blank out anything else */
  if (blank[fv]) 
  {;     /* nothing here at all */
/*   setcolor(14);
   outtextxy(113+210*fv,43,'(Nothing here!)'); */
   setcolor(14); settextstyle(0,0,2);
   outtextxy(113+210*fv, 77,"Nothing");
   outtextxy(113+210*fv,100,"here!");
   settextstyle(0,0,1);
  } else
  {;     /* something here- what? */
   setcolor(11);
   for( ff=0; ff <= 15; ff ++)
   {;
    info[fv][ff+2]=possible[fv][page_[fv]*15+ff+1]; minisc(info[fv][ff+2]);
   }
   if (page_[fv]>0)  info[fv][1]=up; else info[fv][1]="";
   if (possible[fv][page_[fv]*15+17]!="") 
    info[fv][18]=down; else info[fv][18]="";
   for( ff=1; ff <= 18; ff ++)
   {;
    outtextxy(113+210*fv,35+ff*8,copy(info[fv][ff],2,255));
   }
  }
 }
 block(5,12,640,22,cdir);
}

void changedir(string x)
{;

 chdir(x); getdir(0,cdir);
}

void drawup()
{
    integer gd;
;
 block( 15, 0,630,10,"Choose an .ASG file to load or save.");
 block( 15,24,210,34,"Looking back:");
 block(225,24,420,34,"Here:");
 block(435,24,630,34,"Looking forwards:");
 for( gd=0; gd <= 2; gd ++) bigbar(gd); /* just to tide us over the wait... */
 showall();
}

void setup()
{;
 settextjustify(1,1); setfillstyle(1,1);
 fillchar(blank,sizeof(blank),'\0'); fillchar( info,sizeof( info),'\0');
 fillchar(possible,sizeof(possible),'\0');
 fillchar( page_,sizeof( page_),'\0');
 split(cdir); getem(); drawup();
}

void setup1()
{
    integer gd,gm;
;
 gd=3; gm=0; initgraph(gd,gm,""); answer="";
 getdir(0,cdir); resetmouse; setgraphicscursor(fletch);
 fillchar(light,sizeof(light),'\0');
 setup();
}

void clickwait()
{
 const array<1,4,varying_string<30> > msg = 
  {{"change to another drive.",
   "return to a lower directory.",
   "use the file named.",
   "enter a sub-directory."}};
    byte oldcht; /* Click Here To... code */
;
 showmousecursor; oldcht=177;
 do {
  if (mousey<38)  chtcode=1; else
   switch (mousex) {
    case 0 ... 210: chtcode=2; break;
    case 211 ... 421: chtcode=3; break;
    default: chtcode=4;
   }
  if (oldcht!=chtcode) 
  {;
   hidemousecursor; message(string("Click here to ")+msg[chtcode]);
   showmousecursor; oldcht=chtcode;
  }
 } while (!leftmousekeypressed);
 hidemousecursor; where=((mousey-39) / 8)+1;
}

void blip()
{;
 sound(32); delay(3); nosound;
}

void do_cht()
{
    char r; byte fv; string x;
;
 if (chtcode==1) 
 {;     /* change drives */
  message("Enter the drive letter (e.g. A)...");
  r=readkey();
  changedir(string(r)+':'); setup();
 } else
 {;
  x=info[chtcode-2][where]; r=x[1]; x=copy(x,2,255);
  switch (r) {
   case 'b': {; /* back some dirs */
         if (x=='\\')  x="";
         for( fv=where-1; fv >= 3; fv --)
          x=copy(info[0][fv],2,255)+'\\'+x;
         changedir(string('\\')+x);
         setup();
        }
        break;
   case 'f': {; /* sub-directory */
         changedir(x);
         setup();
        }
        break;
   case '+': {; /* scroll one panel down */
         page_[chtcode-2] += 1;
         drawup();
        }
        break;
   case '-': {; /* scroll one panel up */
         page_[chtcode-2] -= 1;
         drawup();
        }
        break;
   case 'a': answer=x; break;
  }
 }
}

int main(int argc, const char* argv[])
{pio_initialize(argc, argv);
;
 setup1();
 do {
  clickwait();
  do_cht();
 } while (!(answer!=""));
 if (length(cdir)>3)  cdir=cdir+'\\';
 answer=cdir+answer;
 closegraph();
 output << "Routine completed." << NL;
 output << "Answer: " << answer << NL;
 output << "Hit Enter:"; input >> NL;
return EXIT_SUCCESS;
}