nis-util
1.0.D108
|
00001 // 00002 // nis-util - NIS Administration Utilities 00003 // Copyright (C) 2012 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or (at 00008 // your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License along 00016 // with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #include <lib/ac/assert.h> 00020 #include <lib/ac/stdio.h> 00021 00022 #include <lib/source_location.h> 00023 00024 00025 source_location::~source_location() 00026 { 00027 } 00028 00029 00030 source_location::source_location() : 00031 file_name("the command line"), 00032 line_number(0) 00033 { 00034 } 00035 00036 00037 source_location::source_location( 00038 const rcstring &a_file_name, 00039 int a_line_number 00040 ) : 00041 file_name(a_file_name), 00042 line_number(a_line_number) 00043 { 00044 assert(line_number > 0); 00045 } 00046 00047 00048 source_location::source_location(const source_location &rhs) : 00049 file_name(rhs.file_name), 00050 line_number(rhs.line_number) 00051 { 00052 } 00053 00054 00055 source_location & 00056 source_location::operator=(const source_location &rhs) 00057 { 00058 if (this != &rhs) 00059 { 00060 file_name = rhs.file_name; 00061 line_number = rhs.line_number; 00062 } 00063 return *this; 00064 } 00065 00066 00067 rcstring 00068 source_location::get_both(void) 00069 const 00070 { 00071 if (line_number < 1) 00072 return file_name; 00073 char buffer[20]; 00074 snprintf(buffer, sizeof(buffer), ": %d", line_number); 00075 return (file_name + buffer); 00076 } 00077 00078 00079 source_location 00080 source_location::operator+(int nlines) 00081 const 00082 { 00083 int n = line_number + nlines; 00084 if (n < 1) 00085 n = 1; 00086 return source_location(file_name, n); 00087 } 00088 00089 00090 // vim: set ts=8 sw=4 et :