|
|
1.1 ! root 1: /* Copyright Bell Telephone Laboratories Whippany, N.J. ! 2: ! 3: * *********************************** ! 4: * *********************************** ! 5: * ******* SAVE A BITE PROGRAM ******* ! 6: * *** R. B. Drake WH 8C-005 X4163 *** ! 7: * **** Sun Aug 26 11:27:17 1979 ***** ! 8: * *********************************** ! 9: * *********************************** ! 10: ! 11: */ ! 12: /* "@(#) save.c: V 1.1 12/21/80" */ ! 13: ! 14: /* This routine is used to save BASIC programs in standard ASCII format ! 15: on the UNIX file system. Files saved in this way can be edited by ! 16: the standard unix editor if desired. However if that is done no ! 17: syntax checking can be done until the file is "loaded" */ ! 18: #include "bas.h" ! 19: extern char filnam[]; ! 20: ! 21: save() ! 22: { ! 23: FILE *fopen(),*fp; ! 24: char *ptr; ! 25: if(expr[0] == '\0' && filnam[0] == '\0') ! 26: getfnam(); ! 27: if(expr[0] != '\0') ! 28: { ! 29: if(strlen(expr) > 40) ! 30: { ! 31: error(inst.thing.linno,4); ! 32: return(-1); ! 33: } ! 34: strcpy(filnam,expr); ! 35: postb(filnam); ! 36: } ! 37: if(fetch(0,&ptr) < 0) ! 38: { ! 39: error(inst.thing.linno,5); ! 40: return(-1); ! 41: } ! 42: if((fp=fopen(filnam,"w")) == 0) ! 43: { ! 44: error(inst.thing.linno,4); ! 45: return(-1); ! 46: } ! 47: outit(fp); ! 48: while(fetch(-1,&ptr) ==0) ! 49: outit(fp); ! 50: fclose(fp); ! 51: printf("File saved on %s\n",filnam); ! 52: return 0; ! 53: } ! 54: outit(fp) ! 55: FILE *fp; ! 56: { ! 57: extern char linbuf[]; ! 58: char *op; ! 59: int i; ! 60: expand(); ! 61: fprintf(fp,"%d",inst.thing.linno); ! 62: if((inst.thing.opcode.hibyte&0377) > 0200) ! 63: { ! 64: i=(inst.thing.opcode.hibyte&0377) - 0200; ! 65: while(i--) ! 66: fprintf(fp,"\t"); ! 67: } ! 68: else ! 69: fprintf(fp," "); ! 70: op = decode(inst.thing.opcode.lobyte); ! 71: if(op[0]=='\010') ! 72: fprintf(fp,"%s\n",linbuf); ! 73: else ! 74: fprintf(fp,"%s %s\n",op,linbuf); ! 75: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.