/****************** ReadStruct() Allocate a new DVDInfo struct. Prompt the user to supply a title, comment, and rating. Fill in the values of the new DVDInfo struct, and return the new struct to the caller. */ struct DVDInfo *ReadStruct( void ) { struct DVDInfo *infoPtr; infoPtr = malloc( sizeof( struct DVDInfo ) ); if ( infoPtr == NULL ) { printf( "Out of memory!!! Goodbye!\n" ); exit( 1 ); } // Buffer to hold each answer char buffer[ 500+1 ]; printf( "Enter DVD Title: " ); fgets( buffer, sizeof(buffer), stdin ); strlcpy( infoPtr->title, TrimLine( buffer ), sizeof(infoPtr->title) ); printf( "Enter DVD Comment: " ); fgets( buffer, sizeof(buffer), stdin ); strlcpy( infoPtr->comment, TrimLine( buffer ), sizeof(infoPtr->comment) ); int num; do { printf( "Enter DVD Rating (1-10): " ); fgets( buffer, sizeof(buffer), stdin ); num = atoi( TrimLine( buffer ) ); } while ( ( num < 1 ) || ( num > 10 ) ); infoPtr->rating = num; return( infoPtr ); }
int EBuffer::BlockTrim() { EPoint B, E; int L; AutoExtend = 0; if (CheckBlock() == 0) return 0; if (RCount <= 0) return 0; B = BB; E = BE; Draw(B.Row, E.Row); for (L = B.Row; L <= E.Row; L++) { switch (BlockMode) { case bmStream: if (L < E.Row || E.Col != 0) if (TrimLine(L) == 0) return 0; break; case bmLine: case bmColumn: if (L < E.Row) if (TrimLine(L) == 0) return 0; break; } } return 1; }
bool FindJVMInSettings() { TCHAR buffer[_MAX_PATH]; TCHAR copy[_MAX_PATH]; GetModuleFileName(NULL, buffer, _MAX_PATH); std::wstring module(buffer); if (LoadString(hInst, IDS_VM_OPTIONS_PATH, buffer, _MAX_PATH)) { ExpandEnvironmentStrings(buffer, copy, _MAX_PATH - 1); std::wstring path(copy); path += L"\\config" + module.substr(module.find_last_of('\\')) + L".jdk"; FILE *f = _tfopen(path.c_str(), _T("rt")); if (!f) return false; char line[_MAX_PATH]; if (!fgets(line, _MAX_PATH, f)) { fclose(f); return false; } TrimLine(line); fclose(f); return FindValidJVM(line); } return false; }
/***************** GetCommand() Get a single command character from stdin and return it as char to the caller. */ char GetCommand( void ) { char buffer[ 100+1 ]; printf( "Enter command (q=quit, n=new, l=list, r=reverse list): " ); fgets( buffer, sizeof(buffer), stdin ); return *TrimLine( buffer ); }
bool CINIFileAdapter::AddAttribute(TSection *section, std::string &attribute) { size_t delimiterPosition = attribute.find('='); if(delimiterPosition == std::string::npos) return false; std::string name = attribute.substr(0, delimiterPosition); std::string value = attribute.substr(delimiterPosition + 1); TrimLine(name); TrimLine(value); section->insert(std::make_pair(name, value)); return true; }
int EBuffer::LineNew() { if (SplitLine(VToR(CP.Row), CP.Col) == 0) return 0; if (!MoveDown()) return 0; if (CP.Col > 0) { if (!MoveLineStart()) return 0; //int Indent = LineIndented(VToR(CP.Row)); if (!LineIndent()) return 0; //if (Indent > 0) // if (InsText(Row, C, Indent, 0) == 0) // return 0; if (BFI(this, BFI_Trim)) if (TrimLine(VToR(CP.Row - 1)) == 0) return 0; } return 1; }
string Join(const vector<string> &vs) { string out; for (auto &s : vs) { out += s + " "; } TrimLine(out); return out; }
int EBuffer::InsertString(const char *aStr, int aCount) { int P; int C, L; int Y = VToR(CP.Row); if (BFI(this, BFI_InsertKillBlock) == 1) if (CheckBlock() == 1) if (BlockKill() == 0) return 0; if (BFI(this, BFI_Insert) == 0) if (CP.Col < LineLen()) if (KillChar() == 0) return 0; if (InsText(Y, CP.Col, aCount, aStr) == 0) return 0; C = CP.Col; L = VToR(CP.Row); P = CharOffset(RLine(L), C); P += aCount; C = ScreenPos(RLine(L), P); if (SetPos(C, CP.Row) == 0) return 0; if (BFI(this, BFI_Trim) && *aStr != '\t') if (TrimLine(L) == 0) return 0; if (BFI(this, BFI_WordWrap) == 2) { if (DoWrap(0) == 0) return 0; } else if (BFI(this, BFI_WordWrap) == 1) { int P, C = CP.Col; PELine LP; int L; if (C > BFI(this, BFI_RightMargin)) { L = CP.Row; C = BFI(this, BFI_RightMargin); P = CharOffset(LP = RLine(L), C); while ((C > BFI(this, BFI_LeftMargin)) && ((LP->Chars[P] != ' ') && (LP->Chars[P] != 9))) C = ScreenPos(LP, --P); if (P <= BFI(this, BFI_LeftMargin)) { C = BFI(this, BFI_RightMargin); } else C = ScreenPos(LP, P); if (SplitLine(L, C) == 0) return 0; IndentLine(L + 1, BFI(this, BFI_LeftMargin)); if (SetPos(CP.Col - C - 1 + BFI(this, BFI_LeftMargin), CP.Row + 1) == 0) return 0; } } return 1; }
/********************************** GetNewDinoName( char *dinoName ) dinoName: char array to recieve name returns true if name is not empty dinoName must be at least kDinoRecordSize+1 bytes long Prompt user to type in a name. Read line, trim it, and copy no more then kDinoRecordSize characters to dinoName. */ bool GetNewDinoName( char *dinoName ) { char line[ kMaxLineLength ]; printf( "Enter new name (optional): " ); fgets( line, kMaxLineLength, stdin ); strlcpy( dinoName, TrimLine(line), kDinoRecordSize+1 ); return ( dinoName[0] != '\0' ); }
/************************** GetNumber() returns a number between 0 and the number of dinosaur records in the file, or -1 if the user typed 'a' Calls GetNumberOfDino() to obtain the # of records in the file. Prompts the user to enter a number between 1 an #. Reads a line and converts that to an integer. Loops until number is between 0 and #, inclusive, or the line starts with the letter 'a'. */ int GetNumber( void ) { int number, numDinos; numDinos = GetNumberOfDinos(); do { printf( "Enter number from 1 to %d (0 to exit, a to add): ", numDinos ); // Read a line from the keyboard and convert it to a number char lineBuffer[ kMaxLineLength ]; fgets( lineBuffer, sizeof(lineBuffer), stdin ); number = atoi( TrimLine(lineBuffer) ); // If the line doesn't contain an integer, see if it starts // with the letter 'a'. If so, return -1 to the caller. if ( number==0 && *TrimLine(lineBuffer)=='a' ) return -1; } while ( (number < 0) || (number > numDinos) ); return number; }
void CINIFileAdapter::Parse() { char *buf; std::ios::streamoff size; mFile->ReadFile(&buf, size); std::string line; std::istringstream ss(std::string(buf, (size_t)size)); std::string sectionName; TSection* currentSection = 0; delete[] buf; while(true) { // Save current section before leaving if(ss.eof()) { if(currentSection) mFileMap.insert(std::make_pair(sectionName, currentSection)); break; } // Read line std::getline(ss, line); TrimLine(line); // if empty or comment if(line.length() == 0 || line[0] == ';' || line[0] == '#') continue; // is section if(line[0] == '[' && line[line.length() - 1] == ']') { if(currentSection) mFileMap.insert(std::make_pair(sectionName, currentSection)); currentSection = new TSection(); sectionName = line.substr(1, line.length() - 2); } // found the attribute else if(!currentSection || !AddAttribute(currentSection, line)) throw FSParsingException("bad INI format"); } }
void Vocab::load_vocab(const string &vocab_file) { ifstream fin(vocab_file.c_str()); if (!fin.is_open()) { cerr<<"cannot open vocab file!\n"; return; } string line; while(getline(fin,line)) { TrimLine(line); string sep(" ||| "); vector<string> vs = Split(line,sep); word_list.push_back(vs[0]); word2id.insert(make_pair(vs[0],stoi(vs[1]))); } }
int EBuffer::Delete() { int Y = VToR(CP.Row); if (CheckBlock() == 1 && BFI(this, BFI_DeleteKillBlock)) { if (BlockKill() == 0) return 0; } else if (CP.Col < LineLen()) { if (BFI(this, BFI_DeleteKillTab)) { int P; int C = CP.Col, C1; P = CharOffset(RLine(Y), C); C1 = ScreenPos(RLine(Y), P + 1); if (DelText(Y, C, C1 - C) == 0) return 0; } else { ELine *L = RLine(Y); int C = CharOffset(L, CP.Col); if (L->Count > 0 && L->Chars[C] == '\t') { /* We're on top of tab character. Skip over all spaces and tabs so that only the last space/tab gets deleted. */ while (C < L->Count && (L->Chars[C+1] == '\t' || L->Chars[C+1] == ' ')) C++; } if (DelText(Y, ScreenPos(L, C), 1) == 0) return 0; } } else if (LineJoin() == 0) return 0; if (BFI(this, BFI_WordWrap) == 2) { if (DoWrap(0) == 0) return 0; if (CP.Col >= LineLen(Y)) if (CP.Row < VCount - 1) { if (SetPos(BFI(this, BFI_LeftMargin), CP.Row + 1) == 0) return 0; } } if (BFI(this, BFI_Trim)) if (TrimLine(VToR(CP.Row)) == 0) return 0; return 1; }
bool LoadVMOptionsFile(const TCHAR* path, std::vector<std::string>& vmOptionLines) { FILE *f = _tfopen(path, _T("rt")); if (!f) return false; char line[_MAX_PATH]; while (fgets(line, _MAX_PATH, f)) { TrimLine(line); if (line[0] == '#') continue; if (strcmp(line, "-server") == 0) { bServerJVM = true; } else if (strlen(line) > 0) { vmOptionLines.push_back(line); } } fclose(f); return true; }
int EBuffer::LineIndent() { int rc = 1; if (BFI(this, BFI_AutoIndent)) { int L = VToR(CP.Row); switch (BFI(this, BFI_IndentMode)) { case INDENT_C: rc = Indent_C(this, L, 1); break; case INDENT_REXX: rc = Indent_REXX(this, L, 1); break; case INDENT_SIMPLE: rc = Indent_SIMPLE(this, L, 1); break; case INDENT_CONTINUE: rc = Indent_Continue(this, L, 1); break; default: rc = Indent_Plain(this, L, 1); break; } } if (rc == 0) return 0; if (BFI(this, BFI_Trim)) if (TrimLine(VToR(CP.Row)) == 0) return 0; return 1; }
static int afsconf_OpenInternal(struct afsconf_dir *adir, char *cell, char clones[]) { afsconf_FILE *tf; char *tp, *bp; struct afsconf_entry *curEntry; struct afsconf_aliasentry *curAlias; afs_int32 code; afs_int32 i; char tbuffer[256], tbuf1[256]; struct stat tstat; #ifdef AFS_NT40_ENV cm_enumCellRegistry_t enumCellRegistry = {0, 0}; #endif /* AFS_NT40_ENV */ /* figure out the local cell name */ #ifdef AFS_NT40_ENV i = GetCellNT(adir); enumCellRegistry.adir = adir; #else i = GetCellUnix(adir); #endif #ifndef AFS_FREELANCE_CLIENT /* no local cell not fatal in freelance */ if (i) { return i; } #endif /* now parse the individual lines */ curEntry = 0; #ifdef AFS_NT40_ENV /* NT client/server have a CellServDB that is the same format as Unix. * However, the NT client uses a different file name */ if (IsClientConfigDirectory(adir->name)) { /* NT client config dir */ char *p; enumCellRegistry.client = 1; if (!afssw_GetClientCellServDBDir(&p)) { strcompose(tbuffer, sizeof(tbuffer), p, "/", AFSDIR_CELLSERVDB_FILE_NTCLIENT, NULL); free(p); } else { int len; strncpy(tbuffer, adir->name, sizeof(tbuffer)); len = (int)strlen(tbuffer); if (tbuffer[len - 1] != '\\' && tbuffer[len - 1] != '/') { strncat(tbuffer, "\\", sizeof(tbuffer)); } strncat(tbuffer, AFSDIR_CELLSERVDB_FILE_NTCLIENT, sizeof(tbuffer)); tbuffer[sizeof(tbuffer) - 1] = '\0'; } } else { /* NT server config dir */ strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL); } #else strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL); #endif /* AFS_NT40_ENV */ if (!stat(tbuffer, &tstat)) { adir->timeRead = tstat.st_mtime; } else { adir->timeRead = 0; } strlcpy(tbuf1, tbuffer, sizeof tbuf1); tf = fopen(tbuffer, "r"); if (!tf) { return -1; } /* The CellServDB file is now open. * The following code parses the contents of the * file and creates a list with the first cell entry * in the CellServDB file at the end of the list. * * No checking is performed for duplicates. * The side effects of this process are that duplicate * entries appended to the end of the CellServDB file * take precedence and are found in a shorter period * of time. */ while (1) { tp = fgets(tbuffer, sizeof(tbuffer), tf); if (!tp) break; TrimLine(tbuffer, sizeof tbuffer); /* remove white space */ if (tbuffer[0] == 0 || tbuffer[0] == '\n') continue; /* empty line */ if (tbuffer[0] == '>') { char linkedcell[MAXCELLCHARS]; /* start new cell item */ if (curEntry) { /* thread this guy on the list */ curEntry->next = adir->entries; adir->entries = curEntry; curEntry = 0; } curEntry = (struct afsconf_entry *)malloc(sizeof(struct afsconf_entry)); memset(curEntry, 0, sizeof(struct afsconf_entry)); code = ParseCellLine(tbuffer, curEntry->cellInfo.name, linkedcell); if (code) { afsconf_CloseInternal(adir); fclose(tf); free(curEntry); return -1; } if (linkedcell[0] != '\0') curEntry->cellInfo.linkedCell = strdup(linkedcell); } else { /* new host in the current cell */ if (!curEntry) { afsconf_CloseInternal(adir); fclose(tf); return -1; } i = curEntry->cellInfo.numServers; if (i < MAXHOSTSPERCELL) { if (cell && !strcmp(cell, curEntry->cellInfo.name)) code = ParseHostLine(tbuffer, &curEntry->cellInfo.hostAddr[i], curEntry->cellInfo.hostName[i], &clones[i]); else code = ParseHostLine(tbuffer, &curEntry->cellInfo.hostAddr[i], curEntry->cellInfo.hostName[i], 0); if (code) { if (code == AFSCONF_SYNTAX) { for (bp = tbuffer; *bp != '\n'; bp++) { /* Take out the <cr> from the buffer */ if (!*bp) break; } *bp = '\0'; fprintf(stderr, "Can't properly parse host line \"%s\" in configuration file %s\n", tbuffer, tbuf1); } free(curEntry); fclose(tf); afsconf_CloseInternal(adir); return -1; } curEntry->cellInfo.numServers = ++i; } else { fprintf(stderr, "Too many hosts for cell %s in configuration file %s\n", curEntry->cellInfo.name, tbuf1); } } } fclose(tf); /* close the file now */ /* end the last partially-completed cell */ if (curEntry) { curEntry->next = adir->entries; adir->entries = curEntry; } #ifdef AFS_NT40_ENV /* * Windows maintains a CellServDB list in the Registry * that supercedes the contents of the CellServDB file. * Prepending these entries to the head of the list * is sufficient to enforce the precedence. */ cm_EnumerateCellRegistry( enumCellRegistry.client, cm_enumCellRegistryProc, &enumCellRegistry); #endif /* AFS_NT40_ENV */ /* Read in the alias list */ strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLALIAS_FILE, NULL); tf = fopen(tbuffer, "r"); while (tf) { char *aliasPtr; tp = fgets(tbuffer, sizeof(tbuffer), tf); if (!tp) break; TrimLine(tbuffer, sizeof tbuffer); /* remove white space */ if (tbuffer[0] == '\0' || tbuffer[0] == '\n' || tbuffer[0] == '#') continue; /* empty line */ tp = tbuffer; while (tp[0] != '\0' && tp[0] != ' ' && tp[0] != '\t') tp++; if (tp[0] == '\0') continue; /* invalid line */ while (tp[0] != '\0' && (tp[0] == ' ' || tp[0] == '\t')) 0[tp++] = '\0'; if (tp[0] == '\0') continue; /* invalid line */ aliasPtr = tp; while (tp[0] != '\0' && tp[0] != ' ' && tp[0] != '\t' && tp[0] != '\r' && tp[0] != '\n') tp++; tp[0] = '\0'; curAlias = malloc(sizeof(*curAlias)); memset(curAlias, 0, sizeof(*curAlias)); strlcpy(curAlias->aliasInfo.aliasName, aliasPtr, sizeof curAlias->aliasInfo.aliasName); strlcpy(curAlias->aliasInfo.realName, tbuffer, sizeof curAlias->aliasInfo.realName); curAlias->next = adir->alias_entries; adir->alias_entries = curAlias; } if (tf != NULL) fclose(tf); /* now read the fs keys, if possible */ adir->keystr = (struct afsconf_keys *)0; afsconf_IntGetKeys(adir); return 0; }
void ruletable2bin(string rule_filename) { unordered_map <string,int> ch_vocab; unordered_map <string,int> en_vocab; vector<string> ch_vocab_vec; vector<string> en_vocab_vec; int ch_word_id = 0; int en_word_id = 0; gzFile gzfp = gzopen(rule_filename.c_str(),"r"); if (!gzfp) { cout<<"fail to open "<<rule_filename<<endl; return; } ofstream fout; fout.open("prob.bin",ios::binary); if (!fout.is_open()) { cout<<"fail open model file to write!\n"; return; } char buf[LEN]; while( gzgets(gzfp,buf,LEN) != Z_NULL) { string line(buf); vector <string> elements; string sep = "|||"; Split(elements,line,sep); for (auto &e : elements) { TrimLine(e); } vector <string> ch_word_vec; Split(ch_word_vec,elements[0]); ch_word_vec.pop_back(); vector <int> ch_id_vec; for (const auto &ch_word : ch_word_vec) { auto it = ch_vocab.find(ch_word); if (it != ch_vocab.end()) { ch_id_vec.push_back(it->second); } else { ch_id_vec.push_back(ch_word_id); ch_vocab.insert(make_pair(ch_word,ch_word_id)); ch_vocab_vec.push_back(ch_word); ch_word_id++; } } vector<int> nonterminal_idx_en; int idx_en = -1; short int rule_type = 0; //规则类型,0和1表示规则包含0个或1个非终结符,2表示规则包含2个正序非终结符,3表示规则包含2个逆序非终结符 vector <string> en_word_vec; Split(en_word_vec,elements[1]); en_word_vec.pop_back(); vector <int> en_id_vec; for (const auto &en_word : en_word_vec) { idx_en += 1; if (en_word == "[X][X]") { nonterminal_idx_en.push_back(idx_en); } auto it = en_vocab.find(en_word); if (it != en_vocab.end()) { en_id_vec.push_back(it->second); } else { en_id_vec.push_back(en_word_id); en_vocab.insert(make_pair(en_word,en_word_id)); en_vocab_vec.push_back(en_word); en_word_id++; } } if (nonterminal_idx_en.size() == 1) { rule_type = 1; } vector <string> prob_str_vec; vector <double> prob_vec; Split(prob_str_vec,elements[2]); for (const auto &prob_str : prob_str_vec) { prob_vec.push_back(stod(prob_str)); } if (nonterminal_idx_en.size() == 2) { vector <string> alignments; sep = "-"; Split(alignments,elements[3]); for (auto &align_str : alignments) { vector <string> pos_pair; Split(pos_pair,align_str,sep); int idx_en = stoi(pos_pair[1]); if (idx_en == nonterminal_idx_en[0]) { rule_type = 2; break; } else if (idx_en == nonterminal_idx_en[1]) { rule_type = 3; break; } } } short int ch_rule_len = ch_id_vec.size(); short int en_rule_len = en_id_vec.size(); fout.write((char*)&ch_rule_len,sizeof(short int)); fout.write((char*)&ch_id_vec[0],sizeof(int)*ch_rule_len); fout.write((char*)&en_rule_len,sizeof(short int)); fout.write((char*)&en_id_vec[0],sizeof(int)*en_rule_len); fout.write((char*)&prob_vec[0],sizeof(double)*prob_vec.size()); fout.write((char*)&rule_type,sizeof(short int)); /* cout<<ch_rule_len<<' '; for (auto e: ch_id_vec) cout<<e<<' '; cout<<"||| "<<en_rule_len<<' '; for (auto e: en_id_vec) cout<<e<<' '; cout<<"||| "; for (auto e: prob_vec) cout<<e<<' '; cout<<"||| "<<rule_type<<endl; */ } short int ch_rule_len = 2; //写入glue规则 vector<int> ch_id_vec = {ch_vocab["[X][X]"],ch_vocab["[X][X]"]}; short int en_rule_len = 2; vector<int> en_id_vec = {en_vocab["[X][X]"],en_vocab["[X][X]"]}; vector<double> prob_vec = {2.718,2.718,2.718,2.718}; short int rule_type = 2; fout.write((char*)&ch_rule_len,sizeof(short int)); fout.write((char*)&ch_id_vec[0],sizeof(int)*ch_rule_len); fout.write((char*)&en_rule_len,sizeof(short int)); fout.write((char*)&en_id_vec[0],sizeof(int)*en_rule_len); fout.write((char*)&prob_vec[0],sizeof(double)*prob_vec.size()); fout.write((char*)&rule_type,sizeof(short int)); gzclose(gzfp); fout.close(); ofstream f_ch_vocab("vocab.ch"); if (!f_ch_vocab.is_open()) { cout<<"fail open ch vocab file to write!\n"; return; } for(size_t i=0;i<ch_vocab_vec.size();i++) { f_ch_vocab<<ch_vocab_vec.at(i)+" "+to_string(i)+"\n"; } f_ch_vocab.close(); ofstream f_en_vocab("vocab.en"); if (!f_en_vocab.is_open()) { cout<<"fail open en vocab file to write!\n"; return; } for(size_t i=0;i<en_vocab_vec.size();i++) { f_en_vocab<<en_vocab_vec.at(i)+" "+to_string(i)+"\n"; } f_en_vocab.close(); }
int EBuffer::BlockPaste(int clipboard) { EPoint B, E; int L, BL; if (SystemClipboard) GetPMClip(clipboard); if (SSBuffer == 0) return 0; if (SSBuffer->RCount == 0) return 0; AutoExtend = 0; BFI(SSBuffer, BFI_TabSize) = BFI(this, BFI_TabSize); BFI(SSBuffer, BFI_ExpandTabs) = BFI(this, BFI_ExpandTabs); BFI(SSBuffer, BFI_Undo) = 0; BlockUnmark(); B.Row = VToR(CP.Row); B.Col = CP.Col; BL = B.Row; switch(BlockMode) { case bmLine: B.Col = 0; for (L = 0; L < SSBuffer->RCount; L++) { if (InsLine(BL, 0) == 0) return 0; if (InsLineText(BL, 0, SSBuffer->LineLen(L), 0, SSBuffer->RLine(L)) == 0) return 0; BL++; } E.Row = BL; E.Col = 0; SetBB(B); SetBE(E); break; case bmColumn: for (L = 0; L < SSBuffer->RCount; L++) { if (AssertLine(BL) == 0) return 0; if (InsLineText(BL, B.Col, SSBuffer->LineLen(L), 0, SSBuffer->RLine(L)) == 0) return 0; if (TrimLine(BL) == 0) return 0; BL++; } if (AssertLine(BL) == 0) return 0; E.Row = BL; E.Col = B.Col + SSBuffer->LineLen(0); SetBB(B); SetBE(E); break; case bmStream: if (SSBuffer->RCount > 1) if (SplitLine(B.Row, B.Col) == 0) return 0; if (InsLineText(B.Row, B.Col, SSBuffer->LineLen(0), 0, SSBuffer->RLine(0)) == 0) return 0; E = B; E.Col += SSBuffer->LineLen(0); BL++; if (SSBuffer->RCount > 1) { for (L = 1; L < SSBuffer->RCount - 1; L++) { if (InsLine(BL, 0) == 0) return 0; if (InsLineText(BL, 0, SSBuffer->LineLen(L), 0, SSBuffer->RLine(L)) == 0) return 0; BL++; } L = SSBuffer->RCount - 1; if (InsLineText(BL, 0, SSBuffer->LineLen(L), 0, SSBuffer->RLine(L)) == 0) return 0; E.Col = SSBuffer->LineLen(L); E.Row = BL; } SetBB(B); SetBE(E); break; } return 1; }
int EBuffer::LineTrim() { return TrimLine(VToR(CP.Row)); }
int EBuffer::FileTrim() { for (int L = 0; L < RCount; L++) if (TrimLine(L) == 0) return 0; return 1; }
int EBuffer::LineSplit() { if (SplitLine(VToR(CP.Row), CP.Col) == 0) return 0; if (BFI(this, BFI_Trim)) if (TrimLine(VToR(CP.Row)) == 0) return 0; return 1; }
/** * Load the cell configuration into memory. * * Read the cell configuration into a newly allocated or cleared afsconf_dir * structure. Reads the CellServDB file, and if present, the cell alias file, * the key files, and kerberos related files. * * If the configuration cannot be loaded for any reason, any partial changes * are freed. The name member is preserved. * * @param[in,out] adir pointer to the cell configuration * the name member must be set to the pathname of the * cell configuration to be loaded. All other members * must be unassigned. * * @returns 0 on success */ static int LoadConfig(struct afsconf_dir *adir) { afsconf_FILE *tf; char *tp, *bp; struct afsconf_entry *curEntry; struct afsconf_aliasentry *curAlias; afs_int32 code; afs_int32 i; char tbuffer[256]; struct stat tstat; #ifdef AFS_NT40_ENV cm_enumCellRegistry_t enumCellRegistry = {0, 0}; #endif /* AFS_NT40_ENV */ /* init the keys queue before any call to UnloadConfig() */ _afsconf_InitKeys(adir); /* figure out the local cell name */ #ifdef AFS_NT40_ENV i = GetCellNT(adir); enumCellRegistry.adir = adir; #else i = GetCellUnix(adir); #endif #ifndef AFS_FREELANCE_CLIENT /* no local cell not fatal in freelance */ if (i) { return i; } #endif /* now parse the individual lines */ curEntry = 0; _afsconf_CellServDBPath(adir, &adir->cellservDB); #ifdef AFS_NT40_ENV if (_afsconf_IsClientConfigDirectory(adir->name)) enumCellRegistry.client = 1; #endif /* AFS_NT40_ENV */ if (!stat(adir->cellservDB, &tstat)) { adir->timeRead = tstat.st_mtime; } else { adir->timeRead = 0; } tf = fopen(adir->cellservDB, "r"); if (!tf) { return -1; } /* The CellServDB file is now open. * The following code parses the contents of the * file and creates a list with the first cell entry * in the CellServDB file at the end of the list. * * No checking is performed for duplicates. * The side effects of this process are that duplicate * entries appended to the end of the CellServDB file * take precedence and are found in a shorter period * of time. */ while (1) { tp = fgets(tbuffer, sizeof(tbuffer), tf); if (!tp) break; TrimLine(tbuffer, sizeof tbuffer); /* remove white space */ if (tbuffer[0] == 0 || tbuffer[0] == '\n') continue; /* empty line */ if (tbuffer[0] == '>') { char linkedcell[MAXCELLCHARS]; /* start new cell item */ if (curEntry) { /* thread this guy on the list */ curEntry->next = adir->entries; adir->entries = curEntry; curEntry = 0; } curEntry = calloc(1, sizeof(struct afsconf_entry)); code = ParseCellLine(tbuffer, curEntry->cellInfo.name, linkedcell); if (code) { UnloadConfig(adir); fclose(tf); free(curEntry); return -1; } if (linkedcell[0] != '\0') curEntry->cellInfo.linkedCell = strdup(linkedcell); } else { /* new host in the current cell */ if (!curEntry) { UnloadConfig(adir); fclose(tf); return -1; } i = curEntry->cellInfo.numServers; if (i < MAXHOSTSPERCELL) { code = ParseHostLine(tbuffer, &curEntry->cellInfo.hostAddr[i], curEntry->cellInfo.hostName[i], &curEntry->cellInfo.clone[i]); if (code) { if (code == AFSCONF_SYNTAX) { for (bp = tbuffer; *bp != '\n'; bp++) { /* Take out the <cr> from the buffer */ if (!*bp) break; } *bp = '\0'; fprintf(stderr, "Can't properly parse host line \"%s\" in configuration file %s\n", tbuffer, adir->cellservDB); } free(curEntry); fclose(tf); UnloadConfig(adir); return -1; } curEntry->cellInfo.numServers = ++i; } else { fprintf(stderr, "Too many hosts for cell %s in configuration file %s\n", curEntry->cellInfo.name, adir->cellservDB); } } } fclose(tf); /* close the file now */ /* end the last partially-completed cell */ if (curEntry) { curEntry->next = adir->entries; adir->entries = curEntry; } #ifdef AFS_NT40_ENV /* * Windows maintains a CellServDB list in the Registry * that supercedes the contents of the CellServDB file. * Prepending these entries to the head of the list * is sufficient to enforce the precedence. */ cm_EnumerateCellRegistry( enumCellRegistry.client, cm_enumCellRegistryProc, &enumCellRegistry); #endif /* AFS_NT40_ENV */ /* Read in the alias list */ strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLALIAS_FILE, (char *)NULL); tf = fopen(tbuffer, "r"); while (tf) { char *aliasPtr; tp = fgets(tbuffer, sizeof(tbuffer), tf); if (!tp) break; TrimLine(tbuffer, sizeof tbuffer); /* remove white space */ if (tbuffer[0] == '\0' || tbuffer[0] == '\n' || tbuffer[0] == '#') continue; /* empty line */ tp = tbuffer; while (tp[0] != '\0' && tp[0] != ' ' && tp[0] != '\t') tp++; if (tp[0] == '\0') continue; /* invalid line */ while (tp[0] != '\0' && (tp[0] == ' ' || tp[0] == '\t')) 0[tp++] = '\0'; if (tp[0] == '\0') continue; /* invalid line */ aliasPtr = tp; while (tp[0] != '\0' && tp[0] != ' ' && tp[0] != '\t' && tp[0] != '\r' && tp[0] != '\n') tp++; tp[0] = '\0'; curAlias = calloc(1, sizeof(*curAlias)); strlcpy(curAlias->aliasInfo.aliasName, aliasPtr, sizeof curAlias->aliasInfo.aliasName); strlcpy(curAlias->aliasInfo.realName, tbuffer, sizeof curAlias->aliasInfo.realName); curAlias->next = adir->alias_entries; adir->alias_entries = curAlias; } if (tf != NULL) fclose(tf); /* now read the fs keys, if possible */ code = _afsconf_LoadKeys(adir); if (code) { return code; } code = _afsconf_LoadRealms(adir); return code; }
int EBuffer::BackSpace() { int Y = VToR(CP.Row); if (CheckBlock() == 1 && BFI(this, BFI_BackSpKillBlock)) { if (BlockKill() == 0) return 0; } else if (BFI(this, BFI_WordWrap) == 2 && CP.Row > 0 && !IsLineBlank(Y - 1) && CP.Col <= BFI(this, BFI_LeftMargin) && CP.Col <= LineIndented(Y)) { if (SetPos(LineLen(Y - 1), CP.Row - 1) == 0) return 0; } else if (CP.Col == 0) { if (CP.Row > 0) if (ExposeRow(VToR(CP.Row) - 1) == 0) return 0; if (MoveUp() == 0) return 0; if (MoveLineEnd() == 0) return 0; if (LineJoin() == 0) return 0; } else { if (BFI(this, BFI_BackSpUnindents) && (LineIndented(Y) == CP.Col)) { int C = CP.Col, C1 = 0; int L = VToR(CP.Row); C1 = C; while (L > 0 && (IsLineBlank(L - 1) || (C1 = LineIndented(L - 1)) >= C)) L--; if (L == 0) C1 = 0; if (C1 == C) C1--; if (C1 < 0) C1 = 0; if (C1 > C) C1 = C; if (SetPos(C1, CP.Row) == 0) return 0; if (C > LineIndented(Y)) return 0; if (DelText(Y, C1, C - C1) == 0) return 0; if (BFI(this, BFI_Insert) == 0) if (InsText(Y, C1, 1, " ") == 0) return 0; } else if (BFI(this, BFI_BackSpKillTab)) { int P; int C = CP.Col, C1; P = CharOffset(RLine(Y), C - 1); C1 = ScreenPos(RLine(Y), P); if (SetPos(C1, CP.Row) == 0) return 0; if (DelText(Y, C1, C - C1) == 0) return 0; if (BFI(this, BFI_Insert) == 0) if (InsText(Y, C1, 1, " ") == 0) return 0; } else { if (MovePrev() == 0) return 0; ELine *L = RLine(Y); int C = CharOffset(L, CP.Col); if (L->Count > 0 && L->Chars[C] == 9) { /* We're on top of tab character. Skip over all spaces and tabs so that only the last space/tab gets deleted. */ while (C < L->Count && (L->Chars[C+1] == 9 || L->Chars[C+1] == ' ')) C++; } if (DelText(Y, ScreenPos(L, C), 1) == 0) return 0; if (BFI(this, BFI_Insert) == 0) if (InsText(Y, ScreenPos(L, C), 1, " ") == 0) return 0; } } if (BFI(this, BFI_WordWrap) == 2) { if (DoWrap(0) == 0) return 0; } if (BFI(this, BFI_Trim)) { Y = VToR(CP.Row); if (TrimLine(Y) == 0) return 0; } return 1; }