char* GetOriginalPatternName() { char* n = new char[5]; // TODO: overflow zone memset(n, 0, 5); //n[0] = 'p'; //n[1] = 't'; int index = 1; Num2String(index, (char*)&n[0]); Element* el = firstElem; while(el != NULL) { if(el->IsPresent() && el->type == El_Pattern) { if(strcmp(n, ((Pattern*)el)->name->string) == 0) { index++; Num2String(index, (char*)&(n[0])); el = firstElem; continue; } } el = el->next; } return n; }
void GetOriginalInstrumentAlias(const char* name, char* alias) { char n[MAX_ALIAS_STRING]; // TODO: overflow zone memset(n, 0, 5); n[0] = name[0]; ToLowerCase(n); int index = 0; Instrument* i = first_instr; while(i != NULL) { if(i->temp == false && strcmp(n, i->alias->string) == 0) { index++; Num2String(index, (char*)&(n[1])); i = first_instr; } i = i->next; } strcpy(alias, n); }
/* Function: SetExtSerialPacket ================================================ * Abstract: * Sets (sends) the contents of an ExtSerialPacket on the comm line. This * includes the packet's buffer as well as all serial communication overhead * associated with the packet. * * EXT_NO_ERROR is returned on success, EXT_ERROR on failure. */ PUBLIC boolean_T SetExtSerialPacket(ExtSerialPacket *pkt, ExtSerialPort *portDev) { uint32_T i; uint32_T newByteCnt = 0; /* Num bytes after filtering. */ boolean_T error = EXT_NO_ERROR; char Buffer[sizeof(uint32_T)*2]; /* Local buffer for converting escape chars. */ /* If not connected, return immediately. */ if (!portDev->fConnected) return false; /* Initialize some fields of the packet. */ pkt->head[0] = packet_head; pkt->head[1] = packet_head; pkt->tail[0] = packet_tail; pkt->tail[1] = packet_tail; pkt->state = ESP_NoPacket; pkt->cursor = 0; pkt->DataCount = 0; pkt->inQuote = false; /* Send the packet header. */ error = ExtSerialPortSetData(portDev, pkt->head, HEAD_SIZE); if (error != EXT_NO_ERROR) goto EXIT_POINT; /* Send the packet type. */ newByteCnt = Filter(Buffer, &(pkt->PacketType), PACKET_TYPE_SIZE); error = ExtSerialPortSetData(portDev, Buffer, newByteCnt); if (error != EXT_NO_ERROR) goto EXIT_POINT; /* Send the size of the packet buffer. */ newByteCnt = Num2String(Buffer, pkt->size, true, portDev->isLittleEndian); error = ExtSerialPortSetData(portDev, Buffer, newByteCnt); if (error != EXT_NO_ERROR) goto EXIT_POINT; /* Send the variable-sized packet buffer data. */ for (i=0; i<pkt->size; i++) { newByteCnt = Filter(Buffer, &(pkt->Buffer[i]), 1); error = ExtSerialPortSetData(portDev, Buffer, newByteCnt); if (error != EXT_NO_ERROR) goto EXIT_POINT; } /* Send the packet tail. */ error = ExtSerialPortSetData(portDev, pkt->tail, TAIL_SIZE); if (error != EXT_NO_ERROR) goto EXIT_POINT; EXIT_POINT: return error; } /* end SetExtSerialPacket */
vector<string> summaryRanges(vector<int>& nums) { int len = nums.size(); vector<string> ret; if(len == 0) return ret; nums.push_back(INT_MAX); int low = 0; for(int i = 1; i < nums.size(); i++){ if(nums[i] > nums[i-1]+1){ ret.push_back(Num2String(nums[low], nums[i-1])); low = i; } } return ret; }
void GetOriginalInstrumentName(const char* name, char* newname) { char ncheck[MAX_NAME_STRING]; // TODO: overflow zone memset(ncheck, 0, MAX_NAME_STRING); strcpy(ncheck, name); int len = strlen(ncheck); int index = 0; Instrument* i = first_instr; while(i != NULL) { if(i->temp == false && strcmp(ncheck, i->name) == 0) { index++; strcpy(ncheck, name); strcat(ncheck, "_"); Num2String(index, (char*)&(ncheck[len + 1])); i = first_instr; } i = i->next; } strcpy(newname, ncheck); }