📄 file.c
字号:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <dir.h>
#include <string.h>
#include <stdlib.h>
#include <process.h>
#include "utilities.h"
#include "definitions.h"
#include "help.h"
int get_file(char *file, char *config)
{
static char item[3][35]={"Load G-Code File", "Create Or Edit G-Code File", "Load Machine CFG File"}, **array;
char tempmode[20], editcommand[20], ecommand[20];
static BYTE screen[2000];
int curnt=0, curnt2=0, page=0, i, tot, done, msg=NULL, ch;
struct find_t ffblk;
gettext(21,1,60,25,screen);
while(1)
{window(21,1,60,25);
textbackground(LIGHTGRAY);
clrscr();
box(21,4,60,10, LIGHTGRAY,BLACK,WHITE,BLUE);
window(21,1,60,25);
gotoxy(15,1); cprintf("<Esc> To Exit");
gotoxy(4,3); cprintf("File: %s",file);
gotoxy(4,4); cprintf("Cfg: %s",config);
for(i=0;i<3;i++) {gotoxy(4,i+6); cprintf("%s",item[i]);}
while (1)
{gotoxy(4,curnt+6); textbackground(BROWN);
cprintf("%s",item[curnt]); ch=getch();
gotoxy(4,curnt+6); textbackground(LIGHTGRAY);
cprintf("%s",item[curnt]);
if (ch == 13 || ch == 32)
{if(curnt==0) {if(chdir("GCODE")!=0) continue; else sprintf(tempmode,"GCODE");}
if(curnt==1) {if(chdir("GCODE")!=0) continue; else sprintf(tempmode,"EDIT");}
if(curnt==2) {if(chdir("CONFIG")!=0) continue; else sprintf(tempmode,"CONFIG");}
gotoxy(4,curnt+6); textbackground(GREEN);
cprintf("%s",item[curnt]); textbackground(LIGHTGRAY);
break;
}
if (ch == 27) {puttext(21,1,60,25,screen); return msg;}
if (ch > 0) continue;
ch = getch();
switch (ch)
{case 72 : --curnt; break; //up arrow
case 80 : ++curnt; break; //down arrow
case 59 :
if(curnt==0) help(41);
else if(curnt==2) help(42);
else help(50);
break;
}
if (curnt < 0) curnt=2;
if (curnt > 2) curnt=0;
}
//allocate memory for array of files
tot=0;
if(strcmp(tempmode,"GCODE")==0) done=_dos_findfirst("*.TXT",_A_NORMAL,&ffblk);
if(strcmp(tempmode,"EDIT")==0) done=1;
if(strcmp(tempmode,"CONFIG")==0) done=_dos_findfirst("*.CFG",_A_NORMAL,&ffblk);
while (!done) {tot++; done=_dos_findnext(&ffblk);}
array=(char**) malloc(tot*sizeof(char *));
for(i=0;i<tot;i++) array[i]=(char*) malloc(20);
//store file names in array
i=0;
if(strcmp(tempmode,"GCODE")==0) done=_dos_findfirst("*.TXT",_A_NORMAL,&ffblk);
if(strcmp(tempmode,"CONFIG")==0) done=_dos_findfirst("*.CFG",_A_NORMAL,&ffblk);
while (!done) {sprintf(array[i],"%s",ffblk.name); done=_dos_findnext(&ffblk); i++;}
//run the editor if that is what is selected
if(strcmp(tempmode,"EDIT")==0)
{if(strcmp(file,"NONE")==0)
{if(spawnlp(P_WAIT,"edit","edit",NULL)==-1 && spawnlp(P_WAIT,"e","e",NULL)==-1) {chdir(".."); help(50); chdir("GCODE");}
}
else
{if(spawnlp(P_WAIT,"edit","edit",file,NULL)==-1 && spawnlp(P_WAIT,"e","e",file,NULL)==-1) {chdir(".."); help(50); chdir("GCODE");}
}
_setcursortype(_NOCURSOR);
}
//show files in lower box
if(tot!=0) {box(21,10,60,25, LIGHTGRAY,BLACK,WHITE,BLUE); window(21,1,60,25);}
while (tot!=0)
{if(curnt2==23) {page++; box(21,10,60,25, LIGHTGRAY,BLACK,WHITE,BLUE); window(21,1,60,25);}
if(curnt2==0 && page>0) {page--; box(21,10,60,25, LIGHTGRAY,BLACK,WHITE,BLUE); window(21,1,60,25);}
if(page==0)
{for(i=0;i<min(tot,23);i++)
{if(i<12) gotoxy(4,i+12); else gotoxy(22,i); cprintf("%s",array[i]);}
if(tot>(page+1)*22+1) {gotoxy(22,i); cprintf("More Files...");}
}
else
{gotoxy(4,12); cprintf("Previous Files...");
for(i=0;i<min(tot-(page*22+1),22);i++)
{if(i<11)gotoxy(4,i+13); else gotoxy(22,i+1); cprintf("%s",array[i+page*22+1]);}
if(tot>(page+1)*22+1) {gotoxy(22,i+1); cprintf("More Files...");}
}
curnt2=0;
while (1)
{if(curnt2<12) gotoxy(4,curnt2+12); else gotoxy(22, curnt2); textbackground(BROWN);
if(curnt2==23) cprintf("More Files...");
else if(curnt2==0 && page!=0) cprintf("Previous Files...");
else cprintf("%s",array[curnt2+page*22]);
ch=getch();
if(curnt2<12)gotoxy(4,curnt2+12); else gotoxy(22, curnt2); textbackground(LIGHTGRAY);
if(curnt2==23) cprintf("More Files...");
else if(curnt2==0 && page!=0) cprintf("Previous Files...");
else cprintf("%s",array[curnt2+page*22]);
if (ch == 13 || ch == 32)
{if(curnt2==23 || (page!=0 && curnt2==0)) break;
box(22,19,59,24, RED,BLACK,WHITE,WHITE);
gotoxy(4,3); cprintf(" Load File: %s",array[curnt2+page*22]);
gotoxy(4,4); cprintf("<Enter> To Accept <Esc> To Abort");
while(1)
{ch=getch();
if(ch==27 || ch==13 || ch==32) break;}
if(ch==27) break;
if(strcmp(tempmode,"CONFIG")==0) {sprintf(config,"%s",array[curnt2+page*22]); msg=1; break;}
else sprintf(file,"%s",array[curnt2+page*22]); break;
}
if (ch == 27) break;
if (ch > 0) continue;
ch = getch();
switch (ch)
{case 72 : --curnt2; break; //up arrow
case 80 : ++curnt2; break; //down arrow
case 77 : if(curnt2+12<=min(tot-(22*page)-1,23)) curnt2=curnt2+12; break; //right arrow
case 75 : if(curnt2-12>=0) curnt2=curnt2-12; break; //left arrow
case 59 : help(45); break;
}
if (curnt2 < 0) curnt2=min(tot-(22*page)-1,23);
if (curnt2 > min(tot-(22*page)-1,23)) curnt2=0;
}
if(ch==27) break;
if(curnt2==23 || (page!=0 && curnt2==0)) continue;
break;
}
for(i=0;i<tot;i++) free(array[i]); free(array);
curnt2=0; page=0;
chdir("..");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -