3 * FusionForge miscellaneous utils
5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 * removeCRLF() - remove any Carriage Return-Line Feed from a string.
28 * That function is useful to remove the possibility of a CRLF Injection when sending mail
29 * All the data that we will send should be passed through that function
31 * @param string The string that we want to empty from any CRLF
33 function util_remove_CRLF($str) {
34 return strtr($str, "\015\012", ' ');
39 * util_check_fileupload() - determines if a filename is appropriate for upload
41 * @param array The uploaded file as returned by getUploadedFile()
43 function util_check_fileupload($filename) {
45 /* Empty file is a valid file.
46 This is because this function should be called
47 unconditionally at the top of submit action processing
48 and many forms have optional file upload. */
49 if ($filename == 'none' || $filename == '') {
53 /* This should be enough... */
54 if (!is_uploaded_file($filename)) {
57 /* ... but we'd rather be paranoic */
58 if (strstr($filename, '..')) {
61 if (!is_file($filename)) {
64 if (!file_exists($filename)) {
67 if ((dirname($filename) != '/tmp') &&
68 (dirname($filename) != "/var/tmp")) {
75 * util_send_message() - Send email
76 * This function should be used in place of the PHP mail() function
78 * @param string The email recipients address
79 * @param string The email subject
80 * @param string The body of the email message
81 * @param string The optional email sender address. Defaults to 'noreply@'
82 * @param string The addresses to blind-carbon-copy this message
83 * @param string The optional email sender name. Defaults to ''
84 * @param boolean Whether to send plain text or html email
87 function util_send_message($to,$subject,$body,$from='',$BCC='',$sendername='',$extra_headers='',$send_html_email=false) {
88 global $sys_bcc_all_email_address,$sys_sendmail_path;
91 $to='noreply@'.$GLOBALS['sys_default_domain'];
94 $from='noreply@'.$GLOBALS['sys_default_domain'];
98 $charset = _('UTF-8');
104 if ($extra_headers) {
105 $body2 .= $extra_headers."\n";
108 "\nFrom: ".util_encode_mailaddr($from,$sendername,$charset);
109 if (!empty($sys_bcc_all_email_address)) {
110 $BCC.=",$sys_bcc_all_email_address";
113 $body2 .= "\nBCC: $BCC";
115 $send_html_email?$type="html":$type="plain";
116 $body2 .= "\n".util_encode_mimeheader("Subject", $subject, $charset).
117 "\nContent-type: text/$type; charset=$charset".
119 util_convert_body($body, $charset);
121 if (!$sys_sendmail_path){
122 $sys_sendmail_path="/usr/sbin/sendmail";
125 exec ("/bin/echo ". util_prep_string_for_sendmail($body2) .
126 " | ".$sys_sendmail_path." -f'$from' -t -i > /dev/null 2>&1 &");
127 // WARNING : popen commented code probably brought some trouble, we will use the pipe method as we were before
128 /*if (!$handle = popen($sys_sendmail_path." -f'$from' -t -i", "w")) {
129 echo "<p>Error: cannot run '$sys_sendmail_path' - mail not sent</p>\n";
131 fwrite($handle, util_prep_string_for_sendmail($body2));
137 * util_encode_mailaddr() - Encode email address to MIME format
139 * @param string The email address
140 * @param string The email's owner name
141 * @param string The converting charset
144 function util_encode_mailaddr($email,$name,$charset) {
145 if (function_exists('mb_convert_encoding') && trim($name) != "") {
146 $name = "=?".$charset."?B?".
147 base64_encode(mb_convert_encoding(
148 $name,$charset,"UTF-8")).
152 return $name." <".$email."> ";
156 * util_encode_mimeheader() - Encode mimeheader
158 * @param string The name of the header (e.g. "Subject")
159 * @param string The email subject
160 * @param string The converting charset (like ISO-2022-JP)
161 * @return string The MIME encoded subject
164 function util_encode_mimeheader($headername,$str,$charset) {
165 if (function_exists('mb_internal_encoding') &&
166 function_exists('mb_encode_mimeheader')) {
167 $x = mb_internal_encoding();
168 mb_internal_encoding("UTF-8");
169 $y = mb_encode_mimeheader($headername . ": " . $str,
171 mb_internal_encoding($x);
175 if (!function_exists('mb_convert_encoding')) {
176 return $headername . ": " . $str;
179 return $headername . ": " . "=?".$charset."?B?".
180 base64_encode(mb_convert_encoding(
181 $str,$charset,"UTF-8")).
186 * util_convert_body() - Convert body of the email message
188 * @param string The body of the email message
189 * @param string The charset of the email message
190 * @return string The converted body of the email message
193 function util_convert_body($str,$charset) {
194 if (!function_exists('mb_convert_encoding') || $charset == 'UTF-8') {
198 return mb_convert_encoding($str,$charset,"UTF-8");
201 function util_send_jabber($to,$subject,$body) {
202 if (!$GLOBALS['sys_use_jabber']) {
205 $JABBER = new Jabber();
206 if (!$JABBER->Connect()) {
207 echo '<br />Unable to connect';
210 //$JABBER->SendAuth();
211 //$JABBER->AccountRegistration();
212 if (!$JABBER->SendAuth()) {
213 echo '<br />Auth Failure';
214 $JABBER->Disconnect();
216 //or die("Couldn't authenticate!");
218 $JABBER->SendPresence(NULL, NULL, "online");
220 $body=htmlspecialchars($body);
221 $to_arr=explode(',',$to);
222 for ($i=0; $i<count($to_arr); $i++) {
224 //echo '<br />Sending Jabbers To: '.$to_arr[$i];
225 if (!$JABBER->SendMessage($to_arr[$i], "normal", NULL, array("body" => $body,"subject"=>$subject))) {
226 echo '<br />Error Sending to '.$to_arr[$i];
231 $JABBER->CruiseControl(2);
232 $JABBER->Disconnect();
236 * util_prep_string_for_sendmail() - Prepares a string to be sent by email
238 * @param string The text to be prepared
239 * @returns The prepared text
242 function util_prep_string_for_sendmail($body) {
243 /*$body=str_replace("`","\\`",$body);
244 $body=str_replace("\"","\\\"",$body);
245 $body=str_replace("\$","\\\$",$body);*/
246 $body = escapeshellarg($body);
251 * util_handle_message() - a convenience wrapper which sends messages
252 * to either a jabber account or email account or both, depending on
255 * @param array array of user_id's from the user table
256 * @param string subject of the message
257 * @param string the message body
258 * @param string a comma-separated list of email address
259 * @param string a comma-separated list of jabber address
260 * @param string From header
262 function util_handle_message($id_arr,$subject,$body,$extra_emails='',$extra_jabbers='',$from='') {
265 if (count($id_arr) < 1) {
268 $res = db_query_params ('SELECT user_id,jabber_address,email,jabber_only FROM users WHERE user_id = ANY ($1)',
269 array (db_int_array_to_any_clause ($id_arr))) ;
270 $rows = db_numrows($res) ;
272 for ($i=0; $i<$rows; $i++) {
273 if (db_result($res, $i, 'user_id') == 100) {
274 // Do not send messages to "Nobody"
278 // Build arrays of the jabber address
280 if (db_result($res,$i,'jabber_address')) {
281 $address['jabber_address'][]=db_result($res,$i,'jabber_address');
282 if (db_result($res,$i,'jabber_only') != 1) {
283 $address['email'][]=db_result($res,$i,'email');
286 $address['email'][]=db_result($res,$i,'email');
289 if (isset ($address['email']) && count($address['email']) > 0) {
290 $extra_emails=implode($address['email'],',').',' . $extra_emails;
292 if (isset ($address['jabber_address']) && count($address['jabber_address']) > 0) {
293 $extra_jabbers=implode($address['jabber_address'],',').','.$extra_jabbers;
297 util_send_message('',$subject,$body,$from,$extra_emails);
299 if ($extra_jabbers) {
300 util_send_jabber($extra_jabbers,$subject,$body);
305 * util_unconvert_htmlspecialchars() - Unconverts a string converted with htmlspecialchars()
306 * This function requires PHP 4.0.3 or greater
308 * @param string The string to unconvert
309 * @returns The unconverted string
312 function util_unconvert_htmlspecialchars($string) {
313 if (strlen($string) < 1) {
316 //$trans = get_html_translation_table(HTMLENTITIES, ENT_QUOTES);
317 $trans = get_html_translation_table(HTML_ENTITIES);
318 $trans = array_flip ($trans);
319 $str = strtr ($string, $trans);
325 * util_result_columns_to_assoc() - Takes a result set and turns the column pair into an associative array
327 * @param string The result set ID
328 * @param int The column key
329 * @param int The optional column value
330 * @returns An associative array
333 function util_result_columns_to_assoc($result, $col_key=0, $col_val=1) {
334 $rows=db_numrows($result);
338 for ($i=0; $i<$rows; $i++) {
339 $arr[db_result($result,$i,$col_key)]=db_result($result,$i,$col_val);
348 * util_result_column_to_array() - Takes a result set and turns the optional column into an array
350 * @param int The result set ID
351 * @param int The column
355 function &util_result_column_to_array($result, $col=0) {
357 Takes a result set and turns the optional column into
360 $rows=db_numrows($result);
364 for ($i=0; $i<$rows; $i++) {
365 $arr[$i]=db_result($result,$i,$col);
374 * util_wrap_find_space() - Find the first space in a string
376 * @param string The string in which to find the space (must be UTF8!)
377 * @param int The number of characters to wrap - Default is 80
378 * @returns The position of the first space
381 function util_wrap_find_space($string,$wrap) {
388 //find the first space starting at $start
389 $pos=@strpos($string,' ',$start);
391 //if that space is too far over, go back and start more to the left
392 if (($pos > ($wrap+5)) || !$pos) {
394 $start=($wrap-($try*5));
395 //if we've gotten so far left , just truncate the line
398 $code = ord(substr($string,$wrap,1));
401 //Here is single byte character
402 //or head of multi byte character
405 //Do not break multi byte character
420 * util_line_wrap() - Automatically linewrap text
422 * @param string The text to wrap
423 * @param int The number of characters to wrap - Default is 80
424 * @param string The line break to use - Default is '\n'
425 * @returns The wrapped text
428 function util_line_wrap ($text, $wrap = 80, $break = "\n") {
429 $paras = explode("\n", $text);
433 while ($i < count($paras)) {
434 if (strlen($paras[$i]) <= $wrap) {
435 $result[] = $paras[$i];
438 $pos=util_wrap_find_space($paras[$i],$wrap);
440 $result[] = substr($paras[$i], 0, $pos);
442 $new = trim(substr($paras[$i], $pos, strlen($paras[$i]) - $pos));
445 $pos=util_wrap_find_space($paras[$i],$wrap);
451 return implode($break, $result);
455 * util_make_links() - Turn URL's into HREF's.
457 * @param string The URL
458 * @returns The HREF'ed URL
461 function util_make_links ($data='') {
465 $lines = split("\n",$data);
467 while ( list ($key,$line) = each ($lines)) {
468 // When we come here, we usually have form input
469 // encoded in entities. Our aim is to NOT include
470 // angle brackets in the URL
471 // (RFC2396; http://www.w3.org/Addressing/URL/5.1_Wrappers.html)
472 $line = str_replace('>', "\1", $line);
473 $line = eregi_replace("([ \t]|^)www\."," http://www.",$line);
474 $text = eregi_replace("([[:alnum:]]+)://([^[:space:]<\1]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" target=\"_new\">\\1://\\2\\3</a>", $line);
475 $text = eregi_replace("([[:space:]]|^)(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "\\1<a href=\"mailto:\\2\" target=\"_new\">\\2</a>", $text);
476 $text = str_replace("\1", '>', $text);
483 * show_priority_colors_key() - Show the priority colors legend
486 function show_priority_colors_key() {
487 echo '<p /><strong> '._('Priority Colors').':</strong><br />
489 <table border="0"><tr>';
491 for ($i=1; $i<6; $i++) {
493 <td class="priority'.$i.'">'.$i.'</td>';
495 echo '</tr></table>';
499 * utils_buildcheckboxarray() - Build a checkbox array
501 * @param int Number of options to be in the array
502 * @param string The name of the checkboxes
503 * @param array An array of boxes to be pre-checked
506 function utils_buildcheckboxarray($options,$name,$checked_array) {
507 $option_count=count($options);
508 $checked_count=count($checked_array);
510 for ($i=1; $i<=$option_count; $i++) {
512 <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"';
513 for ($j=0; $j<$checked_count; $j++) {
514 if ($i == $checked_array[$j]) {
518 echo '> '.$options[$i];
523 * utils_requiredField() - Adds the required field marker
525 * @return a string holding the HTML to mark a required field
527 function utils_requiredField() {
528 return '<span class="requiredfield">*</span>';
532 * GraphResult() - Takes a database result set and builds a graph.
533 * The first column should be the name, and the second column should be the values
534 * Be sure to include HTL_Graphs.php before using this function
536 * @author Tim Perdue tperdue@valinux.com
537 * @param int The databse result set ID
538 * @param string The title of the graph
541 Function GraphResult($result,$title) {
542 $rows=db_numrows($result);
544 if ((!$result) || ($rows < 1)) {
550 for ($j=0; $j<db_numrows($result); $j++) {
551 if (db_result($result, $j, 0) != '' && db_result($result, $j, 1) != '' ) {
552 $names[$j]= db_result($result, $j, 0);
553 $values[$j]= db_result($result, $j, 1);
558 This is another function detailed below
560 GraphIt($names,$values,$title);
565 * GraphIt() - Build a graph
567 * @author Tim Perdue tperdue@valinux.com
568 * @param array An array of names
569 * @param array An array of values
570 * @param string The title of the graph
573 Function GraphIt($name_string,$value_string,$title) {
576 $counter=count($name_string);
579 Can choose any color you wish
583 for ($i = 0; $i < $counter; $i++) {
584 $bars[$i]=$HTML->COLOR_LTBACK1;
587 $counter=count($value_string);
590 Figure the max_value passed in, so scale can be determined
595 for ($i = 0; $i < $counter; $i++) {
596 if ($value_string[$i] > $max_value) {
597 $max_value=$value_string[$i];
601 if ($max_value < 1) {
606 I want my graphs all to be 800 pixels wide, so that is my divisor
609 $scale=(400/$max_value);
612 I create a wrapper table around the graph that holds the title
618 echo $GLOBALS['HTML']->listTableTop ($title_arr);
621 Create an associate array to pass in. I leave most of it blank
650 This is the actual call to the HTML_Graphs class
653 html_graph($name_string,$value_string,$bars,$vals);
657 <!-- end outer graph table -->';
658 echo $GLOBALS['HTML']->listTableBottom();
662 * ShowResultSet() - Show a generic result set
663 * Very simple, plain way to show a generic result set
665 * @param int The result set ID
666 * @param string The title of the result set
667 * @param bool The option to turn URL's into links
668 * @param bool The option to display headers
669 * @param array The db field name -> label mapping
670 * @param array Don't display these cols
673 function ShowResultSet($result,$title='',$linkify=false,$displayHeaders=true,$headerMapping=array(), $excludedCols=array()) {
674 global $group_id,$HTML;
677 $rows = db_numrows($result);
678 $cols = db_numfields($result);
680 echo '<table border="0" width="100%">';
682 /* Create the headers */
683 $headersCellData = array();
684 $colsToKeep = array();
685 for ($i=0; $i < $cols; $i++) {
686 $fieldName = db_fieldname($result, $i);
687 if(in_array($fieldName, $excludedCols)) {
691 if(isset($headerMapping[$fieldName])) {
692 if(is_array($headerMapping[$fieldName])) {
693 $headersCellData[] = $headerMapping[$fieldName];
695 $headersCellData[] = array($headerMapping[$fieldName]);
699 $headersCellData[] = array($fieldName);
703 /* Create the title */
704 if(strlen($title) > 0) {
705 $titleCellData = array();
706 $titleCellData[] = array($title, 'colspan="'.count($headersCellData).'"');
707 echo $HTML->multiTableRow('', $titleCellData, TRUE);
710 /* Display the headers */
711 if($displayHeaders) {
712 echo $HTML->multiTableRow('', $headersCellData, TRUE);
715 /* Create the rows */
716 for ($j = 0; $j < $rows; $j++) {
717 echo '<tr '. $HTML->boxGetAltRowStyle($j) . '>';
718 for ($i = 0; $i < $cols; $i++) {
719 if(in_array($i, $colsToKeep)) {
720 if ($linkify && $i == 0) {
721 $link = '<a href="'.getStringFromServer('PHP_SELF').'?';
723 if ($linkify == "bug_cat") {
724 $link .= 'group_id='.$group_id.'&bug_cat_mod=y&bug_cat_id='.db_result($result, $j, 'bug_category_id').'">';
725 } else if($linkify == "bug_group") {
726 $link .= 'group_id='.$group_id.'&bug_group_mod=y&bug_group_id='.db_result($result, $j, 'bug_group_id').'">';
727 } else if($linkify == "patch_cat") {
728 $link .= 'group_id='.$group_id.'&patch_cat_mod=y&patch_cat_id='.db_result($result, $j, 'patch_category_id').'">';
729 } else if($linkify == "support_cat") {
730 $link .= 'group_id='.$group_id.'&support_cat_mod=y&support_cat_id='.db_result($result, $j, 'support_category_id').'">';
731 } else if($linkify == "pm_project") {
732 $link .= 'group_id='.$group_id.'&project_cat_mod=y&project_cat_id='.db_result($result, $j, 'group_project_id').'">';
734 $link = $linkend = '';
737 $link = $linkend = '';
739 echo '<td>'.$link . db_result($result, $j, $i) . $linkend.'</td>';
751 * validate_email() - Validate an email address
753 * @param string The address string to validate
754 * @returns true on success/false on error
757 function validate_email ($address) {
758 return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $address) !== false);
762 * validate_emails() - Validate a list of e-mail addresses
764 * @param string E-mail list
765 * @param char Separator
766 * @returns array Array of invalid e-mail addresses (if empty, all addresses are OK)
768 function validate_emails ($addresses, $separator=',') {
769 if (strlen($addresses) == 0) return array();
771 $emails = explode($separator, $addresses);
774 if (is_array($emails)) {
775 foreach ($emails as $email) {
776 $email = trim($email); // This is done so we can validate lists like "a@b.com, c@d.com"
777 if (!validate_email($email)) $ret[] = $email;
786 * util_is_valid_filename() - Verifies whether a file has a valid filename
788 * @param string The file to verify
789 * @returns true on success/false on error
792 function util_is_valid_filename ($file) {
794 $invalidchars = eregi_replace("[-A-Z0-9+_\.]","",$file);
796 if (!empty($invalidchars)) {
799 if (strstr($file,'..')) {
808 * valid_hostname() - Validates a hostname string to make sure it doesn't contain invalid characters
810 * @param string The optional hostname string
811 * @returns true on success/false on failur
814 function valid_hostname ($hostname = "xyz") {
817 $invalidchars = eregi_replace("[-A-Z0-9\.]","",$hostname);
819 if (!empty($invalidchars)) {
823 //double dot, starts with a . or -
824 if (ereg("\.\.",$hostname) || ereg("^\.",$hostname) || ereg("^\-",$hostname)) {
828 $multipoint = explode(".",$hostname);
830 if (!(is_array($multipoint)) || ((count($multipoint) - 1) < 1)) {
840 * human_readable_bytes() - Translates an integer representing bytes to a human-readable format.
842 * Format file size in a human-readable way
843 * such as "xx Megabytes" or "xx Mo"
845 * @author Andrea Paleni <andreaSPAMLESS_AT_SPAMLESScriticalbit.com>
847 * @param int bytes is the size
848 * @param bool base10 enable base 10 representation, otherwise
849 * default base 2 is used
850 * @param int round number of fractional digits
851 * @param array labels strings associated to each 2^10 or
852 * 10^3(base10==true) multiple of base units
854 function human_readable_bytes ($bytes, $base10=false, $round=0, $labels=array(' bytes', ' KB', ' MB', ' GB')) {
855 if ($bytes <= 0 || !is_array($labels) || (count($labels) <= 0)) {
858 $step = $base10 ? 3 : 10;
859 $base = $base10 ? 10 : 2;
860 $log = (int)(log10($bytes)/log10($base));
862 foreach ($labels as $p=>$lab) {
867 if ($lab == " MB" or $lab == " GB") {
870 $text = round($bytes/pow($base,$pow),$round).$lab;
877 * ls - lists a specified directory and returns an array of files
878 * @param string the path of the directory to list
879 * @param boolean whether to filter out directories and illegal filenames
880 * @return array array of file names.
882 function &ls($dir,$filter=false) {
883 exec('ls -c1 '.$dir,$out);
885 for ($i=0; $i<count($out); $i++) {
886 if (util_is_valid_filename($out[$i]) && is_file($dir.'/'.$out[$i])) {
887 $filtered[]=$out[$i];
897 * readfile_chunked() - replacement for readfile
899 * @param string The file path
900 * @param bool Whether to return bytes served or just a bool
903 function readfile_chunked($filename, $returnBytes=true) {
904 $chunksize = 1*(1024*1024); // 1MB chunks
908 $handle = fopen($filename, 'rb');
909 if ($handle === false) {
913 while (!feof($handle)) {
914 $buffer = fread($handle, $chunksize);
919 $byteCounter += strlen($buffer);
922 $status = fclose($handle);
923 if ($returnBytes && $status) {
924 return $byteCounter; // return num. bytes delivered like readfile() does.
930 * util_is_root_dir() - Checks if a directory points to the root dir
931 * @param string Directory
934 function util_is_root_dir($dir) {
935 return !preg_match('/[^\\/]/',$dir);
938 function normalized_urlprefix () {
939 $prefix = $GLOBALS['sys_urlprefix'] ;
940 $prefix = ereg_replace ("^/", "", $prefix) ;
941 $prefix = ereg_replace ("/$", "", $prefix) ;
942 $prefix = "/$prefix/" ;
948 function util_make_url ($path) {
949 if ($GLOBALS['sys_use_ssl'])
954 $url .= $GLOBALS['sys_default_domain'] ;
955 $url .= normalized_urlprefix () ;
956 $path = ereg_replace ("^/", "", $path) ;
961 function util_make_link ($path, $text, $extra_params=false, $absolute=false) {
963 if (is_array($extra_params)) {
964 foreach ($extra_params as $key => $value) {
965 $ep .= "$key=\"$value\" ";
969 return '<a ' . $ep . 'href="' . $path . '">' . $text . '</a>' ;
971 return '<a ' . $ep . 'href="' . util_make_url ($path) . '">' . $text . '</a>' ;
975 function util_make_link_u ($username, $user_id,$text) {
976 return '<a href="' . util_make_url_u ($username, $user_id) . '">' . $text . '</a>' ;
979 function util_make_url_u ($username, $user_id) {
980 if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
981 return util_make_url ("/developer/?user_id=$user_id");
983 return util_make_url ("/users/$username/");
987 function util_make_link_g ($groupame, $group_id,$text) {
988 return '<a href="' . util_make_url_g ($groupame, $group_id) . '">' . $text . '</a>' ;
991 function util_make_url_g ($groupame, $group_id) {
992 if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
993 return util_make_url ("/project/?group_id=$group_id");
995 return util_make_url ("/projects/$groupame/");
999 function util_ensure_value_in_set ($value, $set) {
1000 if (in_array ($value, $set)) {
1009 // c-file-style: "bsd"