/****************************** * C02 File Handling Routines * ******************************/ #include #include #include #include #include #include "common.h" #include "files.h" /* Error - Print textual description of system error * * and exit with system error code */ void extsys(char *s) { perror(s); exterr(errno); } /* Open Source File * * Uses: srcnam - Source File Name * * Sets: srcfil - Source File Handle */ void opnsrc() { DEBUG("Processing Source File Name '%s'\n", srcnam); if (strrchr(srcnam, '.') == NULL) //if no extension strcat(srcnam, ".c02"); // add ".c02" DEBUG("opening Source File '%s'\n", srcnam); srcfil = fopen(srcnam, "r"); //open file if (srcfil == NULL) extsys(srcnam); } /* Close Source File */ void clssrc() { fclose(srcfil); } /* Open Output File * * Uses: outnam - Output File Name * * Sets: outfil - Output File Handle */ void opnout() { DEBUG("Processing Output File Name '%s'\n", outnam); if (strlen(outnam) == 0) //if Output File not specified { strcpy(outnam, srcnam); //copy Source Name to Ouput Name char *dot = strrchr(outnam, '.'); //find extension if (dot != NULL) *dot = 0; //and remove it DEBUG("Set Output File Name to '%s'\n", outnam); } if (strrchr(outnam, '.') == NULL) //if no extension strcat(outnam, ".asm"); // add ".asm" DEBUG("Opening Output File '%s'\n", outnam); outfil = fopen(outnam, "w"); //open file if (outfil == NULL) extsys(outnam); } /* Close Output File */ void clsout() { fprintf(outfil, "\n"); fclose(outfil); } /* Open Log File * * Uses: srcnam - Source File Name * * Sets: logfil - Log File Handle */ void opnlog() { strcpy(lognam, srcnam); //set Log File Name to Source File Name char *dot = strrchr(lognam, '.'); //find file extension if (dot != NULL) *dot = 0; //and remove it strcat(lognam, ".log"); //add extension ".asm" DEBUG("Opening Log File '%s'\n", lognam); logfil = fopen(lognam, "w"); if (logfil == NULL) extsys(lognam); } /* Close Log File * * Uses: logfil - Log File Handle */ void clslog() { fclose(logfil); } /* Open Include file * * Uses: incnam - Include File Name * * Sets: incfil - Include File Handle */ void opninc() { DEBUG("Opening include file '%s'\n", incnam); incfil = fopen(incnam, "r"); if (incfil == NULL) extsys(incnam); } /* Close Include File * * Uses: incfil - Include File Handle */ void clsinc() { fclose(incfil); }