//helpers.cpp #include "stdafx.h" #include #include #include #include #include "helpers.h" #include "pattern.h" char *stralloccopy (const char *src) { char *dest; dest = (char *)malloc(strlen(src)*(sizeof(char)+1)); if (dest==0) { fprintf(stderr,"ERROR: malloc failed for %d bytes in stralloccopy(%s)\n",strlen(src)*sizeof(char),src); exit(-1); }; strcpy(dest,src); return(dest); }; char *strrealloccopy (char *old_dest, const char *src) { char *dest; dest = (char *)realloc(old_dest,strlen(src)*(sizeof(char)+1)); if (dest==0) { fprintf(stderr,"ERROR: realloc failed for %d bytes in strrealloccopy(%s)\n",strlen(src)*sizeof(char),src); exit(-1); }; strcpy(dest,src); return(dest); }; char *flagstotext (int flags) { switch(flags) { case NORMAL: return("Normal Stitch"); break; case END: return("End"); break; case JUMP: return("Jump Stitch"); break; case STOP: return("Stop/Color"); break; default: return("Unknown"); break; }; }; int round(double src) { return(int(floor(src+0.5))); }; double lfRECT::width(void) { return(right-left); }; double lfRECT::height(void) { return(bottom-top); }; char *split_cell_str(char *line, int field) { //returns a pointer to a string containging the cell at field number. //copy this for storage because temporary storage will be overwritten by 10th next call. unsigned int i,j; int f; static char buf[10][2048]; // 10 big static temporary buffers static int lastused=0; int quotemode=0; f=1; lastused++; lastused%=10; // choose a different buffer than last time for (i=0;i2047) break; if (buf[lastused][j]=='"') { quotemode=-quotemode+1; // toggle j--; // eat quote from output }; if ((buf[lastused][j]==',' && quotemode==0) || buf[lastused][j]=='\n') break; }; buf[lastused][j]='\0'; return(buf[lastused]); }; double split_cell_double(char *line, int field) { char *buf; double val; buf = split_cell_str(line,field); val = atof(buf); return(val); }; int split_cell_int(char *line, int field) { char *buf; int val; buf = split_cell_str(line,field); val = atoi(buf); return(val); }; //This class encapsulates the file read/write functions using MFC's CFile type or standard C' FILE type. //It does this efficiently by creating a memory buffer /* class membuf_io { unsigned char *buf; int buf_allocated; int pos; */