void BadWords::OnFileUpdated(ThreadedFileWatcher *watcher) { RLOG() << watcher_.filename() << " has changed!"; FILE *f = fopen(watcher_.filename().c_str(), "r"); if (f == NULL) { return; } std::map<std::string, std::vector<std::string> > pairs; nodes_.clear(); nodes_.push_back(MatchNode()); bool standalone = false; bool wildcards = true; char sz[256]; while (fgets(sz, sizeof(sz), f) != NULL) { int cch; const char *start = StripWhitespace(sz, &cch); if (cch == 0) { continue; } std::string s(start, cch); if (s[0] == '#') { continue; } if (s.find("@pairs") == 0) { pairs = ParsePairs(s); continue; } if (s.find("@standalone") == 0) { std::vector<std::string> parts = Split(s.c_str(), '/'); if (parts.size() == 2) { if (parts[1].compare("true") == 0) { standalone = true; } if (parts[1].compare("false") == 0) { standalone = false; } } continue; } if (s.find("@wildcards") == 0) { std::vector<std::string> parts = Split(s.c_str(), '/'); if (parts.size() == 2) { if (parts[1].compare("true") == 0) { wildcards = true; } if (parts[1].compare("false") == 0) { wildcards = false; } } continue; } AddPermutations(s, pairs, standalone, wildcards); } fclose(f); }
/* initialize the output processor for this particular instantiation */ OpAlertSyslog2_Data *OpAlertSyslog2_ParseArgs(char *args) { OpAlertSyslog2_Data *data; char **toks; int num_toks; int i; int header_length = -1; char *index; if(pv.verbose) LogMessage("Parsing %s arguments: %s\n", MODULE_NAME, args); if(!(data = (OpAlertSyslog2_Data *)calloc(1, sizeof(OpAlertSyslog2_Data)))) { FatalError("Out of memory creating %s configuration\n", MODULE_NAME); return NULL; } data->facility = -1; data->severity = -1; data->socket = -1; if(args) { toks = mSplit(args, ";", 8, &num_toks, 0); /* XXX error check */ for(i = 0; i < num_toks; i++) { char *token = toks[i]; char **subtoks; int num_subtoks; long value; StripWhitespace(&token); if(*token == '\0') continue; /* split the token on ':' */ subtoks = mSplit(token, ":", 2, &num_subtoks, 0); /* XXX error check */ if(strcasecmp("facility", subtoks[0]) == 0) { if(data->facility >= 0) { FatalError("%s: Multiple %s arguments\n", MODULE_NAME, subtoks[0]); } /* Process facility Argument */ if(num_subtoks != 2) { FatalError("%s: Invalid %s argument: %s\n", MODULE_NAME, subtoks[0], subtoks[1]); } if(String2Long(subtoks[1], &value) == 0) { if(value > MAX_FACILITY) FatalError("%s: Invalid %s argument: %s\n" MODULE_NAME, subtoks[0], subtoks[1]); else data->facility = value; } else { /* search for match in facility map */ int j = 0; while(facility_map[j].keyword) { if(strcasecmp(facility_map[j].keyword, subtoks[1]) == 0) { data->facility = facility_map[j].value; break; } j++; } if(data->facility < 0) { FatalError("%s: Invalid %s argument: %s\n", MODULE_NAME, subtoks[0], subtoks[1]); } } } else if(strcasecmp("severity", subtoks[0]) == 0) { if(data->severity >= 0) { FatalError("%s: Multiple %s arguments\n", MODULE_NAME, subtoks[0]); } /* Process severity Argument */ if(num_subtoks != 2) { FatalError("%s: Invalid %s argument: %s\n", MODULE_NAME, subtoks[0], subtoks[1]); } if(String2Long(subtoks[1], &value) == 0) { if(value > MAX_FACILITY) FatalError("%s: Invalid %s argument: %s\n" MODULE_NAME, subtoks[0], subtoks[1]); else data->severity = value; } else { /* search for match in severity map */ int j = 0; while(severity_map[j].keyword) { if(strcasecmp(severity_map[j].keyword, subtoks[1]) == 0) { data->severity = severity_map[j].value; break; } j++; } if(data->severity < 0) { FatalError("%s: Invalid %s argument: %s\n", MODULE_NAME, subtoks[0], subtoks[1]); } } } else if(strcasecmp("hostname", subtoks[0]) == 0) { if(data->hostname) { FatalError("%s: Multiple %s arguments\n", MODULE_NAME, subtoks[0]); } /* Must be < 255 bytes and must contain only alphanumeric * names and embedded '-'s */ if(IsValidHostname(subtoks[1]) != 1) FatalError("%s: %s argument is not a valid hostname: %s\n", MODULE_NAME, subtoks[0], subtoks[1]); if(!(data->hostname = strdup(subtoks[1]))) FatalError("%s: Out of memory processing config\n"); } else if(strcasecmp("tag", subtoks[0]) == 0) { if(data->tag) { FatalError("%s: Multiple %s arguments\n", MODULE_NAME, subtoks[0]); } if(IsValidSyslogTag(subtoks[1]) != 1) FatalError("%s: %s argument is not a valid syslog tag: " "%s\n", MODULE_NAME, subtoks[0], subtoks[1]); if(!(data->tag = strdup(subtoks[1]))) FatalError("%s: Out of memory processing config\n"); } else if(strcasecmp("syslog_host", subtoks[0]) == 0) { if(data->syslog_host) { FatalError("%s: Multiple %s arguments\n", MODULE_NAME, subtoks[0]); } if(!(data->syslog_host = strdup(subtoks[1]))) FatalError("%s: Out of memory processing config\n"); } else if(strcasecmp("syslog_port", subtoks[0]) == 0) { if(data->syslog_port > 0) { FatalError("%s: Multiple %s arguments\n", MODULE_NAME, subtoks[0]); } if(String2Long(subtoks[1], &value) != 0) FatalError("%s: Invalid %s argument: %s\n", MODULE_NAME, subtoks[0], subtoks[1]); if(value < 1 || value > 65535) FatalError("%s: Invalid %s argument: %s\n", MODULE_NAME, subtoks[0], subtoks[1]); data->syslog_port = value; } else if(strcasecmp("withpid", subtoks[0]) == 0) { if(num_subtoks != 1) { FatalError("%s: %s does not take arguments\n", MODULE_NAME, subtoks[0]); } data->pid_flag = 1; } else { FatalError("%s: Unknown argument: %s\n", MODULE_NAME, subtoks[0]); } FreeToks(subtoks, num_subtoks); } FreeToks(toks, num_toks); } if(data->facility == -1) data->facility = DEFAULT_FACILITY; if(data->severity == -1) data->severity = DEFAULT_SEVERITY; if(!data->tag) { if(!(data->tag = strdup(PROGRAM_NAME))) FatalError("%s: Out of memory processing config\n"); } if(!data->hostname) { char hostname[255]; char *index; if(gethostname(hostname, 255) != 0) FatalError("%s: Unable to get hostname\n"); /* since we may get a FQDN, munge the hostname */ if((index = strchr(hostname, '.'))) *index = '\0'; if(!(data->hostname = strdup(hostname))) FatalError("%s: Out of memory processing config\n"); } if(!data->syslog_host) { if(!(data->syslog_host = strdup(DEFAULT_SYSLOG_HOST))) FatalError("%s: Out of memory processing config\n"); } if(data->syslog_port == 0) data->syslog_port = DEFAULT_SYSLOG_PORT; /* calculate the syslog priority */ data->priority = data->facility * 8 + data->severity; /* allocate the message buffer */ if(!(data->message_buffer = calloc(MESSAGE_LENGTH, sizeof(char)))) FatalError("%s: Out of memory starting output plugin\n"); /* copy in the basic string */ if(data->pid_flag) header_length = snprintf(data->message_buffer, MESSAGE_LENGTH, "<%u>XXX XX XX:XX:XX %s %s[%u]: ", data->priority, data->hostname, data->tag, getpid()); else header_length = snprintf(data->message_buffer, MESSAGE_LENGTH, "<%u>XXX XX XX:XX:XX %s %s: ", data->priority, data->hostname, data->tag); if(header_length > MESSAGE_LENGTH) FatalError("%s: Message header length is too long: %i\n", header_length); data->header_length = header_length; if(!(index = strchr(data->message_buffer, '>'))) FatalError("%s: Error calculating priority field length\n"); data->month_offset = index - data->message_buffer + 1; data->timestamp_offset = data->month_offset + 4; if(pv.verbose) { } return data; }
static bool CreateDictionaryFromXMLRecursive(char *data, int size, CFMutableDictionaryRef *dict, char *key) { if (size == 0) return true; xml_token tok; char *buf = data; int bytesleft = size, closeindex; bool bClosed, bAllocatedKey = false; while (bytesleft) { // skip whitespace if (isspace(buf[0])) { buf++; bytesleft--; continue; } bClosed = false; closeindex = -1; // get XML token if (!GetNextToken(&buf, &bytesleft, &tok, &bClosed)) { if (bAllocatedKey) free(key); return false; } // closed XML token? if (bClosed) { if (key == NULL) continue; if (*dict == NULL) { if (bAllocatedKey) free(key); return false; } CFBooleanRef value = NULL; if (!strcasecmp(tok.id, "true")) { value = kCFBooleanTrue; } else if (!strcasecmp(tok.id, "false")) { value = kCFBooleanFalse; } if (value != NULL) { CFStringRef cfkey = CFStringCreateWithCString(kCFAllocatorDefault, key, kCFStringEncodingUTF8); if (bAllocatedKey) { free(key); key = NULL; bAllocatedKey = false; } if (cfkey == NULL) { return false; } CFDictionaryAddValue(*dict, cfkey, value); } else if (bAllocatedKey) { free(key); key = NULL; bAllocatedKey = false; } continue; } // check for token types we know about if (!strcasecmp(tok.id, "key")) { if (bAllocatedKey) free(key); if (*dict == NULL) return false; closeindex = PIGetIndexOfClosingTag(buf, bytesleft, "key"); if (closeindex == -1) return false; key = (char*)malloc(closeindex+1); strncpy(key, buf, closeindex); key[closeindex] = 0; StripWhitespace(&key); #ifdef DEBUG printf("key = %s\n", key); #endif // empty keys are not allowed if (strlen(key) == 0) { free(key); return false; } bAllocatedKey = true; buf += closeindex + 6; bytesleft -= closeindex + 6; } else if (!strcasecmp(tok.id, "dict")) { if (key == NULL) { if (*dict != NULL) return false; closeindex = PIGetIndexOfClosingTag(buf, bytesleft, "dict"); if (closeindex == -1) { return false; } *dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (*dict == NULL) { return false; } if (!CreateDictionaryFromXMLRecursive(buf, closeindex, dict, NULL)) { CFRelease(*dict); return false; } return true; } else if (*dict != NULL) { closeindex = PIGetIndexOfClosingTag(buf, bytesleft, "dict"); if (closeindex == -1) { if (bAllocatedKey) free(key); return false; } CFMutableDictionaryRef dict2 = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (dict2 == NULL) { if (bAllocatedKey) free(key); return false; } if (!CreateDictionaryFromXMLRecursive(buf, closeindex, &dict2, NULL)) { if (bAllocatedKey) free(key); CFRelease(dict2); return false; } CFStringRef cfkey = CFStringCreateWithCString(kCFAllocatorDefault, key, kCFStringEncodingUTF8); if (bAllocatedKey) { free(key); key = NULL; bAllocatedKey = false; } if (cfkey == NULL) { CFRelease(dict2); return false; } CFDictionaryAddValue(*dict, cfkey, dict2); buf += closeindex + 7; bytesleft -= closeindex + 7; } else { if (bAllocatedKey) free(key); return false; } } else if (!strcasecmp(tok.id, "data")) { if ( (key == NULL) || (*dict == NULL) ) return false; closeindex = PIGetIndexOfClosingTag(buf, bytesleft, "data"); if (closeindex == -1) { if (bAllocatedKey) free(key); return false; } CFStringRef cfkey = CFStringCreateWithCString(kCFAllocatorDefault, key, kCFStringEncodingUTF8); if (bAllocatedKey) { free(key); key = NULL; bAllocatedKey = false; } if (cfkey == NULL) { return false; } char *value = (char*)malloc(closeindex+1); strncpy(value, buf, closeindex); value[closeindex] = 0; StripWhitespace(&value); if (strlen(value) > 0) { // Base64 decode the data int decodelen = Base64decode_len(value); if (decodelen > 0) { char *decodedval = (char*)malloc(decodelen); Base64decode(decodedval, value); free(value); value = decodedval; } } CFDataRef cfvalue = CFDataCreate(kCFAllocatorDefault, (const UInt8*)value, strlen(value)); free(value); if (cfvalue == NULL) { return false; } CFDictionaryAddValue(*dict, cfkey, cfvalue); buf += closeindex + 7; bytesleft -= closeindex + 7; } else if (!strcasecmp(tok.id, "string")) { if ( (key == NULL) || (*dict == NULL) ) return false; closeindex = PIGetIndexOfClosingTag(buf, bytesleft, "string"); if (closeindex == -1) { if (bAllocatedKey) free(key); return false; } CFStringRef cfkey = CFStringCreateWithCString(kCFAllocatorDefault, key, kCFStringEncodingUTF8); if (bAllocatedKey) { free(key); key = NULL; bAllocatedKey = false; } if (cfkey == NULL) { return false; } char *value = (char*)malloc(closeindex+1); strncpy(value, buf, closeindex); value[closeindex] = 0; StripWhitespace(&value); #ifdef DEBUG printf("string = %s\n", value); #endif CFStringRef cfvalue = CFStringCreateWithCString(kCFAllocatorDefault, value, kCFStringEncodingUTF8); free(value); if (cfvalue == NULL) { return false; } CFDictionaryAddValue(*dict, cfkey, cfvalue); buf += closeindex + 9; bytesleft -= closeindex + 9; } else if (!strcasecmp(tok.id, "?xml") || !strcasecmp(tok.id, "!DOCTYPE") || !strcasecmp(tok.id, "plist")) { // Ignore } else { // unknown token -- just skip it if (bAllocatedKey) { free(key); key = NULL; bAllocatedKey = false; } closeindex = PIGetIndexOfClosingTag(buf, bytesleft, tok.id); if (closeindex == -1) { return false; } buf += closeindex + strlen(tok.id) + 3; bytesleft -= closeindex + strlen(tok.id) + 3; } } if (bAllocatedKey) free(key); return true; }
void CModelConverter::ReadMTL(const tstring& sFilename) { FILE* fp = tfopen(sFilename, _T("r")); if (!fp) return; if (m_pWorkListener) m_pWorkListener->SetAction(_T("Reading materials"), 0); size_t iCurrentMaterial = ~0; tstring sLine; while (fgetts(sLine, fp)) { sLine = StripWhitespace(sLine); if (sLine.length() == 0) continue; if (sLine[0] == '#') continue; eastl::vector<tstring> asTokens; tstrtok(sLine, asTokens, _T(" ")); const tchar* pszToken = NULL; pszToken = asTokens[0].c_str(); CConversionMaterial* pMaterial = NULL; if (iCurrentMaterial != ~0) pMaterial = m_pScene->GetMaterial(iCurrentMaterial); if (tstrncmp(pszToken, _T("newmtl"), 6) == 0) { pszToken = asTokens[1].c_str(); CConversionMaterial oMaterial(pszToken, Vector(0.2f,0.2f,0.2f), Vector(0.8f,0.8f,0.8f), Vector(1,1,1), Vector(0,0,0), 1.0, 0); iCurrentMaterial = m_pScene->AddMaterial(oMaterial); } else if (tstrncmp(pszToken, _T("Ka"), 2) == 0) { eastl::vector<tstring> asTokens; tstrtok(sLine, asTokens, _T(" ")); if (asTokens.size() == 4) { pMaterial->m_vecAmbient.x = stof(asTokens[1]); pMaterial->m_vecAmbient.y = stof(asTokens[2]); pMaterial->m_vecAmbient.z = stof(asTokens[3]); } } else if (tstrncmp(pszToken, _T("Kd"), 2) == 0) { eastl::vector<tstring> asTokens; tstrtok(sLine, asTokens, _T(" ")); if (asTokens.size() == 4) { pMaterial->m_vecDiffuse.x = stof(asTokens[1]); pMaterial->m_vecDiffuse.y = stof(asTokens[2]); pMaterial->m_vecDiffuse.z = stof(asTokens[3]); } } else if (tstrncmp(pszToken, _T("Ks"), 2) == 0) { eastl::vector<tstring> asTokens; tstrtok(sLine, asTokens, _T(" ")); if (asTokens.size() == 4) { pMaterial->m_vecSpecular.x = stof(asTokens[1]); pMaterial->m_vecSpecular.y = stof(asTokens[2]); pMaterial->m_vecSpecular.z = stof(asTokens[3]); } } else if (tstrncmp(pszToken, _T("d"), 1) == 0 || tstrncmp(pszToken, _T("Tr"), 2) == 0) { pMaterial->m_flTransparency = (float)stof(asTokens[1]); } else if (tstrncmp(pszToken, _T("Ns"), 2) == 0) { pMaterial->m_flShininess = (float)stof(asTokens[1])*128/1000; } else if (tstrncmp(pszToken, _T("illum"), 5) == 0) { pMaterial->m_eIllumType = (IllumType_t)stoi(asTokens[1]); } else if (tstrncmp(pszToken, _T("map_Kd"), 6) == 0) { pszToken = asTokens[1].c_str(); FILE* fpTest = tfopen(pszToken, _T("r")); if (fpTest) { fclose(fpTest); pMaterial->m_sDiffuseTexture = tstring(pszToken); } else { tstring sDirectory = GetDirectory(sFilename); pMaterial->m_sDiffuseTexture = sprintf(tstring("%s/%s"), sDirectory.c_str(), pszToken); } } } fclose(fp); }
void Target::ImportFile(string filename, string comment_chars) { vector <string> lines = ReadFile(filename, comment_chars, "Cannot Open Target Definition File"); vector <string> results; int max_params = 9; int n_params = 0; for(unsigned int i = 0; i < lines.size(); i++) { // Clear out the results, split the string and strip whitespace results.clear(); // StringSplit(lines[i], string("="), results); results = SplitString(lines[i], '='); StripWhitespace(results); // Now we parse the file by keyword if(results[0] == "name") { this->name = string(results[1]); n_params += 1; } if(results[0] == "res") { try { this->pixellation = atof(results[1].c_str()); n_params += 1; } catch(...) { throw std::runtime_error("Invalid Pixellation Definition in Target File"); } } if(results[0] == "mag") { try { this->mag = atof(results[1].c_str()); n_params += 1; } catch(...) { throw std::runtime_error("Invalid Magnitude Definition in Target File"); } } if(results[0] == "band") { try { this->band = results[1][0]; n_params += 1; } catch(...) { throw std::runtime_error("Invalid Band Definition in Target File"); } } if(results[0] == "temp") { try { this->temperature = atof(results[1].c_str()); n_params += 1; } catch(...) { throw std::runtime_error("Invalid Temperature Definition in Target File"); } } if(results[0] == "bkgrnd") { try { this->background = atof(results[1].c_str()); n_params += 1; } catch(...) { throw std::runtime_error("Invalid Background Definition in Target File"); } } if(results[0] == "bkgrnd_ap") { try { this->background_ap = atof(results[1].c_str()); n_params += 1; } catch(...) { throw std::runtime_error("Invalid Background Definition in Target File"); } } if(results[0] == "src_dec") { try { this->declination = atof(results[1].c_str()) * PI / 180; n_params += 1; } catch(...) { throw std::runtime_error("Invalid source declination Target File"); } } if(results[0] == "src_ra") { try { this->right_ascension = atof(results[1].c_str()) * PI / 180; n_params += 1; } catch(...) { throw std::runtime_error("Invalid source right ascention Target File"); } } } if(n_params != max_params) throw std::runtime_error("The Target file is missing some parameters. Please check the file."); // Now, init the flux. this->InitFlux(); }
// Create and initialize an array from data given in a text file. void Array::ImportFile(string filename, string comment_chars) { // Some local variables int max_params = 8; // This is the number of non-telescope parameters found in the array definition file. int n_params = 0; // the number of parameters read in from the file // Local varaibles for creating Station objects. string staname; int sta_index; double North; double East; double Up; double gain; double diameter; int coord_sys; bool xyz_coords = false; int line_number; // We permit shortcuts in the name of the arrays, this lets us do // $ oifits-sim -a CHARA // instead of // $ oifits-sim -a /home/.../etc/CHARA.txt // which I think is a nice feature. To do this, we first need to see if a file with the // name, filename, really exists. // TODO: Use a global variable, read in from a configuration file, to specify "../etc" below. if(!FileExists(filename)) { filename = "../etc/" + filename + ".txt"; } // stores non-blank, non-comment lines vector < string > lines = ReadFile(filename, comment_chars, "Cannot Open Array Definition File"); vector <string> results; for(line_number = 0; line_number < max_params; line_number++) { // Clear out the results, split the string and strip whitespace results.clear(); results = SplitString(lines[line_number], '='); StripWhitespace(results); if(results[0] == "name") { try { this->arrayname = string(results[1]); n_params += 1; cout << "Loading Array " << this->arrayname << endl; } catch(...) { throw std::runtime_error("Invalid array name"); } } if(results[0] == "lat") { try { this->latitude = atof(results[1].c_str()); // Convert to radians: this->latitude *= PI / 180; n_params += 1; } catch(...) { throw std::runtime_error("Invalid array latitude"); } } if(results[0] == "lon") { try { this->longitude = atof(results[1].c_str()); // Convert to radians: this->longitude *= PI / 180; n_params += 1; } catch(...) { throw std::runtime_error("Invalid array longitude"); } } if(results[0] == "alt") { try { this->altitude = atof(results[1].c_str()); n_params += 1; } catch(...) { throw std::runtime_error("Invalid array altitude"); } } if(results[0] == "coord") { try { coord_sys = atoi(results[1].c_str()); if(coord_sys == 0) { cout << "Array Coordinate system specified in XYZ." << endl; xyz_coords = true; } else cout << "Array Coordinate system specified in (North, East, Up)." << endl; n_params += 1; } catch(...) { throw std::runtime_error("Invalid Coordinate definition specification for telescope positions."); } } if(results[0] == "throughput") { try { this->throughput = atof(results[1].c_str()); n_params += 1; } catch(...) { throw std::runtime_error("Invalid array throughput"); } } if(results[0] == "wind_speed") { try { // Import the wind speed. In the input parameter file it is in m/s // all variables are stored in MKS units, so no conversion is necessary. this->wind_speed = atof(results[1].c_str()); n_params += 1; } catch(...) { throw std::runtime_error("Invalid array average wind speed"); } } if(results[0] == "r0") { try { this->r0 = atof(results[1].c_str()); n_params += 1; } catch(...) { throw std::runtime_error("Invalid average r0 for the array"); } } } // Do some quick error checking on the file format. First, make sure we've got all of the parameters: if(n_params != max_params) throw std::runtime_error("Parameters are missing from the array definition file."); // Now double-check that there are at least two telescopes in this array // This is represented by at least two lines remaining in the file. if(lines.size() - line_number < 2) throw std::runtime_error("At least two telescopes are required for an array! Check configuration file."); // Now iterate through the telescope definitions. There are four entries above // this point in the data file so we start at 4. for (unsigned int i = line_number; i < lines.size(); i++) { // First tokenize the line vector < string > tokens = Tokenize(lines[i]); // And now attempt to read in the line try { staname = tokens[0]; sta_index = atoi(tokens[1].c_str()); North = atof(tokens[2].c_str()); East = atof(tokens[3].c_str()); Up = atof(tokens[4].c_str()); gain = atof(tokens[5].c_str()); diameter = atof(tokens[6].c_str()); } catch(...) { throw std::runtime_error("Error in telecope definitions in array configuration file."); } // Push this station on to the list of stations for this array. this->stations.push_back( Station(this->latitude, staname, sta_index, xyz_coords, North, East, Up, gain, diameter) ); } // Compute a hash table for the stations: this->sta_hash = ComputeStationHash(stations); // Now compute all possible baselines from these stations. this->baselines = ComputeBaselines(stations); this->bl_hash = ComputeBaselineHash(this->baselines); this->triplets = ComputeTriplets(this, stations); this->tri_hash = ComputeTripletHash(this->triplets); this->quadruplets = ComputeQuadruplets(this, stations); this->quad_hash = ComputeQuadrupletHash(this->quadruplets); }
static int ReadTmBbs(char *pchFileName, char *TmBbsName, char *NetmailPath, USERDATAOPT *pUserData, PDRIVEREMAP pDriveRemap, PAREALIST pRetList, PDESCLIST pDescList) { char pchBBSName[LEN_USERNAME+1]; FILE *pfBBS; AREADEFOPT Area; if (NetmailPath[0]) AddNetmailArea(&Area, pchFileName, NetmailPath, pUserData, pRetList); if (TmBbsName[0] && TmBbsName[1] == ':') { /* voller Name */ strcpy(pchBBSName, TmBbsName); MSG_RemapDrive(pchBBSName, pDriveRemap); } else { /* Teil-Name */ CopyPath(pchBBSName, pchFileName); strcat(pchBBSName, "\\"); strcat(pchBBSName, TmBbsName); } pfBBS = fopen(pchBBSName, "r"); if (pfBBS) { char zeile[200]; char *pchTemp; while (!feof(pfBBS)) { if (fgets(zeile, sizeof(zeile), pfBBS)) { StripWhitespace(zeile); if (zeile[0] && zeile[0] != '@') { BOOL bNotValid = FALSE; memset(&Area, 0, sizeof(Area)); Area.areaformat = AREAFORMAT_FTS; /* Default */ Area.areatype = AREATYPE_ECHO; /* Default */ strcpy(Area.username, pUserData->username[0]); strcpy(Area.address, pUserData->address[0]); Area.ulAreaOpt = AREAOPT_FROMCFG; /* Pfad ermitteln */ pchTemp = strtok(zeile, " \t"); if (pchTemp) { if (pchTemp[0] && pchTemp[1] == ':') /* voller Pfad */ strncpy(Area.pathfile, pchTemp, LEN_PATHNAME); else { /* relativer pfad */ CopyPath(Area.pathfile, pchFileName); strcat(Area.pathfile, "\\"); strcat(Area.pathfile, pchTemp); Area.ulTempFlags = AREAFLAG_NOREMAP; } RemoveBackslash(Area.pathfile); if (pchTemp = strtok(NULL, " \t")) { PDESCLIST pDesc = pDescList; strncpy(Area.areatag, pchTemp, LEN_AREATAG); /* Description suchen */ while (pDesc && stricmp(pDesc->pchAreaTag, pchTemp)) pDesc = pDesc->next; if (pDesc) strcpy(Area.areadesc, pDesc->pchDesc); else strncpy(Area.areadesc, pchTemp, LEN_AREADESC); while (pchTemp = strtok(NULL, " \t")) { if (!stricmp(pchTemp, "JAM")) Area.areaformat = AREAFORMAT_JAM; else if (!stricmp(pchTemp, "HOLD")) Area.areatype = AREATYPE_LOCAL; else if (!stricmp(pchTemp, "QWK")) { bNotValid = TRUE; break; } } if (!bNotValid) AM_AddArea(pRetList, &Area, ADDAREA_TAIL | ADDAREA_UNIQUE); } } } } else if (ferror(pfBBS)) { fclose(pfBBS); return CFGFILE_READ; } } fclose(pfBBS); return CFGFILE_OK; } else return CFGFILE_OPEN; }
static int ReadTmCfg(char *pchFileName, char *pchNameBuffer, char *pchOutbound, char *pchNetmail, USERDATAOPT *pUserData, PDESCLIST *ppDescList) { FILE *pfTmCfg; char zeile[200]; pfTmCfg=fopen(pchFileName, "r"); if (pfTmCfg) { while (!feof(pfTmCfg)) { if (fgets(zeile, sizeof(zeile), pfTmCfg)) { /* Whitespace u. Kommentare entfernen */ StripWhitespace(zeile); if (zeile[0]) /* Zeile m. Inhalt */ { char *pchKeyword; char *pchParam, *pchParam2; char *pchDup = strdup(zeile); pchKeyword = strtok(zeile, " \t"); if (pchKeyword) { pchParam = strtok(NULL, " \t"); switch(QueryKeyword(pchKeyword)) { case KEY_NETMAIL: if (!pchNetmail[0] && pchParam) { strcpy(pchNetmail, pchParam); RemoveBackslash(pchOutbound); } break; case KEY_OUTBOUND: if (!pchOutbound[0] && pchParam) { strcpy(pchOutbound, pchParam); RemoveBackslash(pchOutbound); } break; case KEY_AREAFILE: if (!pchNameBuffer[0] && pchParam) strcpy(pchNameBuffer, pchParam); break; case KEY_ORIGIN: if (pchParam) AddOrigin(pUserData, pchDup); break; case KEY_NAME: if (pchParam) AddName(pUserData, pchDup); break; case KEY_ADDRESS: if (pchParam) AddAddress(pUserData, pchParam); break; case KEY_ADESC: if (ppDescList) { pchParam2 = strtok(NULL, " \t"); if (pchParam2) { PDESCLIST pNewDesc; pNewDesc = calloc(1, sizeof(DESCLIST)); if (pNewDesc) { char *pchTemp; /* vorne einhaengen */ pNewDesc->next = *ppDescList; *ppDescList = pNewDesc; /* Daten */ strncpy(pNewDesc->pchAreaTag, pchParam, LEN_AREATAG); strncpy(pNewDesc->pchDesc, pchParam2, LEN_AREADESC); /* _ umwandeln */ pchTemp = pNewDesc->pchDesc; while (*pchTemp) { if (*pchTemp == '_') *pchTemp = ' '; pchTemp++; } } } } break; default: /* unbekannt/unbehandelt */ break; } } free(pchDup); } } else if (ferror(pfTmCfg)) { /* Fehler beim Lesen der Datei */ fclose(pfTmCfg); return CFGFILE_READ; } } fclose(pfTmCfg); return CFGFILE_OK; } else return CFGFILE_OPEN; }