diff options
author | Sunil Shetye | 2019-05-16 12:18:48 +0530 |
---|---|---|
committer | Sunil Shetye | 2019-05-29 11:08:01 +0530 |
commit | 26b77d7593b5ee0792b6b556f5569ea4227c2b02 (patch) | |
tree | 8f92052234b01bf39b9c3a6e3cb12b3962d96b1b /macros/GeneralFunctions/KeyStr2FileStrPos.sci | |
parent | 5a73e6bec4a12db7afae9de300e39256f754d8d3 (diff) | |
download | scilab2c-26b77d7593b5ee0792b6b556f5569ea4227c2b02.tar.gz scilab2c-26b77d7593b5ee0792b6b556f5569ea4227c2b02.tar.bz2 scilab2c-26b77d7593b5ee0792b6b556f5569ea4227c2b02.zip |
convert to unix format
Diffstat (limited to 'macros/GeneralFunctions/KeyStr2FileStrPos.sci')
-rw-r--r-- | macros/GeneralFunctions/KeyStr2FileStrPos.sci | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/macros/GeneralFunctions/KeyStr2FileStrPos.sci b/macros/GeneralFunctions/KeyStr2FileStrPos.sci index e9fb1c48..6e818ec0 100644 --- a/macros/GeneralFunctions/KeyStr2FileStrPos.sci +++ b/macros/GeneralFunctions/KeyStr2FileStrPos.sci @@ -1,83 +1,83 @@ -function [flag_found,requested_line,line_position] = KeyStr2FileStrPos(filename,key_string,method)
-// function [flag_found,requested_line,line_position] = KeyStr2FileStrPos(filename,key_string,method)
-// --------------------------------------------------------------------------------
-// #RNU_RES_B
-// This function returns a line and its position from a specified ASCII file.
-// The line and the position returned starts with a key string specified in the
-// input parameters.
-//
-// Input data:
-// filename: path + name of the ASCII file.
-// key_string: string that specifies the initial portion of the line to return.
-// method: 'cut': in the returned line will be removed the key_string
-// 'no_cut': (default), in the returned line will not be removed the key_string
-//
-// Output data:
-// flag_found: 0 if the line is not found or an error occured.
-// 1 if the search succeed.
-// requested_line: is the line in the file which contains as first characters those
-// specified in the key_string.
-// line_position: position of the line in the file; the first line in the file
-// is the line number 1.
-// #RNU_RES_E
-//
-//
-// Status:
-// 08-Jul-2002 -- Author: Raffaele Nutricato
-// 08-Jul-2002 -- Raffaele Nutricato: Revision OK
-// 23-Nov-2004 -- Raffaele Nutricato: Changed disp to warning in if (flag_found == 0).
-// It allows to disable the message it generates
-// by using warning off.
-//
-// Copyright 2007 Raffaele Nutricato.
-// Contact: raffaele.nutricato@tiscali.it
-// -----------------------------------------------------------------
+function [flag_found,requested_line,line_position] = KeyStr2FileStrPos(filename,key_string,method) +// function [flag_found,requested_line,line_position] = KeyStr2FileStrPos(filename,key_string,method) +// -------------------------------------------------------------------------------- +// #RNU_RES_B +// This function returns a line and its position from a specified ASCII file. +// The line and the position returned starts with a key string specified in the +// input parameters. +// +// Input data: +// filename: path + name of the ASCII file. +// key_string: string that specifies the initial portion of the line to return. +// method: 'cut': in the returned line will be removed the key_string +// 'no_cut': (default), in the returned line will not be removed the key_string +// +// Output data: +// flag_found: 0 if the line is not found or an error occured. +// 1 if the search succeed. +// requested_line: is the line in the file which contains as first characters those +// specified in the key_string. +// line_position: position of the line in the file; the first line in the file +// is the line number 1. +// #RNU_RES_E +// +// +// Status: +// 08-Jul-2002 -- Author: Raffaele Nutricato +// 08-Jul-2002 -- Raffaele Nutricato: Revision OK +// 23-Nov-2004 -- Raffaele Nutricato: Changed disp to warning in if (flag_found == 0). +// It allows to disable the message it generates +// by using warning off. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- -// ------------------------------
-// --- Check input arguments. ---
-// ------------------------------
-SCI2CNInArgCheck(argn(2),2,3);
-
-
-if (argn(2) == 2)
- method = 'no_cut';
-end
-method = convstr(method, 'u');
-
-// Initialize output parameters
-flag_found = 0;
-requested_line = '';
-line_position = 0;
-
-// Open the text file (read only)
-[fid,mess] = mopen(filename,'r');
-if ( fid == -1 )
- disp(['Cannot open: '+filename])
- disp(mess);
- flag_found = 0;
- return;
-end
-
-// loop on the lines of the file
-num_chars = length(key_string);
-while (meof(fid) == 0)
- check_string = fgetl(fid);
- line_position = line_position + 1;
- if (key_string == check_string) & (key_string == num_chars) then
- flag_found = 1;
- requested_line = check_string;
- if (method =='cut') then
- requested_line(1:num_chars) = [];
- end
- mclose(fid);
- return;
- end
-end
-
-if (flag_found == 0)
- warning('Warning: string ' + key_string + ' not found in file: ' + filename);
- mclose(fid);
-end
-
-mclose(fid);
-endfunction
+// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,3); + + +if (argn(2) == 2) + method = 'no_cut'; +end +method = convstr(method, 'u'); + +// Initialize output parameters +flag_found = 0; +requested_line = ''; +line_position = 0; + +// Open the text file (read only) +[fid,mess] = mopen(filename,'r'); +if ( fid == -1 ) + disp(['Cannot open: '+filename]) + disp(mess); + flag_found = 0; + return; +end + +// loop on the lines of the file +num_chars = length(key_string); +while (meof(fid) == 0) + check_string = fgetl(fid); + line_position = line_position + 1; + if (key_string == check_string) & (key_string == num_chars) then + flag_found = 1; + requested_line = check_string; + if (method =='cut') then + requested_line(1:num_chars) = []; + end + mclose(fid); + return; + end +end + +if (flag_found == 0) + warning('Warning: string ' + key_string + ' not found in file: ' + filename); + mclose(fid); +end + +mclose(fid); +endfunction |