#!/bin/bash #.Y / 70 83 / / / / 105 / / / / / / ;A4_QUER.Y #.YT 3 2 0 0 3 3 1 / / / #.H!a!0:linux//io/f_/Attributes0.!c # # copyright : (C) 2009 by Thomas Bruecker =: tbrue # email : public0x05bf@bluewin.ch # # tbrue 03apr2007; 13apr2007: works perfect ! # # f_ Attributes : functions for (dos)-file-attributes # +++++++++++++++++++++++++++++++++++++++++++++++++++ # # MyHash("linux//io/f_/Attributes") = 0x0C32 # # * for every function: # * if returned result is not commented, the function returns 0 on no-error. # SCRIPTS=root/bin f_QToAttributeCommand() # ?ToAttributeCommand # * if attribute in { H, R, S }, write the complete dos-command # "attrib" to stdout. # $1 : one line written by the dos-command "attrib". { local AttributeSet0x0C32 StrippedLine0x0C32 StrippedLine0x0C32=$(f_RemoveCR "$1") AttributeSet0x0C32=$(f_ToAttributeSet "$StrippedLine0x0C32") if f_ConvertLineQ "$AttributeSet0x0C32"; then echo -n "ATTRIB $AttributeSet0x0C32 " echo -n "\"$(f_ToPath "$StrippedLine0x0C32")\"" echo -en "\r\n" fi return 0 } f_NumLines() # #Lines # * write #lines to stdout. # $1 : input-file. { /usr/bin/wc -l < $1 return # /usr/bin/wc returns 0 . } f_AttributeListToAttributeCommands() # * convert an list written by the dos-command "attrib" to a list of # dos-commands "attrib ..." and write list to stdout. # $1: input list. { local Count0x0C32 I0x0C32 Line0x0C32 Count0x0C32=$(f_NumLines $1) echo $Count0x0C32 > /dev/stderr echo -en "@ECHO off\r\n" for((I0x0C32=1; Count0x0C32+1-I0x0C32; I0x0C32++)) do Line0x0C32=$(f_LineN $1 $I0x0C32) echo $I0x0C32 > /dev/stderr f_QToAttributeCommand "$Line0x0C32" done return 0 } f_ConvertLineQ() # ConvertLine? # * returns "shell-true" if the line should be converted. # $1 : attribute-set equivalent to one generated by f_ToAttributeSet . { echo "$1" | /usr/bin/grep -q "+" return # result from grep command is returned. } f_LineN() # * get line# from input-file, write it to stdout. # $1 : input-file. # $2 : n; the line# . { /usr/bin/sed -n $2p $1 return # /usr/bin/sed returns 0 . } f_RemoveCR() # * remove from one line written by the dos-command "attrib"; # writer result to stdout. # $1 : one line written by the dos-command "attrib". { echo "$1" | sed 's/\r//' return 0 } f_ToAttributes() # * write attributes to stdout # $1 : one line written by the dos-command "attrib". { # example: " SHR " # columns: 1234567890 echo "$1" | /usr/bin/colrm 10 return # /usr/bin/colrm returns 0 . } f_ToAttributeSet() # * write attribute set for the dos-command "attrib"s to stdout. # $1 : one line written by the dos-command "attrib". { local Attributes0x0C32 AttributeSet0x0C32 Attributes0x0C32=$(f_ToAttributes "$1") # convert "R": if echo $Attributes0x0C32 | /usr/bin/grep -q "R"; then AttributeSet0x0C32=${AttributeSet0x0C32}"+R" fi # convert "S": if echo $Attributes0x0C32 | /usr/bin/grep -q "S"; then AttributeSet0x0C32=${AttributeSet0x0C32}" +S" fi # convert "H": if echo $Attributes0x0C32 | /usr/bin/grep -q "H"; then AttributeSet0x0C32=${AttributeSet0x0C32}" +H" fi echo $AttributeSet0x0C32 return # echo returns 0 . } f_ToPath() # * write path to stdout. # $1 : one line written by the dos-command "attrib". { # example: " SHR " # columns: 123456789012 echo "$1" | colrm 1 11 return # /usr/bin/colrm returns 0 . }