wmgen

Генератор WINGs апликација
git clone https://git.sr.ht/~strahinja/wmgen
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

wmgen (4178B)


      1 #!/bin/sh
      2 # vim: set ft=bash:
      3 
      4 src_dir=$(dirname $(pwd))
      5 
      6 prompt_for_vars()
      7 {
      8 	if [ ! $app_name ]; then
      9 		printf "Name of the new application (whitespace or just Enter="\
     10 "quit): "
     11 		IFS= read -r papp_name
     12 		if [ ! "$papp_name" ]; then
     13 			exit
     14 		fi
     15 		app_name=$(echo "$papp_name" | tr -dc [A-Za-z])
     16 	else
     17 		printf "Name of the new application [%s]: " "$app_name"
     18 		IFS= read -r papp_name
     19 		if [ "$papp_name" ]; then
     20 			app_name=$(echo "$papp_name" | tr -dc [A-Za-z])
     21 		fi
     22 	fi
     23 
     24 	if [ ! "$app_version" ]; then
     25 		app_version=0.1
     26 	fi
     27 	printf "App version [%s]: " "$app_version"
     28 	IFS= read -r papp_version
     29 	if [ "$papp_version" ]; then
     30 		app_version="$papp_version"
     31 	fi
     32 
     33 	app_dir=$(echo "$app_name" | tr [A-Z] [a-z])
     34 	printf "Application directory [%s]: " "$app_dir"
     35 	IFS= read -r papp_dir
     36 	if [ "$papp_dir" ]; then
     37 		app_dir="$papp_dir"
     38 	fi
     39 
     40 	res_name=$(echo "$app_name" | tr [A-Z] [a-z])
     41 	printf "Main window resource name [%s]: " "$res_name"
     42 	IFS= read -r pres_name
     43 	if [ "$pres_name" ]; then
     44 		res_name="$pres_name"
     45 	fi
     46 
     47 	if [ ! "$author_name" ]; then
     48 		author_name=$(whoami)
     49 	fi
     50 	printf "Name of the author [%s]: " "$author_name"
     51 	IFS= read -r pauthor_name
     52 	if [ "$pauthor_name" ]; then
     53 		author_name="$pauthor_name"
     54 	fi
     55 
     56 	if [ ! "$author_email" ]; then
     57 		author_email="$(whoami)@localhost"
     58 	fi
     59 	printf "Author's email [%s]: " "$author_email"
     60 	IFS= read -r pauthor_email
     61 	if [ "$pauthor_email" ]; then
     62 		author_email="$pauthor_email"
     63 	fi
     64 
     65 	if [ ! "$copy_years" ]; then
     66 		copy_years=$(date +%Y)
     67 	fi
     68 	printf "Copyright years [%s]: " "$copy_years"
     69 	IFS= read -r pcopy_years
     70 	if [ "$pcopy_years" ]; then
     71 		copy_years="$pcopy_years"
     72 	fi
     73 
     74 	if [ ! "$copy_holder" ]; then
     75 		copy_holder="$author_name"
     76 	fi
     77 	printf "Copyright holder [%s]: " "$copy_holder"
     78 	IFS= read -r pcopy_holder
     79 	if [ "$pcopy_holder" ]; then
     80 		copy_holder="$pcopy_holder"
     81 	fi
     82 }
     83 
     84 while true; do
     85 	prompt_for_vars
     86 	var_name=$(echo "$res_name" | sed 's/\(...\).*/\1/')
     87 	full_app_dir="$src_dir"/"$app_dir"
     88 	confirmed=0
     89 	while [ "$confirmed" -ne 1 ]; do
     90 		cat <<ENDSUMMARY
     91 Option summary
     92 ===========================================================================
     93 App name:			$app_name
     94 App version:			$app_version
     95 App directory:			$full_app_dir
     96 Main window resource name:	$res_name ($res_name.$app_name)
     97 Author:				$author_name
     98 Author's Email:			$author_email
     99 Copyright years:		$copy_years
    100 Copyright holder:		$copy_holder
    101 License:			GPL v3+ (copy your own if not)
    102 ===========================================================================
    103 ENDSUMMARY
    104 		printf "Is this correct [y/N/q]: "
    105 		IFS= read -r confirm
    106 		case "$confirm" in
    107 			y|Y)	confirmed=1
    108 				break 2;;
    109 			q|Q)	exit;;
    110 			*)	confirmed=1
    111 				continue 2;;
    112 		esac
    113 	done
    114 done
    115 
    116 subst_copy()
    117 { 
    118 	file=$1
    119 	app_dir=$2
    120 	tofile=$3
    121 	if [ ! "$tofile" ]; then
    122 		tofile=$1
    123 	fi
    124 	sed	-e 's/WMNewApp/'"$app_name"'/g' \
    125 		-e 's/WMNEWAPP/'$(echo "$app_name" | tr [a-z] [A-Z])'/g' \
    126 		-e 's/wmnewapp/'"$res_name"'/g' \
    127 		-e 's/\<wma\>/'"$var_name"'/g' \
    128 		-e 's/0\.1/'"$app_version"'/g' \
    129 		-e 's/Yourname Here/'"$author_name"'/g' \
    130 		-e 's/Yoyodyne, Inc./'"$copy_holder"'/g' \
    131 		-e 's/address@example.com/'"$author_email"'/g' \
    132 		-e 's/2020-2024/'"$copy_years"'/g' \
    133 		"$file" > "$app_dir"/"$tofile"
    134 }
    135 
    136 set -x
    137 mkdir -p "$full_app_dir"
    138 #sed 's/^\(PROG.*= \).*/\1'$app_name'/' Makefile > "$full_app_dir"/Makefile
    139 subst_copy Makefile "$full_app_dir"
    140 subst_copy WMNewApp.1 "$full_app_dir" "$app_name".1
    141 subst_copy app.h "$full_app_dir"
    142 cp appicon.xpm "$full_app_dir"/appicon.xpm
    143 subst_copy config.def.h "$full_app_dir"
    144 subst_copy infopanel.h "$full_app_dir"
    145 subst_copy infopanel.c "$full_app_dir"
    146 subst_copy main.c "$full_app_dir"
    147 subst_copy mainwindow.c "$full_app_dir"
    148 subst_copy mainwindow.h "$full_app_dir"
    149 subst_copy menu.c "$full_app_dir"
    150 subst_copy menu.h "$full_app_dir"
    151 cp windowmanager.c "$full_app_dir"/windowmanager.c
    152 cp windowmanager.h "$full_app_dir"/windowmanager.h
    153 cp LICENSE "$full_app_dir"/LICENSE
    154 cat <<ENDREADME > "$full_app_dir"/README
    155 $app_name
    156 ==============
    157 
    158 Describe your newly generated application
    159 
    160 
    161 License
    162 -------
    163 
    164 Copyright (C) $copy_years $author_name
    165 
    166 License description
    167 ENDREADME
    168 set +x
    169 printf "Done! See the generated files in %s\n" "$full_app_dir"