1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
|
;;
;; Lepton EDA
;; lepton-upcfg - gEDA => Lepton EDA configuration upgrade utility
;; Copyright (C) 2019 dmn <graahnul.grom@gmail.com>
;; Copyright (C) 2019-2022 Lepton EDA Contributors
;; License: GPLv2+. See the COPYING file
;;
(use-modules (ice-9 format)
(ice-9 rdelim) ; read-line()
(ice-9 getopt-long)
(lepton ffi)
(lepton legacy-config)
(lepton log)
(lepton version))
;; Initialize liblepton library.
(liblepton_init)
(unless (getenv "LEPTON_INHIBIT_RC_FILES")
(register-data-dirs))
(edascm_init)
; command line options:
;
( define cmd-line-args-spec
( list
( list ; --local (-l)
'local
( list 'single-char #\l )
( list 'value #f )
)
( list ; --user (-u)
'user
( list 'single-char #\u )
( list 'value #f )
)
( list ; --copy (-c)
'copy
( list 'single-char #\c )
( list 'value #f )
)
( list ; --overwrite (-x)
'overwrite
( list 'single-char #\x )
( list 'value #f )
)
( list ; --help (-h)
'help
( list 'single-char #\h )
( list 'value #f )
)
( list ; --version (-V)
'version
( list 'single-char #\V )
( list 'value #f )
)
)
) ; cmd-line-args-spec
( define ( usage exit-code )
( format #t "~
Usage: lepton-upcfg [OPTIONS] | FILE
Lepton EDA configuration upgrade utility.
Converts geda*.conf configuration files
to corresponding lepton*.conf files.
By default, the upgraded configuration
is printed to standard output.
One of the options can be passed on the
command line to upgrade the configuration
located in predefined locations. Instead of
the options, one can specify the
configuration file path to convert and
redirect the output to some destination file.
Options:
-l, --local geda.conf => lepton.conf
(in current directory)
-u, --user geda-user.conf => lepton-user.conf
(in user configuration directory)
-c, --copy Write to configuration file, not STDOUT
-x, --overwrite Overwrite existing files
-h, --help Show usage information
-V, --version Show version information
Report bugs at <~a>
Lepton EDA homepage: <~a>
"
( lepton-version-ref 'bugs )
( lepton-version-ref 'url )
)
( primitive-exit exit-code )
)
( define ( version )
( display-lepton-version #:print-name #t #:copyright #t )
( primitive-exit 0 )
)
( define ( failure )
( upcfg-log "lepton-upcfg: configuration upgrade failed.~%" )
( primitive-exit 1 )
)
( define ( prompt-for-user-cfg ids )
( let
(
( i 0 )
( ndx #f )
)
( define ( input-error )
( upcfg-log "ee: wrong value entered~%" )
( failure )
)
( upcfg-log "ii: more than one user configuration files found:~%" )
( while ( < i (length ids) )
( upcfg-log "~d: ~a~%" (1+ i) (config-file-path (list-ref ids i)) )
( set! i (1+ i) )
)
( upcfg-log "Type config file number to upgrade and press Enter: " )
( set! ndx (false-if-exception (read-line)) )
( set! ndx (false-if-exception (string->number ndx)) )
( unless ndx
( input-error )
)
( upcfg-log "ii: choice: [ ~a ]~%" ndx )
( set! ndx ( 1- ndx ) )
( if ( or (< ndx 0) (>= ndx (length ids)) )
( input-error )
)
; return:
( list-ref ids ndx )
) ; let
) ; prompt-for-user-cfg()
( define ( get-user-cfg-id )
( let
(
( ids (find-user-config-files) )
)
( when ( null? ids )
( upcfg-log "ii: no user configuration files found.~%" )
( primitive-exit 0 )
)
; return:
( if ( > (length ids) 1 )
( prompt-for-user-cfg ids ) ; if
( list-ref ids 0 ) ; else
)
) ; let
) ; get-user-cfg-id()
; program entry point:
;
( define ( main )
( let*
(
( cmd-line-args (getopt-long (program-arguments) cmd-line-args-spec) )
( files (option-ref cmd-line-args '() '()) )
( copy (option-ref cmd-line-args 'copy #f) )
( overwrite (option-ref cmd-line-args 'overwrite #f) )
( args-len 0 )
( cfg-id #f )
)
( init-log "upcfg" )
( set! args-len (length cmd-line-args) )
( when ( and (null? files) (or (< args-len 2) (> args-len 4)) )
( usage 1 )
)
( if (option-ref cmd-line-args 'help #f)
( usage 0 )
)
( if (option-ref cmd-line-args 'version #f)
( version )
)
( if (option-ref cmd-line-args 'local #f)
( set! cfg-id 'geda-local )
)
( if (option-ref cmd-line-args 'user #f)
( set! cfg-id ( get-user-cfg-id ) )
)
( if ( and (null? files) (not cfg-id) )
( usage 1 )
)
( upcfg-log
"ii: upgrading config in [~a]...~%"
( if cfg-id
( config-file-path cfg-id ) ; if
( list-ref files 0 ) ; else
)
)
( if ( null? files )
( or (config-upgrade cfg-id #:copy copy #:overwrite overwrite) (failure) ) ; if
( or (config-upgrade-file (list-ref files 0)) (failure) ) ; else
)
) ; let
) ; main()
; top-level code:
;
( main )
|